refresh and unsafeWindow

in Script development
Subscribe to refresh and unsafeWindow 21 posts, 3 voices



ekbworldwide Scriptwright
FirefoxWindows

Salon Technology
http://www.salon.com/technology/

• after the refresh the url changes to
http://www.salon.com/technology/?source=refresh

This test code...

GM_log(unsafeWindow.refresh_time);
unsafeWindow.refresh_time = 1000;
GM_log(unsafeWindow.refresh_time);

...outputs...
300000
1000

...but the tab doesn't refresh in a second - it still takes 5 minutes to refresh.

source code:

<script type="text/javascript" language="javascript">
	<!--
		var urlReg = /^((\w+):\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/.exec(location.href);
		var host = urlReg[6];
		var path = urlReg[8];
		var refresh_url = 'http://' + host + path + '?source=refresh';
		var refresh_time = 300000;

		function salonRefresh() {
			document.location.href = refresh_url;
		}

		var refreshTimeout = setTimeout('salonRefresh()', refresh_time);
	//-->
</script>

 
JoeSimmons Scriptwright
FirefoxWindows

because a timeout was already set for that refresh time. try this

unsafeWindow.refreshTimeout = unsafeWindow.setTimeout('salonRefresh()', 1000);

also i dont see why u cant just do this
window.setTimeout(unsafeWindow.salonRefresh, 1000);

 
ekbworldwide Scriptwright
FirefoxWindows

I made a local file for testing:

<head><script type="text/javascript" language="javascript">
	<!--
		var refresh_time = 1000;
		function salonRefresh() {
			location.href = location.href
		}
		var refreshTimeout = setTimeout('salonRefresh()', refresh_time);
	//-->
</script></head>
<body>I refresh therefore I exist.</body>

code tests

unsafeWindow.refreshTimeout = unsafeWindow.setTimeout('salonRefresh()', 1000000);

Result - a refresh every second

window.setTimeout(unsafeWindow.salonRefresh, 1000000);

Result - a refresh every second

 
JoeSimmons Scriptwright
FirefoxWindows

well u will also have to clear their timeout first then set yours

 
ekbworldwide Scriptwright
FirefoxWindows

>> clear their timeout

I have no idea how to do that.

 
JoeSimmons Scriptwright
FirefoxWindows

for(let i=999; i>=0; i--) unsafeWindow.clearTimeout(i);

 
ekbworldwide Scriptwright
FirefoxWindows

for(let i=999; i>=0; i--) unsafeWindow.clearTimeout(i);
unsafeWindow.refreshTimeout = unsafeWindow.setTimeout('salonRefresh()', 2000);

Result - it works.

for(let i=30000; i>=0; i--) unsafeWindow.clearTimeout(i);
window.setTimeout(unsafeWindow.salonRefresh, 2000);

Result - it works.

But I'm confused. This...

for (let i=30000; i>=0; i--)
	unsafeWindow.clearTimeout(i);

...works too.

_____________________________
questions

1. Why doesn't this work(?):

unsafeWindow.clearTimeout(0);

2. setTimeout stuff
Why do I need the setTimeout stuff?

Window clearTimeout() Method
http://www.w3schools.com/jsref/met_win_cleartim...

The clearTimeout() method cancels a timeout that is set with the setTimeout() method.

3. global use
I'd like to use this script globally to kill refreshes. Is there an easy way to grab n of clearTimeout? If so - would this work(?):

for(let i=n; i>=0; i--) unsafeWindow.clearTimeout(i)

 
JoeSimmons Scriptwright
FirefoxWindows

ekbworldwide wrote:
unsafeWindow.clearTimeout(0);
cuz the first timeout must not be the right one. even anomyous settimeout calls get assigned an integer in a global scope.
ekbworldwide wrote:
I'd like to use this script globally to kill refreshes.
it would screw up timeouts on other sites, probably not good for a global idea
 
ekbworldwide Scriptwright
FirefoxWindows

#1
Ah... I somehow thought that counting down numbers for clearTimeout was necessary. I think I got it now - the for loop is doing an exhaustive search to find the value of clearTimeout which is changing every millisecond. Right?

#2
Why do I need the setTimeout stuff?

#3

it would screw up timeouts on other sites, probably not good for a global idea

I could just put the sites/domains in exclude. I just realized excludes are needed for http*:*.google.* and stuff relating to feeds and email - but I'm basically anti-twitter and all that crud. I don't need pages to be brand new every three minutes (or whatever). I'd rather have a page be "old" because I didn't allow refreshes (for the page or parts of the page) - than have the site refresh it for me.

If I now understand correctly - n isn't constant. So how about this(?):

for (let i=2000000; i>=0; i--)
	unsafeWindow.clearTimeout(i);

... inside an if statement. I'm trying to figure out how to build the if statement.

2 million milliseconds is about 30 minutes. I know that 30 minutes is overkill but I really hate refreshes.

 
JoeSimmons Scriptwright
FirefoxWindows

ekbworldwide wrote:
the for loop is doing an exhaustive search to find the value of clearTimeout which is changing every millisecond. Right?
no. its clearing all timeouts on the page.
ekbworldwide wrote:
I could just put the sites/domains in exclude.
no, it would screw up 85% of websites, not a good idea
ekbworldwide wrote:
2 million milliseconds is about 30 minutes.
you dont get it. if theres 1 timeout on a page, it will be 0, if i add another, it will be 1, and so on. i can clearTimeout(0) and it will clear the first timeout that was set on the page
 
ekbworldwide Scriptwright
FirefoxWindows

no. its clearing all timeouts on the page.

My first thought was right? I'm confused again. Haha. Anyway... using a giant n is a terrible idea. It works fine on my tiny local test page but on a real webpage - the first link in my first post - even setting n > 500000 can start to take a few seconds or freeze Firefox or crash it. And I sometimes have many tabs open. So FOR loops aren't a good idea.

New idea

1. In a script tag...

2. Use regex and find setTimeout - example - setTimeout('salonRefresh()', refresh_time)

3. Use unsafeWindow to create the equivalent of t=setTimeout('salonRefresh()', refresh_time)

4. eval(t=setTimeout('salonRefresh()', refresh_time))

5. clearTimeout(t);

6. Repeat steps on next script tag.

_____________
problems

I don't know if my logic is sound.

I have no idea how to do step 3.

The idea assumes only one setTimeout in a tag.

 
JoeSimmons Scriptwright
FirefoxWindows

ekbworldwide wrote:
n > 500000 can start to take a few seconds or freeze Firefox or crash it
i highly doubt theres ever gonna be 500,000 timeouts on a page. probably 100 or 200 is fine
 
ekbworldwide Scriptwright
FirefoxWindows

The more I do this - the more confused I'm getting, but this...

for (let i=100; i>=0; i--) {
	refresh_time = Math.round((Math.random()*1000)*(Math.random()*1000));
	function salonRefresh() {
		location.href = location.href
	}
	var refreshTimeout = setTimeout('salonRefresh()', refresh_time);
	t=setTimeout('salonRefresh()', refresh_time);
	GM_log("refresh_time: " + refresh_time + " " + "t: " + t);
}

...helped me a bit. I see now that refresh_time isn't relevant at all.

t starts at 3 and is only odd numbers - but at least I understand more.

So - I've walked around in a big circle. Is this all I need(?):

for (let i=500; i>=0; i--)
	unsafeWindow.clearTimeout(i);

My overkill will be to make n = 500 and not 100 or 200. I won't bother with an IF statement.

 
JoeSimmons Scriptwright
FirefoxWindows

ekbworldwide wrote:
I won't bother with an IF statement.
u cant do one anyways, its not in a variable so no way to check just gotta clear em.
ekbworldwide wrote:
setTimeout('salonRefresh()', refresh_time);
stop using the quotes. use window.setTimeout(salonRefresh, refresh_time);
are you trying to kill the refresh? if so just use unsafeWindow.salonRefresh=function(){return true;};
 
devnull69 Scriptwright
FirefoxWindows

oh oh oh ... big confusion. Trying to shed some light on it

First:

for(let i=900; i>=0; i--) unsafeWindow.clearTimeout(i);

is EXACTLY the same as
for(let i=900; i>=0; i--)
  unsafeWindow.clearTimeout(i);

which both are different than
for(let i=900; i>=0; i--) {}
unsafeWindow.clearTimeout(i);

Second: Your first statement lead us to the impression that you wanted to have a ONE SECOND TIMEOUT instead of the FIVE MINUTE TIMEOUT to refresh the page. This is obviously not the case any more. Can you specify your question again without anticipating the answer? Let us do the work :-)

Third: You said that t starts with 3 and has just odd numbers in this example

var refreshTimeout = setTimeout('salonRefresh()', refresh_time);
t=setTimeout('salonRefresh()', refresh_time);

This is of course correct, because EVERY call of setTimeout will generate a completely NEW timeout in ADDITION to every timeout currently running. So Joe suggested to clear all running timeouts before you set your new one. And you can do that with the statement under my "First" section.

Fourth: The result of a setTimeout call is a unique identifier of the generated timeout. In the previous example the variables refreshTimeout and t both hold a different identifier, because they identify different timeouts. You can use these identifiers to clear a specific timeout (e.g. clearTimeout(refreshTimeout))

 
ekbworldwide Scriptwright
FirefoxWindows

Current script:

// regular refresh stuff ----------------------------------
for (let i=500; i>=0; i--)
	unsafeWindow.clearTimeout(i);

// meta stuff ---------------------------------------------
let m=window.setTimeout(function() {},99);
for(let i=m;i>0;i--)
	window.clearTimeout(i); 
// For the meta stuff to work - an about:config tweak needs to be made.
// set accessibility.blockautorefresh to true

__________________________________________
Problem
The about:config settings makes this display this with every blocked meta refresh:

I can't figure out how to hide it or remove it.

With the script enabled - going to the link:

Chicago Tribune
http://www.chicagotribune.com/

...instantly shows the message.

 
devnull69 Scriptwright
FirefoxWindows

Ok, but it's not the enabled script that causes this behaviour. It is the Firefox option (Tools/Options/Advanced/Tab General/Section Accessibility ... "Warn me when web sites try to redirect or reload the page") which is checked for you. As far as I know the alert message can not be turned off by Greasemonkey.

 
ekbworldwide Scriptwright
FirefoxWindows

So the meta refresh code doesn't actually work?

I'll post at userstyles.org and see if I can hide the message with Stylish.

_____________
edit

I just realized that there's no way to "exclude" about:config stuff - so using the about:config setting isn't going to work.

example

In a script I an exclude http://*forum*.

 
devnull69 Scriptwright
FirefoxWindows

After some google-ing I strongly believe that a meta refresh can not be stopped by Javascript.

 
ekbworldwide Scriptwright
FirefoxWindows

I noticed the word auto in blockautorefresh. I think what I want to block is all auto-refreshes.

New question: In about:config if I set accessibility.blockautorefresh to true - does that block all auto-refreshes (i.e. meta, js, http, whatever)?

 
devnull69 Scriptwright
FirefoxWindows

It will block meta and http, but not js.

See http://kb.mozillazine.org/Accessibility.blockau...

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel