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

259
Visualizações
How do I combine two user scripts into one script

I have two user scripts that be should be run in the console of the browser

Script #1 - waits for the class .cdn_download_item to appear on the page, after which a response comes out that "the class has been detected".

Script #2 - this script should be used only after the appearance of the class .cdn_download_item, because it iterates over the spans of this class and outputs them.

If I run these scripts separately. Then everything works Question - how do I combine these scripts into one script and get the result?

Script #1

document.addEventListener('DOMNodeInserted', function(event){
    if(document.querySelectorAll('.cdn_download_item'))
    {
        console.log('класс обнаружен');
    }
    else
    {
        console.log('не удалось обнаружить класс');
    }
}, true);

Script #2

var elements = Array.from(document.querySelectorAll('.cdn_download_item span:first-child'));
var linksArray = new Array();
for (element of elements) {
    linksArray.push(element.innerText);
}
linksArray;

I need something like this (see below)

document.addEventListener('DOMNodeInserted', function(event){
    if(document.querySelectorAll('.cdn_download_item'))
    {
        var elements = Array.from(document.querySelectorAll('.cdn_download_item span:first-child'));
        var linksArray = new Array();
        for (element of elements) 
        {
            linksArray.push(element.innerText);
        }
        linksArray;
    }
    else
    {
        //if the class has not been detected yet, then we are waiting for the class to appear
    }
}, true);

I tried to combine these scripts by myself like so (see below). My code is not working correctly, the result should come out once and the array should consist of 76 elements, and now the result is output 76 times!!!

document.addEventListener('DOMNodeInserted', function(event){
    if(document.querySelectorAll('.cdn_download_item'))
    {
        var elements = Array.from(document.querySelectorAll('.cdn_download_item span:first-child'));
        var linksArray = new Array();
        for (element of elements) 
        {
            linksArray.push(element.innerText);
        }
        console.log(linksArray);
    }
}, true);
about 4 years ago · Juan Pablo Isaza
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