finish updater rewrite
This commit is contained in:
parent
79405c2492
commit
740029c8bd
127
4chan_x.js
127
4chan_x.js
@ -59,7 +59,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(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;
|
var __slice = Array.prototype.slice;
|
||||||
if (typeof console != "undefined" && console !== null) {
|
if (typeof console != "undefined" && console !== null) {
|
||||||
log = console.log;
|
log = console.log;
|
||||||
@ -1565,81 +1565,12 @@
|
|||||||
clone.href = href;
|
clone.href = href;
|
||||||
return $.replace(favicon, clone);
|
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() {
|
updateTitle = function() {
|
||||||
var len;
|
var len;
|
||||||
len = g.replies.length;
|
len = g.replies.length;
|
||||||
d.title = d.title.replace(/\d+/, len);
|
d.title = d.title.replace(/\d+/, len);
|
||||||
return updateFavicon();
|
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 = {
|
updater = {
|
||||||
init: function() {
|
init: function() {
|
||||||
var autoUpT, checked, conf, dialog, html, input, interva, name, title, updNow, verbose, _i, _len, _ref;
|
var autoUpT, checked, conf, dialog, html, input, interva, name, title, updNow, verbose, _i, _len, _ref;
|
||||||
@ -1700,32 +1631,62 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
update: function(e) {
|
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]');
|
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', {
|
body = $.el('body', {
|
||||||
innerHTML: this.responseText
|
innerHTML: this.responseText
|
||||||
});
|
});
|
||||||
arr = [];
|
|
||||||
replies = $$('td[id]', body);
|
replies = $$('td[id]', body);
|
||||||
log(replies.length);
|
|
||||||
while ((reply = replies.pop()) && (reply.id > id)) {
|
while ((reply = replies.pop()) && (reply.id > id)) {
|
||||||
arr.push(reply.parentNode.parentNode.parentNode);
|
arr.push(reply.parentNode.parentNode.parentNode);
|
||||||
}
|
}
|
||||||
log(arr.length);
|
if ($.config('Verbose')) {
|
||||||
while (reply = arr.pop()) {
|
timer.textContent = '-' + $.config('Interval');
|
||||||
$.before(br, reply);
|
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() {
|
timeout: function() {
|
||||||
var n, timer;
|
var count, n, timer;
|
||||||
timer = $('#timer');
|
timer = $('#timer');
|
||||||
n = Number(timer.textContent);
|
n = Number(timer.textContent);
|
||||||
n += 1;
|
n += 1;
|
||||||
timer.textContent = n;
|
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();
|
return updater.update();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2167,10 +2128,10 @@
|
|||||||
if ($.config('Keybinds')) {
|
if ($.config('Keybinds')) {
|
||||||
keybinds.init();
|
keybinds.init();
|
||||||
}
|
}
|
||||||
if ($.config('Thread Updater')) {
|
|
||||||
updater.init();
|
|
||||||
}
|
|
||||||
if (g.REPLY) {
|
if (g.REPLY) {
|
||||||
|
if ($.config('Thread Updater')) {
|
||||||
|
updater.init();
|
||||||
|
}
|
||||||
if ($.config('Image Preloading')) {
|
if ($.config('Image Preloading')) {
|
||||||
g.callbacks.push(function(root) {
|
g.callbacks.push(function(root) {
|
||||||
var parent, thumb, thumbs, _i, _len, _results;
|
var parent, thumb, thumbs, _i, _len, _results;
|
||||||
|
|||||||
111
script.coffee
111
script.coffee
@ -6,7 +6,7 @@
|
|||||||
# XXX error on FUCKING CHROME
|
# XXX error on FUCKING CHROME
|
||||||
{log} = console if console?
|
{log} = console if console?
|
||||||
|
|
||||||
# TODO put keybinds back to false when done
|
# TODO reset defaults
|
||||||
config =
|
config =
|
||||||
main:
|
main:
|
||||||
checkbox:
|
checkbox:
|
||||||
@ -1213,70 +1213,11 @@ updateFavicon = ->
|
|||||||
clone.href = href
|
clone.href = href
|
||||||
$.replace favicon, clone
|
$.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 = ->
|
updateTitle = ->
|
||||||
len = g.replies.length
|
len = g.replies.length
|
||||||
d.title = d.title.replace /\d+/, len
|
d.title = d.title.replace /\d+/, len
|
||||||
updateFavicon()
|
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 =
|
updater =
|
||||||
init: ->
|
init: ->
|
||||||
html = "<div class=move><span id=count></span> <span id=timer></span></div>"
|
html = "<div class=move><span id=count></span> <span id=timer></span></div>"
|
||||||
@ -1330,33 +1271,57 @@ updater =
|
|||||||
timer.textContent = 'Thread Updater'
|
timer.textContent = 'Thread Updater'
|
||||||
window.clearInterval updater.intervalID
|
window.clearInterval updater.intervalID
|
||||||
update: (e) ->
|
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]'
|
br = $ 'br[clear]'
|
||||||
|
id = Number $('td[id]', br.previousElementSibling)?.id or 0
|
||||||
id = Number $('td[id]', br.previousElementSibling).id
|
|
||||||
|
|
||||||
body = $.el 'body',
|
|
||||||
innerHTML: @responseText
|
|
||||||
|
|
||||||
arr = []
|
arr = []
|
||||||
|
body = $.el 'body',
|
||||||
|
innerHTML: @responseText
|
||||||
replies = $$ 'td[id]', body
|
replies = $$ 'td[id]', body
|
||||||
log replies.length
|
|
||||||
while (reply = replies.pop()) and (reply.id > id)
|
while (reply = replies.pop()) and (reply.id > id)
|
||||||
arr.push reply.parentNode.parentNode.parentNode #table
|
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
|
#XXX add replies in correct order so /b/acklinks resolve
|
||||||
while reply = arr.pop()
|
while reply = arr.pop()
|
||||||
$.before br, reply
|
$.before br, reply
|
||||||
|
|
||||||
log 'end'
|
|
||||||
|
|
||||||
timeout: ->
|
timeout: ->
|
||||||
timer = $ '#timer'
|
timer = $ '#timer'
|
||||||
n = Number timer.textContent
|
n = Number timer.textContent
|
||||||
n += 1
|
n += 1
|
||||||
timer.textContent = n
|
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()
|
updater.update()
|
||||||
|
|
||||||
update: ->
|
update: ->
|
||||||
@ -1733,10 +1698,10 @@ if $.config 'Anonymize'
|
|||||||
if $.config 'Keybinds'
|
if $.config 'Keybinds'
|
||||||
keybinds.init()
|
keybinds.init()
|
||||||
|
|
||||||
if $.config 'Thread Updater'
|
|
||||||
updater.init()
|
|
||||||
|
|
||||||
if g.REPLY
|
if g.REPLY
|
||||||
|
if $.config 'Thread Updater'
|
||||||
|
updater.init()
|
||||||
|
|
||||||
if $.config 'Image Preloading'
|
if $.config 'Image Preloading'
|
||||||
g.callbacks.push (root) ->
|
g.callbacks.push (root) ->
|
||||||
thumbs = $$ 'img[md5]', root
|
thumbs = $$ 'img[md5]', root
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user