make new request after 10s

This commit is contained in:
James Campos 2010-12-28 13:10:58 -08:00
parent 1cc4c2d7a5
commit bf6639da25
2 changed files with 21 additions and 4 deletions

View File

@ -808,6 +808,7 @@ request = (url, callback) ->
r.onload = -> callback this r.onload = -> callback this
r.open 'get', url, true r.open 'get', url, true
r.send() r.send()
r
updateCallback = (res) -> updateCallback = (res) ->
body = n 'body', innerHTML: res.responseText body = n 'body', innerHTML: res.responseText
@ -835,7 +836,12 @@ updateCallback = (res) ->
updateTime = -> updateTime = ->
span = $ '#updater #timer' span = $ '#updater #timer'
time = Number span.textContent time = Number span.textContent
if ++time is 0 then updateNow() if ++time is 0
updateNow()
else if time > 10
time = 0
g.r.abort()
updateNow()
span.textContent = time span.textContent = time
updateAuto = -> updateAuto = ->
@ -858,7 +864,7 @@ updateInterval = ->
span.textContent = -1 * n span.textContent = -1 * n
updateNow = -> updateNow = ->
request location.href, updateCallback g.r = request location.href, updateCallback
updaterMake = -> updaterMake = ->
div = AEOS.makeDialog 'updater', 'topright' div = AEOS.makeDialog 'updater', 'topright'
@ -994,6 +1000,9 @@ GM_addStyle '
position: fixed; position: fixed;
text-align: right; text-align: right;
} }
#updater input[type=text] {
width: 50px;
}
#watcher { #watcher {
position: absolute; position: absolute;
} }

View File

@ -1067,7 +1067,8 @@
return callback(this); return callback(this);
}; };
r.open('get', url, true); r.open('get', url, true);
return r.send(); r.send();
return r;
}; };
updateCallback = function(res) { updateCallback = function(res) {
var body, count, i, id, replies, reply, root, span, table; var body, count, i, id, replies, reply, root, span, table;
@ -1099,6 +1100,10 @@
time = Number(span.textContent); time = Number(span.textContent);
if (++time === 0) { if (++time === 0) {
updateNow(); updateNow();
} else if (time > 10) {
time = 0;
g.r.abort();
updateNow();
} }
return span.textContent = time; return span.textContent = time;
}; };
@ -1126,7 +1131,7 @@
} }
}; };
updateNow = function() { updateNow = function() {
return request(location.href, updateCallback); return g.r = request(location.href, updateCallback);
}; };
updaterMake = function() { updaterMake = function() {
var auto, div, html, interval; var auto, div, html, interval;
@ -1274,6 +1279,9 @@
position: fixed;\ position: fixed;\
text-align: right;\ text-align: right;\
}\ }\
#updater input[type=text] {\
width: 50px;\
}\
#watcher {\ #watcher {\
position: absolute;\ position: absolute;\
}\ }\