Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
collect .href strings from functions in javascript file without executing them

I have a javascript file filled with functions that changes the url of an element when a button is clicked like this:

function ABBA(element){ 
    document.getElementById("link1").href="https://www.youtube-nocookie.com/embed/playlist?list=PLTrnXQx3tvG9dkC_I0h-AzV5Su6YG2k9G";
    document.getElementById("link2").href="https://www.youtube-nocookie.com/embed/playlist?list=OLAK5uy_kFZ1F___4Iw3JsDoNzF4bWWJCJ5EeVZAE";  
    document.getElementById("link3").href="https://www.youtube-nocookie.com/embed/playlist?list=OLAK5uy_kFZ1F___4Iw3JsDoNzF4bWWJCJ5EeVZAE";  
}

function ABC(element){ 
    document.getElementById("link1").href="https://www.youtube-nocookie.com/embed/playlist?list=PLTrnXQx3tvG9dkC_I0h-AzV5Su6YG2k9G";
    document.getElementById("link2").href="https://www.youtube-nocookie.com/embed/playlist?list=OLAK5uy_kFZ1F___4Iw3JsDoNzF4bWWJCJ5EeVZAE";  
    document.getElementById("link3").href="https://www.youtube-nocookie.com/embed/playlist?list=OLAK5uy_kFZ1F___4Iw3JsDoNzF4bWWJCJ5EeVZAE";  
}
// etc etc

My question is, is there a way to collect all those .href strings and save it to a variable, without executing the functions?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You just need: 1) Fetch your file; 2) Write regex for links.

And combine it together:

fetch('./functions.js')
   .then(response => response.text())
   .then((data) => {
      const regexp = /href="(.*?)"/g;
      const array = [...data.matchAll(regexp)];
      console.log(array);
      console.log(array[0][1]);
   });

And result is:

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda