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);