Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

261
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda