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

193
Views
¿Hay alguna forma de escuchar los cambios en la URL y activar una función JS?

Por lo tanto, he estado trabajando en esta extensión de Chrome que obtiene los no me gusta en un video de la API de YouTube y lo actualiza en el dom.

 let DISLIKE_COUNT = 0; function convertToInternationalCurrencySystem (labelValue) { // Nine Zeroes for Billions return Math.abs(Number(labelValue)) >= 1.0e+9 ? (Math.abs(Number(labelValue)) / 1.0e+9).toFixed(2) + "B" // Six Zeroes for Millions : Math.abs(Number(labelValue)) >= 1.0e+6 ? (Math.abs(Number(labelValue)) / 1.0e+6).toFixed(2) + "M" // Three Zeroes for Thousands : Math.abs(Number(labelValue)) >= 1.0e+3 ? (Math.abs(Number(labelValue)) / 1.0e+3).toFixed(2) + "K" : Math.abs(Number(labelValue)); } const getDislikes = (dc) => { let val; for(let i = 1; i <= 99; i++){ if(document.getElementsByTagName("yt-formatted-string")[i]?.innerText === "DISLIKE" || document.getElementsByTagName("yt-formatted-string")[i]?.innerText === "Dislike"){ console.log("true : " + i) val = i; break; } else{ console.log("false"); } } document.getElementsByTagName("yt-formatted-string")[val].innerText = convertToInternationalCurrencySystem (dc); } window.addEventListener("load", function() { const params = new URLSearchParams(window.location.search); const videoId = params.get('v'); fetch(`https://www.googleapis.com/youtube/v3/videos?part=statistics&id=${videoId}&key=<yourAPIkey>`) .then(response => response.json()) .then(data => { DISLIKE_COUNT =data.items[0].statistics.dislikeCount; getDislikes(DISLIKE_COUNT); }); });

Ahora bien, esto funciona bastante bien, pero cada vez que hago clic en otro video, tengo que actualizar la página para ejecutar el código JS nuevamente y obtener el recuento de aversiones de la API.

Entonces, ¿hay alguna forma de que escuche los cambios dentro de la URL y vuelva a activar el srcipt JS cuando se hayan realizado los cambios?

about 4 years ago · Juan Pablo Isaza
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!