Greasemonkey help

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
9,144
Reaction score
10,489
I have this script which closes a tab if it finds a certain element on the page:

Code:
// ==UserScript==
// @name        Name
// @namespace   bbb
// @match       https://site.com
// @include     about:config
// @version     1
// @grant       none
// ==/UserScript==



var intv = setInterval(function() {
 
if (/(container)|(mediumheight)/i.test (document.body.innerHTML) )

{
    window.close()
}
 
    }, 1000);

How can I make it close the page if it finds this:

<span id="some">0</span>

But it has to check for both the id (some) and for the number (0). Both must be on the page for the script to fire.

If it was just the id (some) I could do it, but I need both to be true for the script to fire.

Can anyone help? Thanks
 
That should work if you put in right area

function closeWin() {
myWindow.close(); // Closes the new window
}
 
That should work if you put in right area

function closeWin() {
myWindow.close(); // Closes the new window
}

But my problem isn't closing the tab/window, my issue is to have it close only if this...

<span id="some">0</span>

...appears on the page
 
So anyway, I figured out a workaround. I solved my problem.

But no one came to help me, unbelievable. Back in the day I'd get 5 replies within the hour. You guys should be ashamed of yourselves :p :D
 
Haha sorry dude, I was sleeping (quite unusual though lol. I normally go to bed at 4 am). :)

Glad to know you solved it. But normally, I would fetch the element using getElementByID.. e.g.

const someSpan = document.getElementByID('some');
 
Back
Top