- Mar 22, 2013
- 9,144
- 10,489
I know the solution to this is super simple, but I'm no coder, and I'm having a brain freeze right now.
I have a Firefox extension which closes the tab if a certain ID appears on the page.
This code:
See where it says "var el = sel('#text')"?
So when "ID=text" appears on the page, the page is closed.
But I also want it to close the page when the "ID=change" appears. I tried this:
But this only closes the page when "ID=change" appears, and it stops working for "ID=text."
So, what's the right arrangement of code to make it work for both? Thanks
I have a Firefox extension which closes the tab if a certain ID appears on the page.
This code:
Code:
function sel(sel, el) { return (el || document).querySelector(sel); }
function selAll(sel, el) { return (el || document).querySelectorAll(sel); }
function closeTab(){ browser.runtime.sendMessage("close") }
function scan(){
var el = sel('#text')
if( el.classList.contains('hidden') == false ){// means visible
setTimeout(closeTab, 5*1000 )
console.log("closing script ", "closing in5 secs")
}else{
setTimeout(scan, 2*1000 )
}
}
setTimeout(scan, 2*1000 )
console.log("closing script IN...")
See where it says "var el = sel('#text')"?
So when "ID=text" appears on the page, the page is closed.
But I also want it to close the page when the "ID=change" appears. I tried this:
Code:
function sel(sel, el) { return (el || document).querySelector(sel); }
function selAll(sel, el) { return (el || document).querySelectorAll(sel); }
function closeTab(){ browser.runtime.sendMessage("close") }
function scan(){
var el = sel('#text')
var el = sel('#change')
if( el.classList.contains('hidden') == false ){// means visible
setTimeout(closeTab, 5*1000 )
console.log("closing script ", "closing in5 secs")
}else{
setTimeout(scan, 2*1000 )
}
}
setTimeout(scan, 2*1000 )
console.log("closing script IN...")
But this only closes the page when "ID=change" appears, and it stops working for "ID=text."
So, what's the right arrangement of code to make it work for both? Thanks