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

168
Views
Recorra la matriz de URL y haga clic en un botón en cada página con una extensión de Chrome en JavaScript

Quiero recorrer una serie de URL y hacer clic en el botón "seguir" en cada página con una extensión de Chrome en JavaScript. En este momento, la secuencia de comandos recorre todas las páginas y espera el botón Seguir, pero no hace clic en él.

La secuencia de comandos de fondo debe recorrer todas las páginas. Luego, debería detener el bucle e inyectar un código JavaScript en el sitio web que verifica si hay un botón para dejar de seguir con Mutation Observer. Si ese es el caso, el bucle debe continuar y pasar a la página siguiente. Si hay un botón de seguimiento, se debe hacer clic en el botón antes de pasar a la página siguiente.

Fondo.js:

 const list = ["https://www.twitch.tv/hello1", "https://www.twitch.tv/hello2"]; // When the start button is clicked chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { if (request.start === true) { // Loop through every link (async () => { for (const link of list) { await new Promise((resolve) => { chrome.tabs.update({ url: link }, (tab) => { chrome.tabs.onUpdated.addListener(function onUpdated(tabId, info) { chrome.tabs.onUpdated.removeListener(onUpdated); chrome.scripting.executeScript( { target: { tabId: tab.id }, files: ["follow.js"], }, () => { resolve(); } ); }); }); }); } })(); } });

seguir.js:

 function clickFollow() { document.querySelector("button[data-a-target='follow-button']").click(); } function waitForElement(timeout) { return new Promise((resolve, reject) => { var timer = false; const observer = new MutationObserver(() => { if (document.querySelector("button[data-a-target='follow-button']").length) { if (timer !== false) clearTimeout(timer); return resolve(); } if (document.querySelector("button[data-a-target='unfollow-button']").length) { observer.disconnect(); if (timer !== false) clearTimeout(timer); setTimeout(clickFollow, 1000); } }); observer.observe(document.body, { childList: true, subtree: true, }); if (timeout) timer = setTimeout(() => { observer.disconnect(); reject(); }, timeout); }); } waitForElement(5000);
about 4 years ago · Santiago Gelvez
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!