This commit is contained in:
James Campos 2011-01-15 17:34:17 -08:00
parent 97336afc5f
commit d13c1fc611
2 changed files with 63 additions and 60 deletions

View File

@ -96,7 +96,7 @@ class Dialog
if left then el.style.left = left else el.style.right = '0px'
if top then el.style.top = top else el.style.bottom = '0px'
$('div.move', el).addEventListener 'mousedown', @move, true
$('div.move a[name=close]', el)?.addEventListener 'click', (-> remove el), true
$('div.move a[name=close]', el)?.addEventListener 'click', (-> rm el), true
move: (e) =>
el = @el
#distance from pointer to el edge is constant; calculate it here.
@ -134,11 +134,9 @@ d = document
g = null #globals
#utility
$ = (selector, root) ->
root or= d.body
$ = (selector, root=d.body) ->
root.querySelector selector
$$ = (selector, root) ->
root or= d.body
$$ = (selector, root=d.body) ->
result = root.querySelectorAll selector
#magic that turns the results object into an array:
node for node in result
@ -166,7 +164,7 @@ n = (tag, props) -> #new
el = d.createElement tag
if props then m el, props
el
remove = (el) ->
rm = (el) ->
el.parentNode.removeChild el
replace = (root, el) ->
root.parentNode.replaceChild el, root
@ -185,8 +183,7 @@ slice = (arr, id) ->
i++
tn = (s) ->
d.createTextNode s
x = (path, root) ->
root or= d.body
x = (path, root=d.body) ->
d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).
singleNodeValue
zeroPad = (n) ->
@ -209,7 +206,7 @@ autoWatch = ->
closeQR = ->
div = @parentNode.parentNode
remove div
rm div
clearHidden = ->
#'hidden' might be misleading; it's the number of IDs we're *looking* for,
@ -261,7 +258,7 @@ expandThread = ->
num = if board is 'b' then 3 else 5
table = x "following::br[@clear][1]/preceding::table[#{num}]", span
while (prev = table.previousSibling) and (prev.nodeName is 'TABLE')
remove prev
rm prev
span.textContent = span.textContent.replace '-', '+'
return
span.textContent = span.textContent.replace '+', 'X Loading...'
@ -291,7 +288,7 @@ getThread = ->
formSubmit = (e) ->
if span = @nextSibling
remove span
rm span
recaptcha = $('input[name=recaptcha_response_field]', this)
if recaptcha.value
$('#qr input[title=autohide]:not(:checked)')?.click()
@ -372,7 +369,7 @@ iframeLoad = ->
#unhide the qr so you know it's ready for the next item
$('input[title=autohide]:checked', qr)?.click()
else
remove qr
rm qr
recaptchaReload()
imageClick = (e) ->
@ -413,7 +410,7 @@ imageFull = (thumb) ->
imageThumb = (thumb) ->
#thumbify the image - show thumb, remove full sized image
thumb.className = ''
remove thumb.nextSibling
rm thumb.nextSibling
keydown = (e) ->
kc = e.keyCode
@ -421,7 +418,7 @@ keydown = (e) ->
g.char = String.fromCharCode kc
keypress = (e) ->
if document.activeElement.nodeName in ['TEXTAREA', 'INPUT']
if d.activeElement.nodeName in ['TEXTAREA', 'INPUT']
keyModeInsert e
else
keyModeNormal e
@ -430,10 +427,10 @@ keyModeInsert = (e) ->
kc = g.keyCode
char = g.char
if kc is 27 #escape
remove $ '#qr'
rm $ '#qr'
e.preventDefault()
else if e.ctrlKey and char is "S"
ta = document.activeElement
ta = d.activeElement
return unless ta.nodeName is 'TEXTAREA'
value = ta.value
@ -567,7 +564,7 @@ onloadThread = (responseText, span) ->
#make sure all comments are fully expanded
span.previousSibling.innerHTML = opbq.innerHTML
while (next = span.nextSibling) and not next.clear#<br clear>
remove next
rm next
if next
for reply in replies
inBefore next, x('ancestor::table', reply)
@ -584,7 +581,7 @@ changeText = ->
options = ->
if div = $ '#options'
remove div
rm div
return
hiddenNum = g.hiddenReplies.length + g.hiddenThreads.length
@ -639,7 +636,7 @@ quickReply = (link, text) ->
clone = form.cloneNode true
#remove recaptcha scripts
for script in $$ 'script', clone
remove script
rm script
m $('input[name=recaptcha_response_field]', clone),
listener: ['keydown', recaptchaListener]
m clone,
@ -722,11 +719,11 @@ scrollThread = (count) ->
showReply = ->
div = @parentNode
table = div.nextSibling
show(table)
remove(div)
show table
rm div
id = $('td.reply, td.replyhl', table).id
slice(g.hiddenReplies, id)
GM_setValue("hiddenReplies/#{g.BOARD}/", JSON.stringify(g.hiddenReplies))
slice g.hiddenReplies, id
GM_setValue "hiddenReplies/#{g.BOARD}/", JSON.stringify(g.hiddenReplies)
showThread = ->
div = @nextSibling
@ -784,7 +781,7 @@ updateCallback = ->
s = ''
if getConfig 'Unread Count' then s += "(#{g.replies.length}) "
s += "/#{g.BOARD}/ - 404"
document.title = s
d.title = s
g.dead = true
updateFavicon()
return
@ -842,7 +839,7 @@ updateTime = ->
updateTitle = ->
len = g.replies.length
document.title = document.title.replace /\d+/, len
d.title = d.title.replace /\d+/, len
updateFavicon()
updateAuto = ->
@ -881,7 +878,7 @@ updaterMake = ->
interval.value = GM_getValue 'Interval', 10
interval.addEventListener 'change', updateInterval, true
$('input[type=button]', div).addEventListener 'click', updateNow, true
document.body.appendChild div
d.body.appendChild div
if getConfig 'Auto Update' then auto.click()
watch = ->
@ -1100,7 +1097,7 @@ recaptcha = $ '#recaptcha_response_field'
recaptcha.addEventListener('keydown', recaptchaListener, true)
scroll = ->
height = document.body.clientHeight
height = d.body.clientHeight
for reply, i in g.replies
bottom = reply.getBoundingClientRect().bottom
if bottom > height #post is not completely read
@ -1246,9 +1243,9 @@ if getConfig 'Anonymize'
trips = $$('span.postertrip', root)
for trip in trips
if trip.parentNode.nodeName is 'A'
remove(trip.parentNode)
rm trip.parentNode
else
remove(trip)
rm trip
if getConfig 'Reply Navigation'
g.callbacks.push (root) ->
@ -1267,8 +1264,8 @@ if getConfig 'Reply Navigation'
inAfter el, span
if getConfig 'Keybinds'
document.addEventListener 'keydown', keydown, true
document.addEventListener 'keypress', keypress, true
d.addEventListener 'keydown', keydown, true
d.addEventListener 'keypress', keypress, true
if g.REPLY
if getConfig 'Thread Updater'
@ -1283,8 +1280,8 @@ if g.REPLY
d.title = "/#{g.BOARD}/ - #{text}"
if getConfig 'Unread Count'
g.replies = []
document.title = '(0) ' + document.title
document.addEventListener 'scroll', scroll, true
d.title = '(0) ' + d.title
d.addEventListener 'scroll', scroll, true
g.callbacks.push (root) ->
g.replies = g.replies.concat $$ 'td.reply, td.replyhl', root
updateTitle()

View File

@ -1,5 +1,5 @@
(function() {
var $, $$, DAY, Dialog, a, addTo, arr, as, autoWatch, autohide, b, board, callback, changeCheckbox, changeText, 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, parseResponse, pathname, qrListener, qrText, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, request, scroll, scrollThread, show, showReply, showThread, slice, span, src, start, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, tzOffset, up, updateAuto, updateCallback, updateFavicon, updateInterval, updateNow, updateTime, updateTitle, updaterMake, watch, watchX, watcher, watcherUpdate, x, zeroPad, _, _base, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4, _ref5;
var $, $$, DAY, Dialog, a, addTo, arr, as, autoWatch, autohide, b, board, callback, changeCheckbox, changeText, 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, parseResponse, pathname, qrListener, qrText, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, replace, replyNav, report, request, rm, scroll, scrollThread, show, showReply, showThread, slice, span, src, start, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, tzOffset, up, updateAuto, updateCallback, updateFavicon, updateInterval, updateNow, updateTime, updateTitle, updaterMake, watch, watchX, watcher, watcherUpdate, x, zeroPad, _, _base, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4, _ref5;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = Array.prototype.slice;
config = {
'404 Redirect': [true, 'Redirect dead threads'],
@ -114,7 +114,7 @@
$('div.move', el).addEventListener('mousedown', this.move, true);
if ((_ref = $('div.move a[name=close]', el)) != null) {
_ref.addEventListener('click', (function() {
return remove(el);
return rm(el);
}), true);
}
}
@ -164,12 +164,16 @@
d = document;
g = null;
$ = function(selector, root) {
root || (root = d.body);
if (root == null) {
root = d.body;
}
return root.querySelector(selector);
};
$$ = function(selector, root) {
var node, result, _i, _len, _results;
root || (root = d.body);
if (root == null) {
root = d.body;
}
result = root.querySelectorAll(selector);
_results = [];
for (_i = 0, _len = result.length; _i < _len; _i++) {
@ -224,7 +228,7 @@
}
return el;
};
remove = function(el) {
rm = function(el) {
return el.parentNode.removeChild(el);
};
replace = function(root, el) {
@ -251,7 +255,9 @@
return d.createTextNode(s);
};
x = function(path, root) {
root || (root = d.body);
if (root == null) {
root = d.body;
}
return d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
};
zeroPad = function(n) {
@ -280,7 +286,7 @@
closeQR = function() {
var div;
div = this.parentNode.parentNode;
return remove(div);
return rm(div);
};
clearHidden = function() {
GM_deleteValue("hiddenReplies/" + g.BOARD + "/");
@ -338,7 +344,7 @@
num = board === 'b' ? 3 : 5;
table = x("following::br[@clear][1]/preceding::table[" + num + "]", span);
while ((prev = table.previousSibling) && (prev.nodeName === 'TABLE')) {
remove(prev);
rm(prev);
}
span.textContent = span.textContent.replace('-', '+');
return;
@ -377,7 +383,7 @@
formSubmit = function(e) {
var recaptcha, span, _ref;
if (span = this.nextSibling) {
remove(span);
rm(span);
}
recaptcha = $('input[name=recaptcha_response_field]', this);
if (recaptcha.value) {
@ -477,7 +483,7 @@
}
}
} else {
remove(qr);
rm(qr);
}
return recaptchaReload();
};
@ -528,7 +534,7 @@
};
imageThumb = function(thumb) {
thumb.className = '';
return remove(thumb.nextSibling);
return rm(thumb.nextSibling);
};
keydown = function(e) {
var kc;
@ -538,7 +544,7 @@
};
keypress = function(e) {
var _ref;
if ((_ref = document.activeElement.nodeName) === 'TEXTAREA' || _ref === 'INPUT') {
if ((_ref = d.activeElement.nodeName) === 'TEXTAREA' || _ref === 'INPUT') {
return keyModeInsert(e);
} else {
return keyModeNormal(e);
@ -549,10 +555,10 @@
kc = g.keyCode;
char = g.char;
if (kc === 27) {
remove($('#qr'));
rm($('#qr'));
return e.preventDefault();
} else if (e.ctrlKey && char === "S") {
ta = document.activeElement;
ta = d.activeElement;
if (ta.nodeName !== 'TEXTAREA') {
return;
}
@ -728,7 +734,7 @@
span.textContent = span.textContent.replace('X Loading...', '- ');
span.previousSibling.innerHTML = opbq.innerHTML;
while ((next = span.nextSibling) && !next.clear) {
remove(next);
rm(next);
}
if (next) {
_results = [];
@ -756,7 +762,7 @@
options = function() {
var checked, description, div, hiddenNum, html, input, option, value, _i, _len, _ref;
if (div = $('#options')) {
remove(div);
rm(div);
return;
}
hiddenNum = g.hiddenReplies.length + g.hiddenThreads.length;
@ -817,7 +823,7 @@
_ref = $$('script', clone);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
script = _ref[_i];
remove(script);
rm(script);
}
m($('input[name=recaptcha_response_field]', clone), {
listener: ['keydown', recaptchaListener]
@ -931,7 +937,7 @@
div = this.parentNode;
table = div.nextSibling;
show(table);
remove(div);
rm(div);
id = $('td.reply, td.replyhl', table).id;
slice(g.hiddenReplies, id);
return GM_setValue("hiddenReplies/" + g.BOARD + "/", JSON.stringify(g.hiddenReplies));
@ -1008,7 +1014,7 @@
s += "(" + g.replies.length + ") ";
}
s += "/" + g.BOARD + "/ - 404";
document.title = s;
d.title = s;
g.dead = true;
updateFavicon();
return;
@ -1073,7 +1079,7 @@
updateTitle = function() {
var len;
len = g.replies.length;
document.title = document.title.replace(/\d+/, len);
d.title = d.title.replace(/\d+/, len);
return updateFavicon();
};
updateAuto = function() {
@ -1117,7 +1123,7 @@
interval.value = GM_getValue('Interval', 10);
interval.addEventListener('change', updateInterval, true);
$('input[type=button]', div).addEventListener('click', updateNow, true);
document.body.appendChild(div);
d.body.appendChild(div);
if (getConfig('Auto Update')) {
return auto.click();
}
@ -1351,7 +1357,7 @@
recaptcha.addEventListener('keydown', recaptchaListener, true);
scroll = function() {
var bottom, height, i, reply, _len, _ref;
height = document.body.clientHeight;
height = d.body.clientHeight;
_ref = g.replies;
for (i = 0, _len = _ref.length; i < _len; i++) {
reply = _ref[i];
@ -1563,7 +1569,7 @@
_results = [];
for (_j = 0, _len2 = trips.length; _j < _len2; _j++) {
trip = trips[_j];
_results.push(trip.parentNode.nodeName === 'A' ? remove(trip.parentNode) : remove(trip));
_results.push(trip.parentNode.nodeName === 'A' ? rm(trip.parentNode) : rm(trip));
}
return _results;
});
@ -1593,8 +1599,8 @@
});
}
if (getConfig('Keybinds')) {
document.addEventListener('keydown', keydown, true);
document.addEventListener('keypress', keypress, true);
d.addEventListener('keydown', keydown, true);
d.addEventListener('keypress', keypress, true);
}
if (g.REPLY) {
if (getConfig('Thread Updater')) {
@ -1614,8 +1620,8 @@
}
if (getConfig('Unread Count')) {
g.replies = [];
document.title = '(0) ' + document.title;
document.addEventListener('scroll', scroll, true);
d.title = '(0) ' + d.title;
d.addEventListener('scroll', scroll, true);
g.callbacks.push(function(root) {
g.replies = g.replies.concat($$('td.reply, td.replyhl', root));
return updateTitle();