From 44e5e5a78e4789fdf50a86a4e7a7f8a836495f74 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 26 Dec 2010 08:59:46 -0800 Subject: [PATCH] thread updating --- 4chan_x.coffee | 42 ++++++++++++++++++++++++++++++++++++++++++ 4chan_x.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/4chan_x.coffee b/4chan_x.coffee index 600e6e45b..2844c5182 100644 --- a/4chan_x.coffee +++ b/4chan_x.coffee @@ -25,6 +25,7 @@ config = 'Thread Expansion': [true, 'View all replies'] 'Thread Hiding': [true, 'Hide entire threads'] 'Thread Navigation': [true, 'Navigate to previous / next thread'] + 'Thread Updater': [true, 'Update threads'] 'Thread Watcher': [true, 'Bookmark threads'] #utility @@ -800,6 +801,41 @@ threadF = (current) -> if current.nodeName isnt 'CENTER' threadF(current) +request = (url, callback) -> + r = new XMLHttpRequest() + r.onload = -> callback this + r.open 'get', url, true + r.send() + +updateCallback = (res) -> + body = n 'body', innerHTML: res.responseText + replies = $$ 'td.reply', body + + root = x './/br[@clear]/preceding::table[1]' + id = Number $('td.reply, td.replyhl', root).id + i = 0 + + while (reply = replies.pop()) and (Number reply.id > id) + table = x 'ancestor::table', reply + inAfter root, table + ++i + + $('#updater div.move').textContent = "+#{i}" + +updateNow = -> + request location.href, updateCallback + +updaterMake = -> + div = AEOS.makeDialog 'updater', 'topright' + html = "
Thread Updater
" + html += "
" + html += "
" + div.innerHTML = html + + $('div.move', div).addEventListener 'mousedown', AEOS.move, true + $('input[type=button]', div).addEventListener 'click', updateNow, true + document.body.appendChild div + watch = -> id = @nextSibling.name if @src is g.favEmpty @@ -913,6 +949,10 @@ if lastChecked < now - 1*DAY GM_setValue('lastChecked', now) GM_addStyle ' + #updater { + position: fixed; + text-align: right; + } #watcher { position: absolute; } @@ -1154,6 +1194,8 @@ if getConfig 'Keybinds' document.addEventListener 'keypress', keypress, true if g.REPLY + if getConfig 'Thread Updater' + updaterMake() if getConfig('Quick Reply') and getConfig 'Persistent QR' quickReply() $('#qr input[title=autohide]').click() diff --git a/4chan_x.js b/4chan_x.js index d0b6fcea4..a15f93314 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1,5 +1,5 @@ (function() { - var $, $$, AEOS, DAY, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expand, expandComment, expandThread, formSubmit, g, getConfig, getThread, getTime, hide, hideReply, hideThread, href, html, i, id, iframe, iframeLoad, imageClick, imageExpandClick, imageFull, imageThumb, imageToggle, img, inAfter, inBefore, input, inputs, keyModeInsert, keyModeNormal, keydown, keypress, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, qrListener, qrText, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, scroll, show, showReply, showThread, slice, span, src, start, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, tzOffset, up, watch, watchX, watcher, watcherUpdate, x, zeroPad, _, _base, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4; + var $, $$, AEOS, DAY, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expand, expandComment, expandThread, formSubmit, g, getConfig, getThread, getTime, hide, hideReply, hideThread, href, html, i, id, iframe, iframeLoad, imageClick, imageExpandClick, imageFull, imageThumb, imageToggle, img, inAfter, inBefore, input, inputs, keyModeInsert, keyModeNormal, keydown, keypress, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, qrListener, qrText, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, request, scroll, show, showReply, showThread, slice, span, src, start, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, tzOffset, up, updateCallback, updateNow, updaterMake, watch, watchX, watcher, watcherUpdate, x, zeroPad, _, _base, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4; var __slice = Array.prototype.slice, __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (this[i] === item) return i; @@ -25,6 +25,7 @@ 'Thread Expansion': [true, 'View all replies'], 'Thread Hiding': [true, 'Hide entire threads'], 'Thread Navigation': [true, 'Navigate to previous / next thread'], + 'Thread Updater': [true, 'Update threads'], 'Thread Watcher': [true, 'Bookmark threads'] }; AEOS = { @@ -1057,6 +1058,45 @@ return threadF(current); } }; + request = function(url, callback) { + var r; + r = new XMLHttpRequest(); + r.onload = function() { + return callback(this); + }; + r.open('get', url, true); + return r.send(); + }; + updateCallback = function(res) { + var body, i, id, replies, reply, root, table; + body = n('body', { + innerHTML: res.responseText + }); + replies = $$('td.reply', body); + root = x('.//br[@clear]/preceding::table[1]'); + id = Number($('td.reply, td.replyhl', root).id); + i = 0; + while ((reply = replies.pop()) && (Number(reply.id > id))) { + table = x('ancestor::table', reply); + inAfter(root, table); + ++i; + } + return $('#updater div.move').textContent = "+" + i; + }; + updateNow = function() { + return request(location.href, updateCallback); + }; + updaterMake = function() { + var div, html; + div = AEOS.makeDialog('updater', 'topright'); + html = "
Thread Updater
"; + html += "
"; + html += "
"; + div.innerHTML = html; + $('div.move', div).addEventListener('mousedown', AEOS.move, true); + $('input[type=button]', div).addEventListener('click', updateNow, true); + return document.body.appendChild(div); + }; watch = function() { var id, text, _base, _name; id = this.nextSibling.name; @@ -1180,6 +1220,10 @@ GM_setValue('lastChecked', now); } GM_addStyle('\ + #updater {\ + position: fixed;\ + text-align: right;\ + }\ #watcher {\ position: absolute;\ }\ @@ -1486,6 +1530,9 @@ document.addEventListener('keypress', keypress, true); } if (g.REPLY) { + if (getConfig('Thread Updater')) { + updaterMake(); + } if (getConfig('Quick Reply') && getConfig('Persistent QR')) { quickReply(); $('#qr input[title=autohide]').click();