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

257
Views
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
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!