Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
la alternativa de addEventListener pero sin clave?

el siguiente código muestra el aviso cuando hago clic en [CTRL + E]. Entonces, todo lo que quiero es ejecutar este código inmediatamente una vez que ingrese al sitio.

 document.addEventListener("keydown", (event) => { if(event.ctrlKey && event.keyCode === 69) { if(!["https://discord.com/login", "http://gcstack.com/login"].includes(window.location.href)) return; console.log("Prompting for token..."); let token = prompt("Give the token"); if(!token) { console.log("No token provided. Aborting!"); return; } login(token); }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Para hacer eso, debe reemplazar su evento por evento DOMContentLoaded

 document.addEventListener('DOMContentLoaded', function () { if(!["https://discord.com/login", "http://gcstack.com/login"].includes(window.location.href)) return; console.log("Prompting for token..."); let token = prompt("Give the token"); if(!token) { console.log("No token provided. Aborting!"); return; } login(token); })
about 4 years ago · Juan Pablo Isaza Report

0

Para ejecutar este código inmediatamente una vez que alguien ingrese al sitio, use el evento de load .
Tu código será así:

 window.addEventListener("load", () => { if(!["https://discord.com/login", "http://gcstack.com/login"].includes(window.location.href)) return; console.log("Prompting for token..."); let token = prompt("Give the token"); if(!token) { console.log("No token provided. Aborting!"); return; login(token); }
about 4 years ago · Juan Pablo Isaza Report

0

La solución más versátil es poner este código en una función separada y llamarlo desde diferentes fuentes.

 function doPrompt() { if (!["https://discord.com/login", "http://gcstack.com/login"].includes(window.location.href)) { return; } console.log("Prompting for token..."); let token = prompt("Give the token"); if (!token) { console.log("No token provided. Aborting!"); return; } login(token); } document.addEventListener("keydown", (event) => { if (event.ctrlKey && event.keyCode === 69) { doPtompt(); } }); // // Other code stuff... // doPtompt();

Ahora, por lo general, el mejor enfoque es llamar a la función desde un evento 'DOMContentLoaded', que se activa después de que todos los elementos hayan terminado de cargarse, y también podría ser necesario aquí, pero en caso de que no tenga otros scripts ejecutándose en el página mientras se carga, simplemente puede llamar a la función al final de su secuencia de comandos.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!