finish updater rewrite

This commit is contained in:
James Campos 2011-04-16 13:43:38 -07:00
parent 79405c2492
commit 740029c8bd
2 changed files with 82 additions and 156 deletions

View File

@ -59,7 +59,7 @@
*/
(function() {
var $, $$, NAMESPACE, a, as, autoWatch, callback, changeCheckbox, changeValue, config, d, delform, el, expand, expandComment, expandThread, g, imageClick, imageExpand, imageExpandClick, imageHover, imageResize, imageThumb, imageToggle, imageType, imageTypeChange, keyModeNormal, keybinds, log, nav, navtopr, nodeInserted, omitted, onloadComment, onloadThread, option, options, parseResponse, pathname, qr, recaptcha, recaptchaListener, recaptchaReload, redirect, replyHiding, replyNav, report, scroll, scrollThread, span, temp, text, threadHiding, tzOffset, ui, updateCallback, updateFavicon, updateTime, updateTitle, updater, watcher, _config, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _m, _ref, _ref2, _ref3, _ref4;
var $, $$, NAMESPACE, a, as, autoWatch, callback, changeCheckbox, changeValue, config, d, delform, el, expand, expandComment, expandThread, g, imageClick, imageExpand, imageExpandClick, imageHover, imageResize, imageThumb, imageToggle, imageType, imageTypeChange, keyModeNormal, keybinds, log, nav, navtopr, nodeInserted, omitted, onloadComment, onloadThread, option, options, parseResponse, pathname, qr, recaptcha, recaptchaListener, recaptchaReload, redirect, replyHiding, replyNav, report, scroll, scrollThread, span, temp, text, threadHiding, tzOffset, ui, updateFavicon, updateTitle, updater, watcher, _config, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _m, _ref, _ref2, _ref3, _ref4;
var __slice = Array.prototype.slice;
if (typeof console != "undefined" && console !== null) {
log = console.log;
@ -1565,81 +1565,12 @@
clone.href = href;
return $.replace(favicon, clone);
};
updateTime = function() {
var count, span, time;
span = $('#updater #timer');
time = Number(span.textContent);
if (++time === 0) {
return updateNow();
} else if (time > 10) {
time = 0;
g.req.abort();
updateNow();
if (g.verbose) {
count = $('#updater #count');
count.textContent = 'retry';
return count.className = '';
}
} else {
return span.textContent = time;
}
};
updateTitle = function() {
var len;
len = g.replies.length;
d.title = d.title.replace(/\d+/, len);
return updateFavicon();
};
updateCallback = function() {
var arr, body, count, id, input, l, replies, reply, root, s, table, timer, _i, _len, _ref;
count = $('#updater #count');
timer = $('#updater #timer');
if (this.status === 404) {
count.textContent = 404;
count.className = 'error';
timer.textContent = '';
clearInterval(g.interval);
_ref = $$('input[type=submit]');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
input = _ref[_i];
input.disabled = true;
input.value = 404;
}
s = '';
if ($.config('Unread Count')) {
s += "(" + g.replies.length + ") ";
}
s += "/" + g.BOARD + "/ - 404";
d.title = s;
g.dead = true;
updateFavicon();
return;
}
body = $.el('body', {
innerHTML: this.responseText
});
replies = $$('td.reply', body);
root = $('br[clear]');
if (reply = $('td.reply, td.replyhl', root.previousElementSibling)) {
id = Number(reply.id);
} else {
id = 0;
}
arr = [];
while ((reply = replies.pop()) && (Number(reply.id > id))) {
arr.push(reply);
}
if (g.verbose) {
l = arr.length;
count.textContent = "+" + l;
count.className = l > 0 ? 'new' : '';
}
while (reply = arr.pop()) {
table = $.x('ancestor::table', reply);
$.before(root, table);
}
return timer.textContent = -1 * GM_getValue('Interval', 10);
};
updater = {
init: function() {
var autoUpT, checked, conf, dialog, html, input, interva, name, title, updNow, verbose, _i, _len, _ref;
@ -1700,32 +1631,62 @@
}
},
update: function(e) {
var arr, body, br, id, replies, reply;
var arr, body, br, count, id, input, replies, reply, s, timer, _i, _len, _ref, _ref2, _results;
count = $('#count');
timer = $('#timer');
if (this.status === 404) {
count.textContent = 404;
count.className = 'error';
timer.textContent = '';
clearInterval(updater.intervalID);
_ref = $$('input[type=submit]');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
input = _ref[_i];
input.disabled = true;
input.value = 404;
}
s = d.title.match(/.+- /)[0];
s += '404';
return;
}
br = $('br[clear]');
id = Number($('td[id]', br.previousElementSibling).id);
id = Number(((_ref2 = $('td[id]', br.previousElementSibling)) != null ? _ref2.id : void 0) || 0);
arr = [];
body = $.el('body', {
innerHTML: this.responseText
});
arr = [];
replies = $$('td[id]', body);
log(replies.length);
while ((reply = replies.pop()) && (reply.id > id)) {
arr.push(reply.parentNode.parentNode.parentNode);
}
log(arr.length);
while (reply = arr.pop()) {
$.before(br, reply);
if ($.config('Verbose')) {
timer.textContent = '-' + $.config('Interval');
count.textContent = '+' + arr.length;
if (arr.length > 0) {
count.className = 'new';
}
}
return log('end');
_results = [];
while (reply = arr.pop()) {
_results.push($.before(br, reply));
}
return _results;
}
},
timeout: function() {
var n, timer;
var count, n, timer;
timer = $('#timer');
n = Number(timer.textContent);
n += 1;
timer.textContent = n;
if (n === 0 || n === 10) {
if (n === 10) {
updater.r.abort();
count = $('#count');
counte.textContent = 'retry';
count.className = '';
n = 0;
}
if (n === 0) {
return updater.update();
}
},
@ -2167,10 +2128,10 @@
if ($.config('Keybinds')) {
keybinds.init();
}
if ($.config('Thread Updater')) {
updater.init();
}
if (g.REPLY) {
if ($.config('Thread Updater')) {
updater.init();
}
if ($.config('Image Preloading')) {
g.callbacks.push(function(root) {
var parent, thumb, thumbs, _i, _len, _results;

View File

@ -6,7 +6,7 @@
# XXX error on FUCKING CHROME
{log} = console if console?
# TODO put keybinds back to false when done
# TODO reset defaults
config =
main:
checkbox:
@ -1213,70 +1213,11 @@ updateFavicon = ->
clone.href = href
$.replace favicon, clone
updateTime = ->
span = $ '#updater #timer'
time = Number span.textContent
if ++time is 0
updateNow()
else if time > 10
time = 0
g.req.abort()
updateNow()
if g.verbose
count = $ '#updater #count'
count.textContent = 'retry'
count.className = ''
else
span.textContent = time
updateTitle = ->
len = g.replies.length
d.title = d.title.replace /\d+/, len
updateFavicon()
updateCallback = ->
count = $ '#updater #count'
timer = $ '#updater #timer'
if @status is 404
count.textContent = 404
count.className = 'error'
timer.textContent = ''
clearInterval g.interval
for input in $$ 'input[type=submit]'
input.disabled = true
input.value = 404
s = ''
if $.config 'Unread Count' then s += "(#{g.replies.length}) "
s += "/#{g.BOARD}/ - 404"
d.title = s
g.dead = true
updateFavicon()
return
body = $.el 'body', innerHTML: @responseText
replies = $$ 'td.reply', body
root = $('br[clear]')
if reply = $ 'td.reply, td.replyhl', root.previousElementSibling
id = Number reply.id
else
id = 0
arr = []
while (reply = replies.pop()) and (Number reply.id > id)
arr.push reply
if g.verbose
l = arr.length
count.textContent = "+#{l}"
count.className = if l > 0 then 'new' else ''
#insert replies in order, so backlinks resolve
while reply = arr.pop()
table = $.x 'ancestor::table', reply
$.before root, table
timer.textContent = -1 * GM_getValue 'Interval', 10
updater =
init: ->
html = "<div class=move><span id=count></span> <span id=timer></span></div>"
@ -1330,33 +1271,57 @@ updater =
timer.textContent = 'Thread Updater'
window.clearInterval updater.intervalID
update: (e) ->
count = $ '#count'
timer = $ '#timer'
if @status is 404
count.textContent = 404
count.className = 'error'
timer.textContent = ''
clearInterval updater.intervalID
for input in $$ 'input[type=submit]'
input.disabled = true
input.value = 404
s = d.title.match(/.+- /)[0]
s += '404'
# TODO
#updateFavicon()
return
br = $ 'br[clear]'
id = Number $('td[id]', br.previousElementSibling).id
body = $.el 'body',
innerHTML: @responseText
id = Number $('td[id]', br.previousElementSibling)?.id or 0
arr = []
body = $.el 'body',
innerHTML: @responseText
replies = $$ 'td[id]', body
log replies.length
while (reply = replies.pop()) and (reply.id > id)
arr.push reply.parentNode.parentNode.parentNode #table
log arr.length
if $.config 'Verbose'
timer.textContent = '-' + $.config 'Interval'
count.textContent = '+' + arr.length
if arr.length > 0
count.className = 'new'
#XXX add replies in correct order so /b/acklinks resolve
while reply = arr.pop()
$.before br, reply
log 'end'
timeout: ->
timer = $ '#timer'
n = Number timer.textContent
n += 1
timer.textContent = n
if n == 0 or n == 10 #retry
if n == 10
updater.r.abort()
count = $ '#count'
counte.textContent = 'retry'
count.className = ''
n = 0
if n == 0
updater.update()
update: ->
@ -1733,10 +1698,10 @@ if $.config 'Anonymize'
if $.config 'Keybinds'
keybinds.init()
if $.config 'Thread Updater'
updater.init()
if g.REPLY
if $.config 'Thread Updater'
updater.init()
if $.config 'Image Preloading'
g.callbacks.push (root) ->
thumbs = $$ 'img[md5]', root