fix qr quoted text, upgrade to coffee-script 0.9.2

This commit is contained in:
James Campos 2010-08-25 05:01:29 -07:00
parent ef293264fa
commit 2773353820
2 changed files with 111 additions and 116 deletions

View File

@ -489,17 +489,16 @@ quickReply = (e) ->
qr.appendChild(clone) qr.appendChild(clone)
document.body.appendChild(qr) document.body.appendChild(qr)
selection = window.getSelection()
id = x('preceding::span[@id][1]', selection.anchorNode)?.id
text = selection.toString()
textarea = $('textarea', qr) textarea = $('textarea', qr)
textarea.focus() textarea.focus()
#we can't just use @textContent b/c of the xxxs. goddamit moot. #we can't just use @textContent b/c of the xxxs. goddamit moot.
textarea.value += '>>' + @parentNode.id.match(/\d+$/)[0] + '\n' textarea.value += '>>' + @parentNode.id.match(/\d+$/)[0] + '\n'
selection = window.getSelection() if text and id is this.parentNode.id
id = x('preceding::span[@id][1]', selection.anchorNode)?.id textarea.value += ">#{text}\n"
if id is this.parentNode.id
if selText = selection.toString()
textarea.value += ">#{selText}\n"
return
watch = -> watch = ->
id = this.nextSibling.name id = this.nextSibling.name

View File

@ -19,16 +19,16 @@
return GM_getValue(name, config[name]); return GM_getValue(name, config[name]);
}; };
x = function(path, root) { x = function(path, root) {
root = root || document.body; root || (root = document.body);
return document.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue; return document.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
}; };
$ = function(selector, root) { $ = function(selector, root) {
root = root || document.body; root || (root = document.body);
return root.querySelector(selector); return root.querySelector(selector);
}; };
$$ = function(selector, root) { $$ = function(selector, root) {
var _a, _b, _c, _d, node, result; var _a, _b, _c, _d, node, result;
root = root || document.body; root || (root = document.body);
result = root.querySelectorAll(selector); result = root.querySelectorAll(selector);
_a = []; _c = result; _a = []; _c = result;
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
@ -91,12 +91,12 @@
position = function(el) { position = function(el) {
var id, left, top; var id, left, top;
id = el.id; id = el.id;
if ((left = GM_getValue(("" + (id) + "Left"), '0px'))) { if (left = GM_getValue("" + (id) + "Left", '0px')) {
el.style.left = left; el.style.left = left;
} else { } else {
el.style.right = '0px'; el.style.right = '0px';
}; }
return (top = GM_getValue(("" + (id) + "Top"), '0px')) ? (el.style.top = top) : (el.style.bottom = '0px'); return (top = GM_getValue("" + (id) + "Top", '0px')) ? (el.style.top = top) : (el.style.bottom = '0px');
}; };
if (typeof GM_deleteValue === 'undefined') { if (typeof GM_deleteValue === 'undefined') {
this.GM_setValue = function(name, value) { this.GM_setValue = function(name, value) {
@ -128,7 +128,7 @@
} }
watched = JSON.parse(GM_getValue('watched', '{}')); watched = JSON.parse(GM_getValue('watched', '{}'));
if (location.hostname.split('.')[0] === 'sys') { if (location.hostname.split('.')[0] === 'sys') {
if ((b = $('table font b'))) { if (b = $('table font b')) {
GM_setValue('error', b.firstChild.textContent); GM_setValue('error', b.firstChild.textContent);
} else { } else {
GM_setValue('error', ''); GM_setValue('error', '');
@ -140,7 +140,7 @@
id = _a[2]; id = _a[2];
if (thread === '0') { if (thread === '0') {
board = $('meta', document).content.match(/4chan.org\/(\w+)\//)[1]; board = $('meta', document).content.match(/4chan.org\/(\w+)\//)[1];
watched[board] = watched[board] || []; watched[board] || (watched[board] = []);
watched[board].push({ watched[board].push({
id: id, id: id,
text: GM_getValue('autoText') text: GM_getValue('autoText')
@ -159,7 +159,7 @@
REPLY = magic; REPLY = magic;
} else { } else {
PAGENUM = parseInt(magic) || 0; PAGENUM = parseInt(magic) || 0;
}; }
xhrs = []; xhrs = [];
r = null; r = null;
iframeLoop = false; iframeLoop = false;
@ -174,8 +174,8 @@
} }
favNormal = favicon.href; favNormal = favicon.href;
favEmpty = 'data:image/gif;base64,R0lGODlhEAAQAJEAAAAAAP///9vb2////yH5BAEAAAMALAAAAAAQABAAAAIvnI+pq+D9DBAUoFkPFnbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw=='; favEmpty = 'data:image/gif;base64,R0lGODlhEAAQAJEAAAAAAP///9vb2////yH5BAEAAAMALAAAAAAQABAAAAIvnI+pq+D9DBAUoFkPFnbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw==';
hiddenThreads = JSON.parse(GM_getValue(("hiddenThreads/" + (BOARD) + "/"), '[]')); hiddenThreads = JSON.parse(GM_getValue("hiddenThreads/" + (BOARD) + "/", '[]'));
hiddenReplies = JSON.parse(GM_getValue(("hiddenReplies/" + (BOARD) + "/"), '[]')); hiddenReplies = JSON.parse(GM_getValue("hiddenReplies/" + (BOARD) + "/", '[]'));
lastChecked = GM_getValue('lastChecked', 0); lastChecked = GM_getValue('lastChecked', 0);
now = getTime(); now = getTime();
DAY = 24 * 60 * 60; DAY = 24 * 60 * 60;
@ -193,74 +193,74 @@
} }
hiddenReplies.shift(); hiddenReplies.shift();
} }
GM_setValue(("hiddenThreads/" + (BOARD) + "/"), JSON.stringify(hiddenThreads)); GM_setValue("hiddenThreads/" + (BOARD) + "/", JSON.stringify(hiddenThreads));
GM_setValue(("hiddenReplies/" + (BOARD) + "/"), JSON.stringify(hiddenReplies)); GM_setValue("hiddenReplies/" + (BOARD) + "/", JSON.stringify(hiddenReplies));
GM_setValue('lastChecked', now); GM_setValue('lastChecked', now);
} }
GM_addStyle(' \ GM_addStyle('\
#watcher { \ #watcher {\
position: absolute; \ position: absolute;\
border: 1px solid; \ border: 1px solid;\
} \ }\
#watcher div.move { \ #watcher div.move {\
text-decoration: underline; \ text-decoration: underline;\
padding: 5px 5px 0 5px; \ padding: 5px 5px 0 5px;\
} \ }\
#watcher div:last-child { \ #watcher div:last-child {\
padding: 0 5px 5px 5px; \ padding: 0 5px 5px 5px;\
} \ }\
span.error { \ span.error {\
color: red; \ color: red;\
} \ }\
#qr span.error { \ #qr span.error {\
position: absolute; \ position: absolute;\
bottom: 0; \ bottom: 0;\
left: 0; \ left: 0;\
} \ }\
#qr { \ #qr {\
position: fixed; \ position: fixed;\
border: 1px solid; \ border: 1px solid;\
} \ }\
#qr > div { \ #qr > div {\
text-align: right; \ text-align: right;\
} \ }\
#qr > form > div {/* ad */ \ #qr > form > div {/* ad */\
display: none; \ display: none;\
} \ }\
#qr td.rules { \ #qr td.rules {\
display: none; \ display: none;\
} \ }\
#options { \ #options {\
position: fixed; \ position: fixed;\
border: 1px solid; \ border: 1px solid;\
padding: 5px; \ padding: 5px;\
text-align: right; \ text-align: right;\
} \ }\
span.navlinks { \ span.navlinks {\
position: absolute; \ position: absolute;\
right: 5px; \ right: 5px;\
} \ }\
span.navlinks > a { \ span.navlinks > a {\
font-size: 16px; \ font-size: 16px;\
text-decoration: none; \ text-decoration: none;\
} \ }\
.move { \ .move {\
cursor: move; \ cursor: move;\
} \ }\
.pointer, #options label, #options a { \ .pointer, #options label, #options a {\
cursor: pointer; \ cursor: pointer;\
} \ }\
'); ');
clearHidden = function() { clearHidden = function() {
GM_deleteValue(("hiddenReplies/" + (BOARD) + "/")); GM_deleteValue("hiddenReplies/" + (BOARD) + "/");
GM_deleteValue(("hiddenThreads/" + (BOARD) + "/")); GM_deleteValue("hiddenThreads/" + (BOARD) + "/");
this.value = "hidden: 0"; this.value = "hidden: 0";
hiddenReplies = []; hiddenReplies = [];
return (hiddenThreads = []); return (hiddenThreads = []);
}; };
options = function() { options = function() {
var _c, _d, checked, div, hiddenNum, option; var _c, _d, checked, div, hiddenNum, option;
if ((div = $('#options'))) { if (div = $('#options')) {
return remove(div); return remove(div);
} else { } else {
hiddenNum = hiddenReplies.length + hiddenThreads.length; hiddenNum = hiddenReplies.length + hiddenThreads.length;
@ -325,8 +325,8 @@ cursor: pointer; \
}; };
mouseup = function() { mouseup = function() {
id = move.div.id; id = move.div.id;
GM_setValue(("" + (id) + "Left"), move.div.style.left); GM_setValue("" + (id) + "Left", move.div.style.left);
GM_setValue(("" + (id) + "Top"), move.div.style.top); GM_setValue("" + (id) + "Top", move.div.style.top);
window.removeEventListener('mousemove', mousemove, true); window.removeEventListener('mousemove', mousemove, true);
return window.removeEventListener('mouseup', mouseup, true); return window.removeEventListener('mouseup', mouseup, true);
}; };
@ -337,30 +337,30 @@ cursor: pointer; \
hide(this); hide(this);
id = div.id; id = div.id;
slice(hiddenThreads, id); slice(hiddenThreads, id);
return GM_setValue(("hiddenThreads/" + (BOARD) + "/"), JSON.stringify(hiddenThreads)); return GM_setValue("hiddenThreads/" + (BOARD) + "/", JSON.stringify(hiddenThreads));
}; };
hideThread = function(div) { hideThread = function(div) {
var _c, a, n, name, p, span, text, trip; var _c, a, n, name, p, span, text, trip;
if ((p = this.parentNode)) { if (p = this.parentNode) {
div = p; div = p;
hiddenThreads.push({ hiddenThreads.push({
id: div.id, id: div.id,
timestamp: getTime() timestamp: getTime()
}); });
GM_setValue(("hiddenThreads/" + (BOARD) + "/"), JSON.stringify(hiddenThreads)); GM_setValue("hiddenThreads/" + (BOARD) + "/", JSON.stringify(hiddenThreads));
} }
hide(div); hide(div);
if (getValue('Show Stubs')) { if (getValue('Show Stubs')) {
a = tag('a'); a = tag('a');
if ((span = $('.omittedposts', div))) { if (span = $('.omittedposts', div)) {
n = Number(span.textContent.match(/\d+/)[0]); n = Number(span.textContent.match(/\d+/)[0]);
} else { } else {
n = 0; n = 0;
}; }
n += $$('table', div).length; n += $$('table', div).length;
text = n === 1 ? "1 reply" : ("" + (n) + " replies"); text = n === 1 ? "1 reply" : ("" + (n) + " replies");
name = $('span.postername', div).textContent; name = $('span.postername', div).textContent;
trip = (typeof (_c = ($('span.postername + span.postertrip', div))) === "undefined" || _c == undefined ? undefined : _c.textContent) || ''; trip = ((typeof (_c = ($('span.postername + span.postertrip', div))) === "undefined" || _c === null) ? undefined : _c.textContent) || '';
a.textContent = ("[ + ] " + (name) + (trip) + " (" + (text) + ")"); a.textContent = ("[ + ] " + (name) + (trip) + " (" + (text) + ")");
a.className = 'pointer'; a.className = 'pointer';
a.addEventListener('click', showThread, true); a.addEventListener('click', showThread, true);
@ -390,7 +390,7 @@ cursor: pointer; \
hidden = _d[_c]; hidden = _d[_c];
if (id === hidden.id) { if (id === hidden.id) {
hideThread(div); hideThread(div);
}; }
} }
current = current.nextSibling.nextSibling; current = current.nextSibling.nextSibling;
return current.nodeName !== 'CENTER' ? threadF(current) : null; return current.nodeName !== 'CENTER' ? threadF(current) : null;
@ -403,20 +403,20 @@ cursor: pointer; \
remove(div); remove(div);
id = $('td.reply, td.replyhl', table).id; id = $('td.reply, td.replyhl', table).id;
slice(hiddenReplies, id); slice(hiddenReplies, id);
return GM_setValue(("hiddenReplies/" + (BOARD) + "/"), JSON.stringify(hiddenReplies)); return GM_setValue("hiddenReplies/" + (BOARD) + "/", JSON.stringify(hiddenReplies));
}; };
hideReply = function(reply) { hideReply = function(reply) {
var _c, a, div, name, p, table, trip; var _c, a, div, name, p, table, trip;
if ((p = this.parentNode)) { if (p = this.parentNode) {
reply = p.nextSibling; reply = p.nextSibling;
hiddenReplies.push({ hiddenReplies.push({
id: reply.id, id: reply.id,
timestamp: getTime() timestamp: getTime()
}); });
GM_setValue(("hiddenReplies/" + (BOARD) + "/"), JSON.stringify(hiddenReplies)); GM_setValue("hiddenReplies/" + (BOARD) + "/", JSON.stringify(hiddenReplies));
} }
name = $('span.commentpostername', reply).textContent; name = $('span.commentpostername', reply).textContent;
trip = (typeof (_c = ($('span.postertrip', reply))) === "undefined" || _c == undefined ? undefined : _c.textContent) || ''; trip = ((typeof (_c = ($('span.postertrip', reply))) === "undefined" || _c === null) ? undefined : _c.textContent) || '';
table = x('ancestor::table', reply); table = x('ancestor::table', reply);
hide(table); hide(table);
if (getValue('Show Stubs')) { if (getValue('Show Stubs')) {
@ -447,12 +447,12 @@ cursor: pointer; \
}; };
iframeLoad = function() { iframeLoad = function() {
var error, qr, span; var error, qr, span;
if ((iframeLoop = !iframeLoop)) { if (iframeLoop = !iframeLoop) {
return null; return null;
} }
$('iframe').src = 'about:blank'; $('iframe').src = 'about:blank';
qr = $('#qr'); qr = $('#qr');
if ((error = GM_getValue('error'))) { if (error = GM_getValue('error')) {
$('form', qr).style.visibility = ''; $('form', qr).style.visibility = '';
span = tag('span'); span = tag('span');
span.textContent = error; span.textContent = error;
@ -473,7 +473,7 @@ cursor: pointer; \
return form.style.visibility ? (form.style.visibility = '') : (form.style.visibility = 'collapse'); return form.style.visibility ? (form.style.visibility = '') : (form.style.visibility = 'collapse');
}; };
quickReply = function(e) { quickReply = function(e) {
var _c, _d, _e, _f, bf, clone, closeB, div, input, minimizeB, qr, script, selText, selection, textarea, xpath; var _c, _d, _e, _f, bf, clone, closeB, div, input, minimizeB, qr, script, selection, text, textarea, xpath;
e.preventDefault(); e.preventDefault();
if (!(qr = $('#qr'))) { if (!(qr = $('#qr'))) {
qr = tag('div'); qr = tag('div');
@ -501,9 +501,9 @@ cursor: pointer; \
closeB.addEventListener('click', close, true); closeB.addEventListener('click', close, true);
div.appendChild(closeB); div.appendChild(closeB);
clone = $('form[name="post"]').cloneNode(true); clone = $('form[name="post"]').cloneNode(true);
if ((bf = $('.bf', clone))) { if (bf = $('.bf', clone)) {
remove(bf); remove(bf);
}; }
_d = $$('script', clone); _d = $$('script', clone);
for (_c = 0, _e = _d.length; _c < _e; _c++) { for (_c = 0, _e = _d.length; _c < _e; _c++) {
script = _d[_c]; script = _d[_c];
@ -523,17 +523,13 @@ cursor: pointer; \
qr.appendChild(clone); qr.appendChild(clone);
document.body.appendChild(qr); document.body.appendChild(qr);
} }
selection = window.getSelection();
id = (typeof (_f = (x('preceding::span[@id][1]', selection.anchorNode))) === "undefined" || _f === null) ? undefined : _f.id;
text = selection.toString();
textarea = $('textarea', qr); textarea = $('textarea', qr);
textarea.focus(); textarea.focus();
textarea.value += '>>' + this.parentNode.id.match(/\d+$/)[0] + '\n'; textarea.value += '>>' + this.parentNode.id.match(/\d+$/)[0] + '\n';
selection = window.getSelection(); return text && id === this.parentNode.id ? textarea.value += (">" + (text) + "\n") : null;
id = typeof (_f = (x('preceding::span[@id][1]', selection.anchorNode))) === "undefined" || _f == undefined ? undefined : _f.id;
if (id === this.parentNode.id) {
if ((selText = selection.toString())) {
textarea.value += (">" + (selText) + "\n");
};
};
return null;
}; };
watch = function() { watch = function() {
var text; var text;
@ -541,7 +537,7 @@ cursor: pointer; \
if (this.src[0] === 'd') { if (this.src[0] === 'd') {
this.src = favNormal; this.src = favNormal;
text = ("/" + (BOARD) + "/ - ") + x('following-sibling::blockquote', this).textContent.slice(0, 25); text = ("/" + (BOARD) + "/ - ") + x('following-sibling::blockquote', this).textContent.slice(0, 25);
watched[BOARD] = watched[BOARD] || []; watched[BOARD] || (watched[BOARD] = []);
watched[BOARD].push({ watched[BOARD].push({
id: id, id: id,
text: text text: text
@ -562,7 +558,7 @@ cursor: pointer; \
watched[board] = slice(watched[board], id); watched[board] = slice(watched[board], id);
GM_setValue('watched', JSON.stringify(watched)); GM_setValue('watched', JSON.stringify(watched));
watcherUpdate(); watcherUpdate();
if ((input = $(("input[name=\"" + (id) + "\"]")))) { if (input = $("input[name=\"" + (id) + "\"]")) {
favicon = input.previousSibling; favicon = input.previousSibling;
return (favicon.src = favEmpty); return (favicon.src = favEmpty);
} }
@ -635,7 +631,7 @@ cursor: pointer; \
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);
} }
@ -655,7 +651,7 @@ cursor: pointer; \
r.onload = function() { r.onload = function() {
return onloadThread(this.responseText, span); return onloadThread(this.responseText, span);
}; };
r.open('GET', ("res/" + (id)), true); r.open('GET', "res/" + (id), true);
r.send(); r.send();
return xhrs.push({ return xhrs.push({
r: r, r: r,
@ -679,7 +675,7 @@ cursor: pointer; \
reply = _f[_e]; reply = _f[_e];
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);
@ -726,7 +722,7 @@ cursor: pointer; \
autoWatch = function() { autoWatch = function() {
var autoText; var autoText;
autoText = $('textarea', this).value.slice(0, 25); autoText = $('textarea', this).value.slice(0, 25);
return GM_setValue('autoText', ("/" + (BOARD) + "/ - " + (autoText))); return GM_setValue('autoText', "/" + (BOARD) + "/ - " + (autoText));
}; };
stopPropagation = function(e) { stopPropagation = function(e) {
return e.stopPropagation(); return e.stopPropagation();
@ -737,7 +733,7 @@ cursor: pointer; \
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)));
} }
}; };
@ -773,7 +769,7 @@ cursor: pointer; \
} }
return _c; return _c;
}); });
}; }
if (getValue('Quick Reply')) { if (getValue('Quick Reply')) {
iframe = tag('iframe'); iframe = tag('iframe');
hide(iframe); hide(iframe);
@ -809,7 +805,7 @@ cursor: pointer; \
} }
return _c; return _c;
}); });
}; }
if (getValue('Thread Watcher')) { if (getValue('Thread Watcher')) {
watcher = tag('div'); watcher = tag('div');
watcher.innerHTML = '<div class="move">Thread Watcher</div><div></div>'; watcher.innerHTML = '<div class="move">Thread Watcher</div><div></div>';
@ -834,7 +830,7 @@ cursor: pointer; \
break; break;
} }
} }
img.src = img.src || favEmpty; img.src || (img.src = favEmpty);
img.className = 'pointer'; img.className = 'pointer';
img.addEventListener('click', watch, true); img.addEventListener('click', watch, true);
inBefore(input, img); inBefore(input, img);
@ -857,7 +853,7 @@ cursor: pointer; \
} }
return _l; return _l;
}); });
}; }
if (getValue('Reply Navigation')) { if (getValue('Reply Navigation')) {
callbacks.push(function(root) { callbacks.push(function(root) {
var _i, _j, _k, _l, arr, down, el, span, up; var _i, _j, _k, _l, arr, down, el, span, up;
@ -884,7 +880,7 @@ cursor: pointer; \
} }
return _i; return _i;
}); });
}; }
if (!REPLY) { if (!REPLY) {
if (getValue('Thread Hiding')) { if (getValue('Thread Hiding')) {
delform = $('form[name=delform]'); delform = $('form[name=delform]');
@ -894,7 +890,7 @@ cursor: pointer; \
} }
if (getValue('Auto Watch')) { if (getValue('Auto Watch')) {
$('form[name="post"]').addEventListener('submit', autoWatch, true); $('form[name="post"]').addEventListener('submit', autoWatch, true);
}; }
if (getValue('Thread Navigation')) { if (getValue('Thread Navigation')) {
arr = $$('div > span.filesize, form > span.filesize'); arr = $$('div > span.filesize, form > span.filesize');
i = 0; i = 0;
@ -935,7 +931,7 @@ cursor: pointer; \
} }
if (location.hash === '#1') { if (location.hash === '#1') {
window.location = window.location; window.location = window.location;
}; }
} }
if (getValue('Thread Expansion')) { if (getValue('Thread Expansion')) {
omitted = $$('span.omittedposts'); omitted = $$('span.omittedposts');