document -> d

This commit is contained in:
James Campos 2010-10-19 21:59:43 -07:00
parent d86bde6f4f
commit 0642cb9e0b
2 changed files with 33 additions and 31 deletions

View File

@ -124,12 +124,13 @@ AEOS =
GM_setValue "#{id}Left", div.style.left GM_setValue "#{id}Left", div.style.left
GM_setValue "#{id}Top", div.style.top GM_setValue "#{id}Top", div.style.top
d = document
#utility funks #utility funks
$ = (selector, root) -> $ = (selector, root) ->
root or= document.body root or= d.body
root.querySelector(selector) root.querySelector(selector)
$$ = (selector, root) -> $$ = (selector, root) ->
root or= document.body root or= d.body
result = root.querySelectorAll(selector) result = root.querySelectorAll(selector)
#magic that turns the results object into an array: #magic that turns the results object into an array:
node for node in result node for node in result
@ -147,7 +148,7 @@ inAfter = (root, el) ->
inBefore = (root, el) -> inBefore = (root, el) ->
root.parentNode.insertBefore(el, root) root.parentNode.insertBefore(el, root)
n = (tag, props) -> #new n = (tag, props) -> #new
el = document.createElement tag el = d.createElement tag
if props if props
if l = props.listener if l = props.listener
delete props.listener delete props.listener
@ -183,10 +184,10 @@ slice = (arr, id) ->
return arr return arr
i++ i++
tn = (s) -> tn = (s) ->
document.createTextNode s d.createTextNode s
x = (path, root) -> x = (path, root) ->
root or= document.body root or= d.body
document. d.
evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null). evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).
singleNodeValue singleNodeValue
@ -201,7 +202,7 @@ if location.hostname.split('.')[0] is 'sys'
html = $('b').innerHTML html = $('b').innerHTML
[nop, thread, id] = html.match(/<!-- thread:(\d+),no:(\d+) -->/) [nop, thread, id] = html.match(/<!-- thread:(\d+),no:(\d+) -->/)
if thread is '0' if thread is '0'
board = $('meta', document).content.match(/4chan.org\/(\w+)\//)[1] board = $('meta', d).content.match(/4chan.org\/(\w+)\//)[1]
watched[board] or= [] watched[board] or= []
watched[board].push({ watched[board].push({
id: id, id: id,
@ -220,7 +221,7 @@ r = null
iframeLoop = false iframeLoop = false
callbacks = [] callbacks = []
#godammit moot #godammit moot
head = $('head', document) head = $('head', d)
if not favicon = $('link[rel="shortcut icon"]', head)#/f/ if not favicon = $('link[rel="shortcut icon"]', head)#/f/
favicon = n 'link', { favicon = n 'link', {
rel: 'shortcut icon' rel: 'shortcut icon'
@ -343,7 +344,7 @@ options = ->
$('input[type="button"]', div).addEventListener('click', clearHidden, true) $('input[type="button"]', div).addEventListener('click', clearHidden, true)
$('a[name="save"]', div).addEventListener('click', optionsSave, true) $('a[name="save"]', div).addEventListener('click', optionsSave, true)
$('a[name="cancel"]', div).addEventListener('click', close, true) $('a[name="cancel"]', div).addEventListener('click', close, true)
addTo document.body, div addTo d.body, div
showThread = -> showThread = ->
@ -553,7 +554,7 @@ quickReply = (e) ->
} }
addTo clone, input addTo clone, input
addTo qr, clone addTo qr, clone
addTo document.body, qr addTo d.body, qr
if e if e
e.preventDefault() e.preventDefault()
@ -784,7 +785,7 @@ if getConfig('Quick Reply')
listener: ['load', iframeLoad] listener: ['load', iframeLoad]
} }
hide(iframe) hide(iframe)
addTo document.body, iframe addTo d.body, iframe
callbacks.push((root) -> callbacks.push((root) ->
quotes = $$('a.quotejs:not(:first-child)', root) quotes = $$('a.quotejs:not(:first-child)', root)
@ -818,7 +819,7 @@ if getConfig('Thread Watcher')
} }
position(watcher) position(watcher)
$('div', watcher).addEventListener('mousedown', AEOS.move, true) $('div', watcher).addEventListener('mousedown', AEOS.move, true)
addTo document.body, watcher addTo d.body, watcher
watcherUpdate() watcherUpdate()
#add buttons #add buttons
@ -880,9 +881,9 @@ else # not reply
if getConfig('Thread Hiding') if getConfig('Thread Hiding')
delform = $('form[name=delform]') delform = $('form[name=delform]')
#don't confuse other scripts #don't confuse other scripts
document.addEventListener('DOMNodeInserted', stopPropagation, true) d.addEventListener('DOMNodeInserted', stopPropagation, true)
threadF(delform.firstChild) threadF(delform.firstChild)
document.removeEventListener('DOMNodeInserted', stopPropagation, true) d.removeEventListener('DOMNodeInserted', stopPropagation, true)
if getConfig('Auto Watch') if getConfig('Auto Watch')
$('form[name="post"]').addEventListener('submit', autoWatch, true) $('form[name="post"]').addEventListener('submit', autoWatch, true)
@ -947,4 +948,4 @@ else # not reply
for callback in callbacks for callback in callbacks
callback() callback()
document.body.addEventListener('DOMNodeInserted', nodeInserted, true) d.body.addEventListener('DOMNodeInserted', nodeInserted, true)

View File

@ -1,5 +1,5 @@
(function() { (function() {
var $, $$, AEOS, BOARD, DAY, PAGENUM, REPLY, _i, _j, _len, _len2, _ref, _ref2, a, addTo, arr, as, autoWatch, autohide, b, board, callback, callbacks, clearHidden, close, config, cutoff, delform, down, el, expandComment, expandThread, favEmpty, favNormal, favicon, getConfig, getTime, head, hiddenReplies, hiddenThreads, hide, hideReply, hideThread, href, html, i, i1, id, iframe, iframeLoad, iframeLoop, img, inAfter, inBefore, input, inputs, l, l1, lastChecked, magic, n, navtopr, nodeInserted, nop, now, omitted, onloadComment, onloadThread, options, optionsSave, parseResponse, position, quickReply, r, remove, replace, replyNav, report, show, showReply, showThread, slice, span, src, stopPropagation, submit, text, textContent, thread, threadF, threads, tn, up, watch, watchX, watched, watcher, watcherUpdate, x, xhrs; var $, $$, AEOS, BOARD, DAY, PAGENUM, REPLY, _i, _j, _len, _len2, _ref, _ref2, a, addTo, arr, as, autoWatch, autohide, b, board, callback, callbacks, clearHidden, close, config, cutoff, d, delform, down, el, expandComment, expandThread, favEmpty, favNormal, favicon, getConfig, getTime, head, hiddenReplies, hiddenThreads, hide, hideReply, hideThread, href, html, i, i1, id, iframe, iframeLoad, iframeLoop, img, inAfter, inBefore, input, inputs, l, l1, lastChecked, magic, n, navtopr, nodeInserted, nop, now, omitted, onloadComment, onloadThread, options, optionsSave, parseResponse, position, quickReply, r, remove, replace, replyNav, report, show, showReply, showThread, slice, span, src, stopPropagation, submit, text, textContent, thread, threadF, threads, tn, up, watch, watchX, watched, watcher, watcherUpdate, x, xhrs;
var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty; var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
config = { config = {
'Thread Hiding': true, 'Thread Hiding': true,
@ -137,13 +137,14 @@
return GM_setValue("" + (id) + "Top", div.style.top); return GM_setValue("" + (id) + "Top", div.style.top);
} }
}; };
d = document;
$ = function(selector, root) { $ = function(selector, root) {
root || (root = document.body); root || (root = d.body);
return root.querySelector(selector); return root.querySelector(selector);
}; };
$$ = function(selector, root) { $$ = function(selector, root) {
var _i, _len, _ref, _result, node, result; var _i, _len, _ref, _result, node, result;
root || (root = document.body); root || (root = d.body);
result = root.querySelectorAll(selector); result = root.querySelectorAll(selector);
_result = []; _ref = result; _result = []; _ref = result;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -179,7 +180,7 @@
}; };
n = function(tag, props) { n = function(tag, props) {
var _ref, el, event, funk, key, l, val; var _ref, el, event, funk, key, l, val;
el = document.createElement(tag); el = d.createElement(tag);
if (props) { if (props) {
if (l = props.listener) { if (l = props.listener) {
delete props.listener; delete props.listener;
@ -231,11 +232,11 @@
return _result; return _result;
}; };
tn = function(s) { tn = function(s) {
return document.createTextNode(s); return d.createTextNode(s);
}; };
x = function(path, root) { x = function(path, root) {
root || (root = document.body); root || (root = d.body);
return document.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue; return d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
}; };
watched = JSON.parse(GM_getValue('watched', '{}')); watched = JSON.parse(GM_getValue('watched', '{}'));
if (location.hostname.split('.')[0] === 'sys') { if (location.hostname.split('.')[0] === 'sys') {
@ -250,7 +251,7 @@
thread = _ref[1]; thread = _ref[1];
id = _ref[2]; id = _ref[2];
if (thread === '0') { if (thread === '0') {
board = $('meta', document).content.match(/4chan.org\/(\w+)\//)[1]; board = $('meta', d).content.match(/4chan.org\/(\w+)\//)[1];
watched[board] || (watched[board] = []); watched[board] || (watched[board] = []);
watched[board].push({ watched[board].push({
id: id, id: id,
@ -275,7 +276,7 @@
r = null; r = null;
iframeLoop = false; iframeLoop = false;
callbacks = []; callbacks = [];
head = $('head', document); head = $('head', d);
if (!(favicon = $('link[rel="shortcut icon"]', head))) { if (!(favicon = $('link[rel="shortcut icon"]', head))) {
favicon = n('link', { favicon = n('link', {
rel: 'shortcut icon', rel: 'shortcut icon',
@ -398,7 +399,7 @@
$('input[type="button"]', div).addEventListener('click', clearHidden, true); $('input[type="button"]', div).addEventListener('click', clearHidden, true);
$('a[name="save"]', div).addEventListener('click', optionsSave, true); $('a[name="save"]', div).addEventListener('click', optionsSave, true);
$('a[name="cancel"]', div).addEventListener('click', close, true); $('a[name="cancel"]', div).addEventListener('click', close, true);
return addTo(document.body, div); return addTo(d.body, div);
} }
}; };
showThread = function() { showThread = function() {
@ -618,7 +619,7 @@
addTo(clone, input); addTo(clone, input);
} }
addTo(qr, clone); addTo(qr, clone);
addTo(document.body, qr); addTo(d.body, qr);
} }
if (e) { if (e) {
e.preventDefault(); e.preventDefault();
@ -886,7 +887,7 @@
listener: ['load', iframeLoad] listener: ['load', iframeLoad]
}); });
hide(iframe); hide(iframe);
addTo(document.body, iframe); addTo(d.body, iframe);
callbacks.push(function(root) { callbacks.push(function(root) {
var _j, _len2, _ref2, _result, quote, quotes; var _j, _len2, _ref2, _result, quote, quotes;
quotes = $$('a.quotejs:not(:first-child)', root); quotes = $$('a.quotejs:not(:first-child)', root);
@ -927,7 +928,7 @@
}); });
position(watcher); position(watcher);
$('div', watcher).addEventListener('mousedown', AEOS.move, true); $('div', watcher).addEventListener('mousedown', AEOS.move, true);
addTo(document.body, watcher); addTo(d.body, watcher);
watcherUpdate(); watcherUpdate();
threads = watched[BOARD] || []; threads = watched[BOARD] || [];
inputs = $$('form > input[value="delete"], div > input[value="delete"]'); inputs = $$('form > input[value="delete"], div > input[value="delete"]');
@ -1004,9 +1005,9 @@
} else { } else {
if (getConfig('Thread Hiding')) { if (getConfig('Thread Hiding')) {
delform = $('form[name=delform]'); delform = $('form[name=delform]');
document.addEventListener('DOMNodeInserted', stopPropagation, true); d.addEventListener('DOMNodeInserted', stopPropagation, true);
threadF(delform.firstChild); threadF(delform.firstChild);
document.removeEventListener('DOMNodeInserted', stopPropagation, true); d.removeEventListener('DOMNodeInserted', stopPropagation, true);
} }
if (getConfig('Auto Watch')) { if (getConfig('Auto Watch')) {
$('form[name="post"]').addEventListener('submit', autoWatch, true); $('form[name="post"]').addEventListener('submit', autoWatch, true);
@ -1083,5 +1084,5 @@
callback = _ref[_i]; callback = _ref[_i];
callback(); callback();
} }
document.body.addEventListener('DOMNodeInserted', nodeInserted, true); d.body.addEventListener('DOMNodeInserted', nodeInserted, true);
}).call(this); }).call(this);