This commit is contained in:
James Campos 2011-03-27 13:25:37 -07:00
parent bcb5b64d9b
commit 520a2f32d1
2 changed files with 40 additions and 40 deletions

View File

@ -56,7 +56,7 @@
*/ */
(function() { (function() {
var $, $$, DAY, a, arr, as, autoWatch, callback, changeCheckbox, changeValue, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expand, expandComment, expandThread, g, getConfig, getThread, hideReply, hideThread, href, html, i, id, imageClick, imageExpand, imageExpandClick, imageHover, imageResize, imageThumb, imageToggle, imageType, imageTypeChange, img, inAfter, input, inputs, keyModeInsert, keyModeNormal, keydown, keypress, l1, lastChecked, log, mv, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, option, options, parseResponse, pathname, qr, recaptcha, recaptchaListener, recaptchaReload, redirect, replyNav, report, request, scroll, scrollThread, showReply, showThread, slice, span, src, start, stopPropagation, temp, text, textContent, threadF, threads, tzOffset, ui, up, updateAuto, updateCallback, updateFavicon, updateInterval, updateNow, updateTime, updateTitle, updateVerbose, updaterMake, watch, watchX, watcher, watcherUpdate, x, zeroPad, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _len7, _m, _n, _ref, _ref2, _ref3, _ref4; var $, $$, DAY, a, arr, as, autoWatch, callback, changeCheckbox, changeValue, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expand, expandComment, expandThread, g, getConfig, getThread, hideReply, hideThread, href, html, i, id, imageClick, imageExpand, imageExpandClick, imageHover, imageResize, imageThumb, imageToggle, imageType, imageTypeChange, img, inAfter, input, inputs, keyModeInsert, keyModeNormal, keydown, keypress, l1, lastChecked, log, mv, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, option, options, parseResponse, pathname, qr, recaptcha, recaptchaListener, recaptchaReload, redirect, replyNav, report, request, scroll, scrollThread, showReply, showThread, slice, span, src, start, stopPropagation, temp, text, textContent, threadF, threads, tzOffset, ui, up, updateAuto, updateCallback, updateFavicon, updateInterval, updateNow, updateTime, updateTitle, updateVerbose, updaterMake, watch, watchX, watcher, watcherUpdate, zeroPad, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _len7, _m, _n, _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;
@ -242,6 +242,12 @@
return object; return object;
}; };
$.extend($, { $.extend($, {
x: function(path, root) {
if (root == null) {
root = d.body;
}
return d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
},
tn: function(s) { tn: function(s) {
return d.createTextNode(s); return d.createTextNode(s);
}, },
@ -368,12 +374,6 @@
} }
return _results; return _results;
}; };
x = function(path, root) {
if (root == null) {
root = d.body;
}
return d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
};
zeroPad = function(n) { zeroPad = function(n) {
if (n < 10) { if (n < 10) {
return '0' + n; return '0' + n;
@ -441,11 +441,11 @@
}; };
expandThread = function() { expandThread = function() {
var id, num, prev, r, span, table, xhr, _i, _len, _ref; var id, num, prev, r, span, table, xhr, _i, _len, _ref;
id = x('preceding-sibling::input[1]', this).name; id = $.x('preceding-sibling::input[1]', this).name;
span = this; span = this;
if (span.textContent[0] === '-') { if (span.textContent[0] === '-') {
num = board === 'b' ? 3 : 5; num = board === 'b' ? 3 : 5;
table = x("following::br[@clear][1]/preceding::table[" + num + "]", span); table = $.x("following::br[@clear][1]/preceding::table[" + num + "]", span);
while ((prev = table.previousSibling) && (prev.nodeName === 'TABLE')) { while ((prev = table.previousSibling) && (prev.nodeName === 'TABLE')) {
$.remove(prev); $.remove(prev);
} }
@ -495,7 +495,7 @@
} }
name = $('span.commentpostername', reply).textContent; name = $('span.commentpostername', reply).textContent;
trip = ((_ref = $('span.postertrip', reply)) != null ? _ref.textContent : void 0) || ''; trip = ((_ref = $('span.postertrip', reply)) != null ? _ref.textContent : void 0) || '';
table = x('ancestor::table', reply); table = $.x('ancestor::table', reply);
$.hide(table); $.hide(table);
if (getConfig('Show Stubs')) { if (getConfig('Show Stubs')) {
a = $.el('a', { a = $.el('a', {
@ -662,7 +662,7 @@
}; };
imageResize = function(cw, ch, imageType, image) { imageResize = function(cw, ch, imageType, image) {
var ih, iw, ratio, _, _ref; var ih, iw, ratio, _, _ref;
_ref = x("preceding::span[@class][1]/text()[2]", image).textContent.match(/(\d+)x(\d+)/), _ = _ref[0], iw = _ref[1], ih = _ref[2]; _ref = $.x("preceding::span[@class][1]/text()[2]", image).textContent.match(/(\d+)x(\d+)/), _ = _ref[0], iw = _ref[1], ih = _ref[2];
iw = Number(iw); iw = Number(iw);
ih = Number(ih); ih = Number(ih);
switch (imageType) { switch (imageType) {
@ -774,7 +774,7 @@
td.className = 'reply'; td.className = 'reply';
rect = td.getBoundingClientRect(); rect = td.getBoundingClientRect();
if (rect.top > 0 && rect.bottom < d.body.clientHeight) { if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
next = x('following::td[@class="reply"]', td); next = $.x('following::td[@class="reply"]', td);
rect = next.getBoundingClientRect(); rect = next.getBoundingClientRect();
if (rect.top > 0 && rect.bottom < d.body.clientHeight) { if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
next.className = 'replyhl'; next.className = 'replyhl';
@ -802,7 +802,7 @@
td.className = 'reply'; td.className = 'reply';
rect = td.getBoundingClientRect(); rect = td.getBoundingClientRect();
if (rect.top > 0 && rect.bottom < d.body.clientHeight) { if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
prev = x('preceding::td[@class="reply"][1]', td); prev = $.x('preceding::td[@class="reply"][1]', td);
rect = prev.getBoundingClientRect(); rect = prev.getBoundingClientRect();
if (rect.top > 0 && rect.bottom < d.body.clientHeight) { if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
prev.className = 'replyhl'; prev.className = 'replyhl';
@ -885,7 +885,7 @@
} }
} }
} }
bq = x('ancestor::blockquote', a); bq = $.x('ancestor::blockquote', a);
return bq.innerHTML = html; return bq.innerHTML = html;
}; };
onloadThread = function(responseText, span) { onloadThread = function(responseText, span) {
@ -900,7 +900,7 @@
_results = []; _results = [];
for (_i = 0, _len = replies.length; _i < _len; _i++) { for (_i = 0, _len = replies.length; _i < _len; _i++) {
reply = replies[_i]; reply = replies[_i];
_results.push($.before(next, x('ancestor::table', reply))); _results.push($.before(next, $.x('ancestor::table', reply)));
} }
return _results; return _results;
} else { } else {
@ -908,7 +908,7 @@
_results2 = []; _results2 = [];
for (_j = 0, _len2 = replies.length; _j < _len2; _j++) { for (_j = 0, _len2 = replies.length; _j < _len2; _j++) {
reply = replies[_j]; reply = replies[_j];
_results2.push(mv(x('ancestor::table', reply), div)); _results2.push(mv($.x('ancestor::table', reply), div));
} }
return _results2; return _results2;
} }
@ -1063,7 +1063,7 @@
text = ">>" + id + "\n"; text = ">>" + id + "\n";
selection = window.getSelection(); selection = window.getSelection();
if (s = selection.toString()) { if (s = selection.toString()) {
selectionID = (_ref = x('preceding::input[@type="checkbox"][1]', selection.anchorNode)) != null ? _ref.name : void 0; selectionID = (_ref = $.x('preceding::input[@type="checkbox"][1]', selection.anchorNode)) != null ? _ref.name : void 0;
if (selectionID === id) { if (selectionID === id) {
text += ">" + s + "\n"; text += ">" + s + "\n";
} }
@ -1111,7 +1111,7 @@
input = $.el('input', { input = $.el('input', {
type: 'hidden', type: 'hidden',
name: 'resto', name: 'resto',
value: x(xpath, link).name value: $.x(xpath, link).name
}); });
$.append(clone, input); $.append(clone, input);
} else if (getConfig('Persistent QR')) { } else if (getConfig('Persistent QR')) {
@ -1214,13 +1214,13 @@
return window.location = this.textContent === '▲' ? '#navtop' : '#navbot'; return window.location = this.textContent === '▲' ? '#navtop' : '#navbot';
} else { } else {
direction = this.textContent === '▲' ? 'preceding' : 'following'; direction = this.textContent === '▲' ? 'preceding' : 'following';
op = x("" + direction + "::span[starts-with(@id, 'nothread')][1]", this).id; op = $.x("" + direction + "::span[starts-with(@id, 'nothread')][1]", this).id;
return window.location = "#" + op; return window.location = "#" + op;
} }
}; };
report = function() { report = function() {
var input; var input;
input = x('preceding-sibling::input[1]', this); input = $.x('preceding-sibling::input[1]', this);
input.click(); input.click();
$('input[value="Report"]').click(); $('input[value="Report"]').click();
return input.click(); return input.click();
@ -1352,7 +1352,7 @@
count.className = l > 0 ? 'new' : ''; count.className = l > 0 ? 'new' : '';
} }
while (reply = arr.pop()) { while (reply = arr.pop()) {
table = x('ancestor::table', reply); table = $.x('ancestor::table', reply);
$.before(root, table); $.before(root, table);
} }
return timer.textContent = -1 * GM_getValue('Interval', 10); return timer.textContent = -1 * GM_getValue('Interval', 10);
@ -1487,7 +1487,7 @@
id = this.nextSibling.name; id = this.nextSibling.name;
if (this.src === g.favEmpty) { if (this.src === g.favEmpty) {
this.src = g.favDefault; this.src = g.favDefault;
text = ("/" + g.BOARD + "/ - ") + x('following-sibling::blockquote', this).textContent.slice(0, 25); text = ("/" + g.BOARD + "/ - ") + $.x('following-sibling::blockquote', this).textContent.slice(0, 25);
(_base = g.watched)[_name = g.BOARD] || (_base[_name] = []); (_base = g.watched)[_name = g.BOARD] || (_base[_name] = []);
g.watched[g.BOARD].push({ g.watched[g.BOARD].push({
id: id, id: id,

View File

@ -145,6 +145,9 @@ $.extend = (object, properties) ->
object object
$.extend $, $.extend $,
x: (path, root=d.body) ->
d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).
singleNodeValue
tn: (s) -> tn: (s) ->
d.createTextNode s d.createTextNode s
replace: (root, el) -> replace: (root, el) ->
@ -241,9 +244,6 @@ slice = (arr, id) ->
arr.splice i, 1 arr.splice i, 1
return arr return arr
i++ i++
x = (path, root=d.body) ->
d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).
singleNodeValue
zeroPad = (n) -> zeroPad = (n) ->
if n < 10 then '0' + n else n if n < 10 then '0' + n else n
@ -299,13 +299,13 @@ expandComment = (e) ->
} }
expandThread = -> expandThread = ->
id = x('preceding-sibling::input[1]', this).name id = $.x('preceding-sibling::input[1]', this).name
span = this span = this
#close expanded thread #close expanded thread
if span.textContent[0] is '-' if span.textContent[0] is '-'
#goddamit moot #goddamit moot
num = if board is 'b' then 3 else 5 num = if board is 'b' then 3 else 5
table = x "following::br[@clear][1]/preceding::table[#{num}]", span table = $.x "following::br[@clear][1]/preceding::table[#{num}]", span
while (prev = table.previousSibling) and (prev.nodeName is 'TABLE') while (prev = table.previousSibling) and (prev.nodeName is 'TABLE')
$.remove prev $.remove prev
span.textContent = span.textContent.replace '-', '+' span.textContent = span.textContent.replace '-', '+'
@ -345,7 +345,7 @@ hideReply = (reply) ->
GM_setValue("hiddenReplies/#{g.BOARD}/", JSON.stringify(g.hiddenReplies)) GM_setValue("hiddenReplies/#{g.BOARD}/", JSON.stringify(g.hiddenReplies))
name = $('span.commentpostername', reply).textContent name = $('span.commentpostername', reply).textContent
trip = $('span.postertrip', reply)?.textContent or '' trip = $('span.postertrip', reply)?.textContent or ''
table = x 'ancestor::table', reply table = $.x 'ancestor::table', reply
$.hide table $.hide table
if getConfig 'Show Stubs' if getConfig 'Show Stubs'
a = $.el 'a', a = $.el 'a',
@ -480,7 +480,7 @@ imageExpand = (thumb, cw, ch, imageType) ->
imageResize = (cw, ch, imageType, image) -> imageResize = (cw, ch, imageType, image) ->
[_, iw, ih] = [_, iw, ih] =
x("preceding::span[@class][1]/text()[2]", image) $.x("preceding::span[@class][1]/text()[2]", image)
.textContent.match(/(\d+)x(\d+)/) .textContent.match(/(\d+)x(\d+)/)
iw = Number iw iw = Number iw
ih = Number ih ih = Number ih
@ -575,7 +575,7 @@ keyModeNormal = (e) ->
td.className = 'reply' td.className = 'reply'
rect = td.getBoundingClientRect() rect = td.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #you're visible if rect.top > 0 and rect.bottom < d.body.clientHeight #you're visible
next = x 'following::td[@class="reply"]', td next = $.x 'following::td[@class="reply"]', td
rect = next.getBoundingClientRect() rect = next.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the next if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the next
next.className = 'replyhl' next.className = 'replyhl'
@ -594,7 +594,7 @@ keyModeNormal = (e) ->
td.className = 'reply' td.className = 'reply'
rect = td.getBoundingClientRect() rect = td.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #you're visible if rect.top > 0 and rect.bottom < d.body.clientHeight #you're visible
prev = x 'preceding::td[@class="reply"][1]', td prev = $.x 'preceding::td[@class="reply"][1]', td
rect = prev.getBoundingClientRect() rect = prev.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the prev if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the prev
prev.className = 'replyhl' prev.className = 'replyhl'
@ -652,7 +652,7 @@ onloadComment = (responseText, a, href) ->
for reply in replies for reply in replies
if reply.id == id if reply.id == id
html = $('blockquote', reply).innerHTML html = $('blockquote', reply).innerHTML
bq = x 'ancestor::blockquote', a bq = $.x 'ancestor::blockquote', a
bq.innerHTML = html bq.innerHTML = html
onloadThread = (responseText, span) -> onloadThread = (responseText, span) ->
@ -664,11 +664,11 @@ onloadThread = (responseText, span) ->
$.remove next $.remove next
if next if next
for reply in replies for reply in replies
$.before next, x('ancestor::table', reply) $.before next, $.x('ancestor::table', reply)
else#threading else#threading
div = span.parentNode div = span.parentNode
for reply in replies for reply in replies
mv x('ancestor::table', reply), div mv $.x('ancestor::table', reply), div
changeCheckbox = -> changeCheckbox = ->
GM_setValue @name, @checked GM_setValue @name, @checked
@ -794,7 +794,7 @@ qr =
selection = window.getSelection() selection = window.getSelection()
if s = selection.toString() if s = selection.toString()
selectionID = x('preceding::input[@type="checkbox"][1]', selection.anchorNode)?.name selectionID = $.x('preceding::input[@type="checkbox"][1]', selection.anchorNode)?.name
if selectionID == id if selectionID == id
text += ">#{s}\n" text += ">#{s}\n"
@ -836,7 +836,7 @@ qr =
input = $.el 'input', input = $.el 'input',
type: 'hidden' type: 'hidden'
name: 'resto' name: 'resto'
value: x(xpath, link).name value: $.x(xpath, link).name
$.append clone, input $.append clone, input
else if getConfig 'Persistent QR' else if getConfig 'Persistent QR'
submit = $ 'input[type=submit]', clone submit = $ 'input[type=submit]', clone
@ -898,11 +898,11 @@ replyNav = ->
window.location = if @textContent is '' then '#navtop' else '#navbot' window.location = if @textContent is '' then '#navtop' else '#navbot'
else else
direction = if @textContent is '' then 'preceding' else 'following' direction = if @textContent is '' then 'preceding' else 'following'
op = x("#{direction}::span[starts-with(@id, 'nothread')][1]", this).id op = $.x("#{direction}::span[starts-with(@id, 'nothread')][1]", this).id
window.location = "##{op}" window.location = "##{op}"
report = -> report = ->
input = x('preceding-sibling::input[1]', this) input = $.x('preceding-sibling::input[1]', this)
input.click() input.click()
$('input[value="Report"]').click() $('input[value="Report"]').click()
input.click() input.click()
@ -1015,7 +1015,7 @@ updateCallback = ->
#insert replies in order, so backlinks resolve #insert replies in order, so backlinks resolve
while reply = arr.pop() while reply = arr.pop()
table = x 'ancestor::table', reply table = $.x 'ancestor::table', reply
$.before root, table $.before root, table
timer.textContent = -1 * GM_getValue 'Interval', 10 timer.textContent = -1 * GM_getValue 'Interval', 10
@ -1131,7 +1131,7 @@ watch = ->
if @src is g.favEmpty if @src is g.favEmpty
@src = g.favDefault @src = g.favDefault
text = "/#{g.BOARD}/ - " + text = "/#{g.BOARD}/ - " +
x('following-sibling::blockquote', this).textContent.slice(0,25) $.x('following-sibling::blockquote', this).textContent.slice(0,25)
g.watched[g.BOARD] or= [] g.watched[g.BOARD] or= []
g.watched[g.BOARD].push { g.watched[g.BOARD].push {
id: id, id: id,