Search code examples
javascriptgreasemonkeytampermonkey

Trying to limit a tampermonkey script to page section


first of, I'm a total, utter newbie. I have to work with this, because nobody in my office is even halfway computer literate. The person who wrote the initial script left the company and we can't get ahold of him anymore.

Now, the problem at hand:

I have a script that's a "look for words and highlight them in garish colour" affair. Now I tried to modify it so that it only runs in a

This is the code:

function Find(node){
    if(!node)
        node=document.getElementsByTagName('div class="listing__top-info"')[0];
    this.rootNode=node;
    this.hits=0;
    this.selected=0;
    this.selection=[];
    this.build();

Yet when I run this code, I get this in the log:

"TypeError: document.getElementsByClassName(...)[1] is undefined" (I also don't understand why the [0] gets changed to a [1] here.)

The script is already set to run at document-idle.

The version of the script that works, is set to look for "body", and then marks/highlights as intended.

What am I missing?


Solution

  • Try using querySelector instead:

    node = document.querySelector('div.listing__top-info');