too much stuff

This commit is contained in:
James Campos 2010-05-31 11:34:16 -07:00
parent 0e907014f4
commit 1622c81c4c
5 changed files with 249 additions and 227 deletions

View File

@ -604,7 +604,7 @@ expandComment: (e) ->
report: -> report: ->
input: x('preceding-sibling::input', this) input: x('preceding-sibling::input[1]', this)
input.click() input.click()
$('input[value="Report"]').click() $('input[value="Report"]').click()
input.click() input.click()
@ -660,7 +660,7 @@ if getValue('Quick Reply')
document.body.appendChild(iframe) document.body.appendChild(iframe)
callbacks.push((root) -> callbacks.push((root) ->
quotes: $$('a.quotejs:not(:first-child)') quotes: $$('a.quotejs:not(:first-child)', root)
for quote in quotes for quote in quotes
quote.addEventListener('click', quickReply, true) quote.addEventListener('click', quickReply, true)
) )

View File

@ -18,18 +18,18 @@
'Auto Watch': true, 'Auto Watch': true,
'Anonymize': false 'Anonymize': false
}; };
getValue = function getValue(name) { getValue = function(name) {
return GM_getValue(name, config[name]); return GM_getValue(name, config[name]);
}; };
x = function x(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);
@ -41,33 +41,33 @@
} }
return _a; return _a;
}; };
inBefore = function inBefore(root, el) { inBefore = function(root, el) {
return root.parentNode.insertBefore(el, root); return root.parentNode.insertBefore(el, root);
}; };
inAfter = function inAfter(root, el) { inAfter = function(root, el) {
return root.parentNode.insertBefore(el, root.nextSibling); return root.parentNode.insertBefore(el, root.nextSibling);
}; };
tag = function tag(el) { tag = function(el) {
return document.createElement(el); return document.createElement(el);
}; };
hide = function hide(el) { hide = function(el) {
el.style.display = 'none'; el.style.display = 'none';
return el.style.display; return el.style.display;
}; };
show = function show(el) { show = function(el) {
el.style.display = ''; el.style.display = '';
return el.style.display; return el.style.display;
}; };
remove = function remove(el) { remove = function(el) {
return el.parentNode.removeChild(el); return el.parentNode.removeChild(el);
}; };
replace = function replace(root, el) { replace = function(root, el) {
return root.parentNode.replaceChild(el, root); return root.parentNode.replaceChild(el, root);
}; };
getTime = function getTime() { getTime = function() {
return Math.floor(new Date().getTime() / 1000); return Math.floor(new Date().getTime() / 1000);
}; };
slice = function slice(arr, id) { slice = function(arr, id) {
var i, l; var i, l;
// the while loop is the only low-level loop left in coffeescript. // the while loop is the only low-level loop left in coffeescript.
// we need to use it to see the index. // we need to use it to see the index.
@ -81,7 +81,7 @@
i++; i++;
} }
}; };
position = function position(el) { position = function(el) {
var id, left, top; var id, left, top;
id = el.id; id = el.id;
(left = GM_getValue(("" + (id) + "Left"), '0px')) ? (el.style.left = left) : (el.style.right = '0px'); (left = GM_getValue(("" + (id) + "Left"), '0px')) ? (el.style.left = left) : (el.style.right = '0px');
@ -94,11 +94,11 @@
} }
}; };
if (typeof GM_deleteValue === 'undefined') { if (typeof GM_deleteValue === 'undefined') {
this.GM_setValue = function GM_setValue(name, value) { this.GM_setValue = function(name, value) {
value = (typeof value)[0] + value; value = (typeof value)[0] + value;
return localStorage.setItem(name, value); return localStorage.setItem(name, value);
}; };
this.GM_getValue = function GM_getValue(name, defaultValue) { this.GM_getValue = function(name, defaultValue) {
var type, value; var type, value;
if (!(value = localStorage.getItem(name))) { if (!(value = localStorage.getItem(name))) {
return defaultValue; return defaultValue;
@ -113,7 +113,7 @@
return value; return value;
} }
}; };
this.GM_addStyle = function GM_addStyle(css) { this.GM_addStyle = function(css) {
var style; var style;
style = tag('style'); style = tag('style');
style.type = 'text/css'; style.type = 'text/css';
@ -245,7 +245,7 @@ cursor: move; \
cursor: pointer; \ cursor: pointer; \
} \ } \
'); ');
options = function options() { options = function() {
var _c, checked, div, option; var _c, checked, div, option;
if ((div = $('#options'))) { if ((div = $('#options'))) {
return remove(div); return remove(div);
@ -268,7 +268,7 @@ cursor: pointer; \
return document.body.appendChild(div); return document.body.appendChild(div);
} }
}; };
mousedown = function mousedown(e) { mousedown = function(e) {
var div; var div;
div = this.parentNode; div = this.parentNode;
move.div = div; move.div = div;
@ -281,7 +281,7 @@ cursor: pointer; \
window.addEventListener('mousemove', mousemove, true); window.addEventListener('mousemove', mousemove, true);
return window.addEventListener('mouseup', mouseup, true); return window.addEventListener('mouseup', mouseup, true);
}; };
mousemove = function mousemove(e) { mousemove = function(e) {
var div, left, realX, realY, top; var div, left, realX, realY, top;
div = move.div; div = move.div;
realX = move.divX + (e.clientX - move.clientX); realX = move.divX + (e.clientX - move.clientX);
@ -307,14 +307,14 @@ cursor: pointer; \
return div.style.bottom; return div.style.bottom;
} }
}; };
mouseup = function mouseup() { 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);
}; };
showThread = function showThread() { showThread = function() {
var div; var div;
div = this.nextSibling; div = this.nextSibling;
show(div); show(div);
@ -323,7 +323,7 @@ cursor: pointer; \
slice(hiddenThreads, id); slice(hiddenThreads, id);
return GM_setValue(("hiddenThreads/" + BOARD + "/"), JSON.stringify(hiddenThreads)); return GM_setValue(("hiddenThreads/" + BOARD + "/"), JSON.stringify(hiddenThreads));
}; };
hideThread = function hideThread(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;
@ -340,14 +340,14 @@ cursor: pointer; \
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 = ((_c = $('span.postername + span.postertrip', div)) == undefined ? undefined : _c.textContent) || ''; trip = (typeof (_c = ($('span.postername + span.postertrip', div))) === "undefined" || _c == undefined ? 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);
return inBefore(div, a); return inBefore(div, a);
} }
}; };
threadF = function threadF(current) { threadF = function(current) {
var _c, _d, _e, a, div, hidden; var _c, _d, _e, a, div, hidden;
div = tag('div'); div = tag('div');
a = tag('a'); a = tag('a');
@ -376,7 +376,7 @@ cursor: pointer; \
return threadF(current); return threadF(current);
} }
}; };
showReply = function showReply() { showReply = function() {
var div, table; var div, table;
div = this.parentNode; div = this.parentNode;
table = div.nextSibling; table = div.nextSibling;
@ -386,7 +386,7 @@ cursor: pointer; \
slice(hiddenReplies, id); slice(hiddenReplies, id);
return GM_setValue(("hiddenReplies/" + BOARD + "/"), JSON.stringify(hiddenReplies)); return GM_setValue(("hiddenReplies/" + BOARD + "/"), JSON.stringify(hiddenReplies));
}; };
hideReply = function hideReply(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;
@ -397,7 +397,7 @@ cursor: pointer; \
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 = ((_c = $('span.postertrip', reply)) == undefined ? undefined : _c.textContent) || ''; trip = (typeof (_c = ($('span.postertrip', reply))) === "undefined" || _c == undefined ? 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')) {
@ -410,7 +410,7 @@ cursor: pointer; \
return inBefore(table, div); return inBefore(table, div);
} }
}; };
optionsSave = function optionsSave() { optionsSave = function() {
var _c, _d, _e, div, input, inputs; var _c, _d, _e, div, input, inputs;
div = this.parentNode.parentNode; div = this.parentNode.parentNode;
inputs = $$('input', div); inputs = $$('input', div);
@ -421,12 +421,12 @@ cursor: pointer; \
} }
return remove(div); return remove(div);
}; };
close = function close() { close = function() {
var div; var div;
div = this.parentNode.parentNode; div = this.parentNode.parentNode;
return remove(div); return remove(div);
}; };
iframeLoad = function iframeLoad() { iframeLoad = function() {
var error, qr, span; var error, qr, span;
if ((iframeLoop = !iframeLoop)) { if ((iframeLoop = !iframeLoop)) {
return null; return null;
@ -443,14 +443,14 @@ cursor: pointer; \
return remove(qr); return remove(qr);
} }
}; };
submit = function submit() { submit = function() {
var span; var span;
this.style.visibility = 'collapse'; this.style.visibility = 'collapse';
if ((span = this.nextSibling)) { if ((span = this.nextSibling)) {
return remove(span); return remove(span);
} }
}; };
minimize = function minimize() { minimize = function() {
var form; var form;
form = this.parentNode.nextSibling; form = this.parentNode.nextSibling;
if (form.style.visibility) { if (form.style.visibility) {
@ -461,7 +461,7 @@ cursor: pointer; \
return form.style.visibility; return form.style.visibility;
} }
}; };
quickReply = function quickReply(e) { quickReply = function(e) {
var _c, a, clone, div, input, qr, selText, selection, textarea, xpath; var _c, a, clone, div, input, qr, selText, selection, textarea, xpath;
e.preventDefault(); e.preventDefault();
if (!(qr = $('#qr'))) { if (!(qr = $('#qr'))) {
@ -506,11 +506,11 @@ cursor: pointer; \
//xx //xx
textarea.value += '>>' + this.parentNode.id.match(/\d+$/)[0] + '\n'; textarea.value += '>>' + this.parentNode.id.match(/\d+$/)[0] + '\n';
selection = window.getSelection(); selection = window.getSelection();
id = (_c = x('preceding::span[@id][1]', selection.anchorNode)) == undefined ? undefined : _c.id; id = typeof (_c = (x('preceding::span[@id][1]', selection.anchorNode))) === "undefined" || _c == undefined ? undefined : _c.id;
id === this.parentNode.id ? (selText = selection.toString()) ? textarea.value += (">" + selText + "\n") : null : null; id === this.parentNode.id ? (selText = selection.toString()) ? textarea.value += (">" + selText + "\n") : null : null;
return textarea.focus(); return textarea.focus();
}; };
watch = function watch() { watch = function() {
var text; var text;
id = this.nextSibling.name; id = this.nextSibling.name;
if (this.src[0] === 'd') { if (this.src[0] === 'd') {
@ -529,7 +529,7 @@ cursor: pointer; \
GM_setValue('watched', JSON.stringify(watched)); GM_setValue('watched', JSON.stringify(watched));
return watcherUpdate(); return watcherUpdate();
}; };
watchX = function watchX() { watchX = function() {
var _c, img, input; var _c, img, input;
_c = this.nextElementSibling.getAttribute('href').split('/'); _c = this.nextElementSibling.getAttribute('href').split('/');
nop = _c[0]; nop = _c[0];
@ -545,7 +545,7 @@ cursor: pointer; \
return img.src; return img.src;
} }
}; };
watcherUpdate = function watcherUpdate() { watcherUpdate = function() {
var _c, _d, _e, _f, a, div, old; var _c, _d, _e, _f, a, div, old;
div = tag('div'); div = tag('div');
_c = watched; _c = watched;
@ -569,7 +569,7 @@ cursor: pointer; \
old = $('#watcher div:last-child'); old = $('#watcher div:last-child');
return replace(old, div); return replace(old, div);
}; };
parseResponse = function parseResponse(responseText) { parseResponse = function(responseText) {
var body, opbq, replies; var body, opbq, replies;
body = tag('body'); body = tag('body');
body.innerHTML = responseText; body.innerHTML = responseText;
@ -577,7 +577,7 @@ cursor: pointer; \
opbq = $('blockquote', body); opbq = $('blockquote', body);
return [replies, opbq]; return [replies, opbq];
}; };
onloadThread = function onloadThread(responseText, span) { onloadThread = function(responseText, span) {
var _c, _d, _e, _f, _g, _h, _i, _j, _k, div, next, opbq, replies, reply; var _c, _d, _e, _f, _g, _h, _i, _j, _k, div, next, opbq, replies, reply;
_c = parseResponse(responseText); _c = parseResponse(responseText);
replies = _c[0]; replies = _c[0];
@ -607,7 +607,7 @@ cursor: pointer; \
return _h; return _h;
} }
}; };
expandThread = function expandThread() { expandThread = function() {
var _c, _d, _e, num, prev, span, table, xhr; var _c, _d, _e, num, prev, span, table, xhr;
id = x('preceding-sibling::input[1]', this).name; id = x('preceding-sibling::input[1]', this).name;
span = this; span = this;
@ -635,7 +635,7 @@ cursor: pointer; \
} }
//create new request //create new request
r = new XMLHttpRequest(); r = new XMLHttpRequest();
r.onload = function onload() { 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);
@ -645,7 +645,7 @@ cursor: pointer; \
id: id id: id
}); });
}; };
onloadComment = function onloadComment(responseText, a, href) { onloadComment = function(responseText, a, href) {
var _c, _d, _e, _f, _g, bq, op, opbq, replies, reply; var _c, _d, _e, _f, _g, bq, op, opbq, replies, reply;
_c = href.match(/(\d+)#(\d+)/); _c = href.match(/(\d+)#(\d+)/);
nop = _c[0]; nop = _c[0];
@ -669,13 +669,13 @@ cursor: pointer; \
bq.innerHTML = html; bq.innerHTML = html;
return bq.innerHTML; return bq.innerHTML;
}; };
expandComment = function expandComment(e) { expandComment = function(e) {
var a, href; var a, href;
e.preventDefault(); e.preventDefault();
a = this; a = this;
href = a.getAttribute('href'); href = a.getAttribute('href');
r = new XMLHttpRequest(); r = new XMLHttpRequest();
r.onload = function onload() { r.onload = function() {
return onloadComment(this.responseText, a, href); return onloadComment(this.responseText, a, href);
}; };
r.open('GET', href, true); r.open('GET', href, true);
@ -685,14 +685,14 @@ cursor: pointer; \
id: href.match(/\d+/)[0] id: href.match(/\d+/)[0]
}); });
}; };
report = function report() { report = function() {
var input; var input;
input = x('preceding-sibling::input', 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();
}; };
nodeInserted = function nodeInserted(e) { nodeInserted = function(e) {
var _c, _d, _e, _f, callback, target; var _c, _d, _e, _f, callback, target;
target = e.target; target = e.target;
if (target.nodeName === 'TABLE') { if (target.nodeName === 'TABLE') {
@ -704,15 +704,15 @@ cursor: pointer; \
return _c; return _c;
} }
}; };
autoWatch = function autoWatch() { 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 stopPropagation(e) { stopPropagation = function(e) {
return e.stopPropagation(); return e.stopPropagation();
}; };
replyNav = function replyNav() { replyNav = function() {
var direction, op; var direction, op;
if (REPLY) { if (REPLY) {
window.location = this.textContent === '▲' ? '#navtop' : '#navbot'; window.location = this.textContent === '▲' ? '#navtop' : '#navbot';

View File

@ -2,7 +2,7 @@
// @name 4chan x // @name 4chan x
// @namespace aeosynth // @namespace aeosynth
// @description Adds various features; replaces the extension / fychan. // @description Adds various features; replaces the extension / fychan.
// @version 1.0.10 // @version 1.0.11
// @copyright 2009, 2010 James Campos // @copyright 2009, 2010 James Campos
// @license MIT; http://en.wikipedia.org/wiki/Mit_license // @license MIT; http://en.wikipedia.org/wiki/Mit_license
// @include http://boards.4chan.org/* // @include http://boards.4chan.org/*

View File

@ -139,8 +139,8 @@ GM_addStyle('
#duplicated code. sigh. #duplicated code. sigh.
# we could try threading the op, but that might affect other scripts. # we could try threading the op, but that might affect other scripts.
# also, I really want to try out *gasp* eval(). # also, I really want to try out *gasp* eval().
filterThread: (thread, filter) -> filterThread: (thread, fields) ->
for field of filter for field of fields
switch field switch field
when 'Name' when 'Name'
s: $('span.postername', thread).textContent s: $('span.postername', thread).textContent
@ -154,29 +154,27 @@ filterThread: (thread, filter) ->
s: $('blockquote', thread).textContent s: $('blockquote', thread).textContent
when 'File' when 'File'
s: x('./span[@class="filesize"]', thread)?.textContent || '' s: x('./span[@class="filesize"]', thread)?.textContent || ''
for regex in filter[field].all.concat(filter[field].op) for regex in fields[field].op
if regex.test(s) if regex.test(s)
return true return true
filterReply: (table, filter) -> filterReply: (table, fields) ->
for field of filter for field of fields
switch field switch field
when 'Name' when 'Name'
s: $('span.commentpostername', table).textContent s: $('span.commentpostername', table).textContent
when 'Tripcode' when 'Tripcode'
s: $('span.postertrip', table)?.textContent || '' s: $('span.postertrip', table)?.textContent || ''
when 'Email' when 'Email'
#http://github.com/jashkenas/coffee-script/issues#issue/342 s: $('a.linkmail', table)?.href.slice(7) || ''
#s: $('a.linkmail', table)?.href.slice(7) || ''
s: ($('a.linkmail', table)?.href.slice(7)) || ''
when 'Subject' when 'Subject'
s: $('span.filetitle', table)?.textContent || '' s: $('span.filetitle', table)?.textContent || ''
when 'Comment' when 'Comment'
s: $('blockquote', table).textContent s: $('blockquote', table).textContent
when 'File' when 'File'
s: $('span.filesize', table)?.textContent || '' s: $('span.filesize', table)?.textContent || ''
for regex in filter[field].all.concat(filter[field].reply) for regex in fields[field].reply
if regex.test(s) if regex.test(s)
return true return true
@ -184,19 +182,18 @@ filterReply: (table, filter) ->
filterAll: -> filterAll: ->
saveFilters() saveFilters()
#better way of doing this? if we just say `compiled: filters`,
#changing a prop in one will change a prop in the other.
compiled: {} compiled: {}
for filter of filters for klass of filters
compiled[filter]: {} compiled[klass]: {}
for field of filters[filter] boards: filters[klass]
s: filters[filter][field] #for ['global', BOARD] of boards
for field of boards['global']
s: boards['global'][field]
split: s.split(';') split: s.split(';')
trimmed: el.trimLeft() for el in split trimmed: el.trimLeft() for el in split
filtered: trimmed.filter((el)-> el.length) filtered: el for el in trimmed when el.length
if filtered.length if filtered.length
obj: { obj: {
all: []
op: [] op: []
reply: [] reply: []
} }
@ -206,27 +203,29 @@ filterAll: ->
switch match switch match
when 'o' then key: 'op' when 'o' then key: 'op'
when 'O' then key: 'reply' when 'O' then key: 'reply'
else
key: 'all'
regex: new RegExp(el, 'i') regex: new RegExp(el, 'i')
obj[key].push(regex) if key
compiled[filter][field]: obj obj[key].push(regex)
else
obj['op'].push(regex)
obj['reply'].push(regex)
compiled[klass][field]: obj
[replies, threads]: reset() [replies, threads]: reset()
num: if threads.length then replies.length + threads.length else $$('blockquote').length num: if threads.length then replies.length + threads.length else $$('blockquote').length
#these loops look combinable #these loops look combinable
for reply in replies for reply in replies
for filter of compiled for klass of compiled
if filterReply(reply, compiled[filter]) if filterReply(reply, compiled[klass])
reply.className+= ' ' + filter reply.className+= ' ' + klass
for thread in threads for thread in threads
for filter of compiled for klass of compiled
if filterThread(thread, compiled[filter]) if filterThread(thread, compiled[klass])
thread.className+= ' ' + filter thread.className+= ' ' + klass
imagesCount: $$('img[md5]').length imageCount: $$('img[md5]').length
box.firstChild.textContent: "Images: $imagesCount Posts: $num" box.firstChild.textContent: "Images: $imageCount Posts: $num"
keydown: (e) -> keydown: (e) ->
@ -266,7 +265,7 @@ save: ->
filters[value]: {} filters[value]: {}
option: tag('option') option: tag('option')
option.textContent: value option.textContent: value
select.appendChild(option) sKlass.appendChild(option)
option?.selected: true option?.selected: true
loadFilters() loadFilters()
GM_setValue('filters', JSON.stringify(filters)) GM_setValue('filters', JSON.stringify(filters))
@ -297,7 +296,7 @@ del: ->
delete filters[value] delete filters[value]
GM_setValue('filters', JSON.stringify(filters)) GM_setValue('filters', JSON.stringify(filters))
remove @parentNode remove @parentNode
for option in select.options for option in sKlass.options
if option.value is value if option.value is value
remove option remove option
loadFilters() loadFilters()
@ -354,7 +353,7 @@ options: ->
loadFilters: -> loadFilters: ->
filter: filters[select.value] filter: filters[sKlass.value][sBoard.value]
inputs: $$('input', box) inputs: $$('input', box)
for input in inputs for input in inputs
input.value: filter[input.name] || '' input.value: filter[input.name] || ''
@ -366,7 +365,7 @@ saveFilters: ->
for input in inputs for input in inputs
if value: input.value if value: input.value
filter[input.name]: value filter[input.name]: value
filters[select.value]: filter filters[sKlass.value][sBoard.value]: filter
GM_setValue('filters', JSON.stringify(filters)) GM_setValue('filters', JSON.stringify(filters))
@ -380,15 +379,27 @@ bar.className: 'move top'
bar.addEventListener('mousedown', mousedown, true) bar.addEventListener('mousedown', mousedown, true)
box.appendChild(bar) box.appendChild(bar)
select: tag('select') sKlass: tag('select')
select.addEventListener('mousedown', saveFilters, true) sKlass.addEventListener('mousedown', saveFilters, true)
select.addEventListener('mouseup', loadFilters, true) sKlass.addEventListener('mouseup', loadFilters, true)
filters: JSON.parse(GM_getValue('filters', '{ "hide": {} }')) defaultValue: JSON.stringify({
for filter of filters 'hide': {
'global': []
}
})
filters: JSON.parse(GM_getValue('filters', defaultValue))
for klass of filters
option: tag('option') option: tag('option')
option.textContent: filter option.textContent: klass
select.appendChild(option) sKlass.appendChild(option)
box.appendChild(select) box.appendChild(sKlass)
sBoard: tag('select')
for board of filters[klass]
option: tag('option')
option.textContent: board
sBoard.appendChild(option)
box.appendChild(sBoard)
fields: [ fields: [
'Name', 'Name',

View File

@ -1,15 +1,15 @@
(function(){ (function(){
var $, $$, _a, _b, _c, _d, _e, _f, _g, a, addClass, autoHide, bar, box, cancel, del, div, f, field, fields, filter, filterAll, filterReply, filterThread, filters, inBefore, input, keydown, label, loadFilters, mousedown, mousemove, mouseup, move, name, option, optionKeydown, options, position, remove, reset, save, saveFilters, select, tag, text, x; var $, $$, _a, _b, _c, _d, _e, _f, _g, _h, a, addClass, autoHide, bar, board, box, cancel, defaultValue, del, div, f, field, fields, filterAll, filterReply, filterThread, filters, inBefore, input, keydown, klass, label, loadFilters, mousedown, mousemove, mouseup, move, name, option, optionKeydown, options, position, remove, reset, sBoard, sKlass, save, saveFilters, tag, text, x;
var __hasProp = Object.prototype.hasOwnProperty; var __hasProp = Object.prototype.hasOwnProperty;
x = function x(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);
@ -21,19 +21,19 @@
} }
return _a; return _a;
}; };
inBefore = function inBefore(root, el) { inBefore = function(root, el) {
return root.parentNode.insertBefore(el, root); return root.parentNode.insertBefore(el, root);
}; };
tag = function tag(el) { tag = function(el) {
return document.createElement(el); return document.createElement(el);
}; };
text = function text(s) { text = function(s) {
return document.createTextNode(s); return document.createTextNode(s);
}; };
remove = function remove(root) { remove = function(root) {
return root.parentNode.removeChild(root); return root.parentNode.removeChild(root);
}; };
position = function position(el) { position = function(el) {
var id, left, top; var id, left, top;
id = el.id; id = el.id;
(left = GM_getValue(("" + (id) + "Left"), '0px')) ? (el.style.left = left) : (el.style.right = '0px'); (left = GM_getValue(("" + (id) + "Left"), '0px')) ? (el.style.left = left) : (el.style.right = '0px');
@ -46,7 +46,7 @@
} }
}; };
move = {}; move = {};
mousedown = function mousedown(e) { mousedown = function(e) {
var div; var div;
div = this.parentNode; div = this.parentNode;
move.div = div; move.div = div;
@ -59,7 +59,7 @@
window.addEventListener('mousemove', mousemove, true); window.addEventListener('mousemove', mousemove, true);
return window.addEventListener('mouseup', mouseup, true); return window.addEventListener('mouseup', mouseup, true);
}; };
mousemove = function mousemove(e) { mousemove = function(e) {
var div, left, realX, realY, top; var div, left, realX, realY, top;
div = move.div; div = move.div;
realX = move.divX + (e.clientX - move.clientX); realX = move.divX + (e.clientX - move.clientX);
@ -85,7 +85,7 @@
return div.style.bottom; return div.style.bottom;
} }
}; };
mouseup = function mouseup() { mouseup = function() {
var id; var id;
id = move.div.id; id = move.div.id;
GM_setValue(("" + (id) + "Left"), move.div.style.left); GM_setValue(("" + (id) + "Left"), move.div.style.left);
@ -95,11 +95,11 @@
}; };
//x-browser //x-browser
if (typeof GM_deleteValue === 'undefined') { if (typeof GM_deleteValue === 'undefined') {
this.GM_setValue = function GM_setValue(name, value) { this.GM_setValue = function(name, value) {
value = (typeof value)[0] + value; value = (typeof value)[0] + value;
return localStorage.setItem(name, value); return localStorage.setItem(name, value);
}; };
this.GM_getValue = function GM_getValue(name, defaultValue) { this.GM_getValue = function(name, defaultValue) {
var type, value; var type, value;
if (!(value = localStorage.getItem(name))) { if (!(value = localStorage.getItem(name))) {
return defaultValue; return defaultValue;
@ -114,7 +114,7 @@
return value; return value;
} }
}; };
this.GM_addStyle = function GM_addStyle(css) { this.GM_addStyle = function(css) {
var style; var style;
style = tag('style'); style = tag('style');
style.type = 'text/css'; style.type = 'text/css';
@ -166,24 +166,24 @@ display: none; \
//duplicated code. sigh. //duplicated code. sigh.
// we could try threading the op, but that might affect other scripts. // we could try threading the op, but that might affect other scripts.
// also, I really want to try out *gasp* eval(). // also, I really want to try out *gasp* eval().
filterThread = function filterThread(thread, filter) { filterThread = function(thread, fields) {
var _a, _b, _c, _d, _e, _f, _g, _h, field, regex, s; var _a, _b, _c, _d, _e, _f, _g, _h, field, regex, s;
_a = filter; _a = fields;
for (field in _a) { if (__hasProp.call(_a, field)) { for (field in _a) { if (__hasProp.call(_a, field)) {
if (field === 'Name') { if (field === 'Name') {
s = $('span.postername', thread).textContent; s = $('span.postername', thread).textContent;
} else if (field === 'Tripcode') { } else if (field === 'Tripcode') {
s = ((_b = x('./span[@class="postertrip"]', thread)) == undefined ? undefined : _b.textContent) || ''; s = (typeof (_b = (x('./span[@class="postertrip"]', thread))) === "undefined" || _b == undefined ? undefined : _b.textContent) || '';
} else if (field === 'Email') { } else if (field === 'Email') {
s = ((_c = x('./a[@class="linkmail"]', thread)) == undefined ? undefined : _c.href.slice(7)) || ''; s = (typeof (_c = (x('./a[@class="linkmail"]', thread))) === "undefined" || _c == undefined ? undefined : _c.href.slice(7)) || '';
} else if (field === 'Subject') { } else if (field === 'Subject') {
s = ((_d = x('./span[@class="filetitle"]', thread)) == undefined ? undefined : _d.textContent) || ''; s = (typeof (_d = (x('./span[@class="filetitle"]', thread))) === "undefined" || _d == undefined ? undefined : _d.textContent) || '';
} else if (field === 'Comment') { } else if (field === 'Comment') {
s = $('blockquote', thread).textContent; s = $('blockquote', thread).textContent;
} else if (field === 'File') { } else if (field === 'File') {
s = ((_e = x('./span[@class="filesize"]', thread)) == undefined ? undefined : _e.textContent) || ''; s = (typeof (_e = (x('./span[@class="filesize"]', thread))) === "undefined" || _e == undefined ? undefined : _e.textContent) || '';
} }
_g = filter[field].all.concat(filter[field].op); _g = fields[field].op;
for (_f = 0, _h = _g.length; _f < _h; _f++) { for (_f = 0, _h = _g.length; _f < _h; _f++) {
regex = _g[_f]; regex = _g[_f];
if (regex.test(s)) { if (regex.test(s)) {
@ -192,26 +192,24 @@ display: none; \
} }
}} }}
}; };
filterReply = function filterReply(table, filter) { filterReply = function(table, fields) {
var _a, _b, _c, _d, _e, _f, _g, _h, field, regex, s; var _a, _b, _c, _d, _e, _f, _g, _h, field, regex, s;
_a = filter; _a = fields;
for (field in _a) { if (__hasProp.call(_a, field)) { for (field in _a) { if (__hasProp.call(_a, field)) {
if (field === 'Name') { if (field === 'Name') {
s = $('span.commentpostername', table).textContent; s = $('span.commentpostername', table).textContent;
} else if (field === 'Tripcode') { } else if (field === 'Tripcode') {
s = ((_b = $('span.postertrip', table)) == undefined ? undefined : _b.textContent) || ''; s = (typeof (_b = ($('span.postertrip', table))) === "undefined" || _b == undefined ? undefined : _b.textContent) || '';
} else if (field === 'Email') { } else if (field === 'Email') {
//http://github.com/jashkenas/coffee-script/issues#issue/342 s = (typeof (_c = ($('a.linkmail', table))) === "undefined" || _c == undefined ? undefined : _c.href.slice(7)) || '';
//s: $('a.linkmail', table)?.href.slice(7) || ''
s = ((_c = $('a.linkmail', table)) == undefined ? undefined : _c.href.slice(7)) || '';
} else if (field === 'Subject') { } else if (field === 'Subject') {
s = ((_d = $('span.filetitle', table)) == undefined ? undefined : _d.textContent) || ''; s = (typeof (_d = ($('span.filetitle', table))) === "undefined" || _d == undefined ? undefined : _d.textContent) || '';
} else if (field === 'Comment') { } else if (field === 'Comment') {
s = $('blockquote', table).textContent; s = $('blockquote', table).textContent;
} else if (field === 'File') { } else if (field === 'File') {
s = ((_e = $('span.filesize', table)) == undefined ? undefined : _e.textContent) || ''; s = (typeof (_e = ($('span.filesize', table))) === "undefined" || _e == undefined ? undefined : _e.textContent) || '';
} }
_g = filter[field].all.concat(filter[field].reply); _g = fields[field].reply;
for (_f = 0, _h = _g.length; _f < _h; _f++) { for (_f = 0, _h = _g.length; _f < _h; _f++) {
regex = _g[_f]; regex = _g[_f];
if (regex.test(s)) { if (regex.test(s)) {
@ -220,98 +218,98 @@ display: none; \
} }
}} }}
}; };
filterAll = function filterAll() { filterAll = function() {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, compiled, filter, imagesCount, num, replies, reply, thread, threads; var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, boards, compiled, el, field, filtered, imageCount, key, klass, match, nop, num, obj, regex, replies, reply, s, split, thread, threads, trimmed;
saveFilters(); saveFilters();
//better way of doing this? if we just say `compiled: filters`,
//changing a prop in one will change a prop in the other.
compiled = {}; compiled = {};
_a = filters; _a = filters;
for (filter in _a) { if (__hasProp.call(_a, filter)) { for (klass in _a) { if (__hasProp.call(_a, klass)) {
(function() { compiled[klass] = {};
var _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, el, field, filtered, key, match, nop, obj, regex, s, split, trimmed; boards = filters[klass];
compiled[filter] = {}; //for ['global', BOARD] of boards
_b = []; _c = filters[filter]; _b = boards['global'];
for (field in _c) { if (__hasProp.call(_c, field)) { for (field in _b) { if (__hasProp.call(_b, field)) {
_b.push((function() { s = boards['global'][field];
s = filters[filter][field]; split = s.split(';');
split = s.split(';'); trimmed = (function() {
trimmed = (function() { _c = []; _e = split;
_d = []; _f = split; for (_d = 0, _f = _e.length; _d < _f; _d++) {
for (_e = 0, _g = _f.length; _e < _g; _e++) { el = _e[_d];
el = _f[_e]; _c.push(el.trimLeft());
_d.push(el.trimLeft()); }
return _c;
})();
filtered = (function() {
_g = []; _i = trimmed;
for (_h = 0, _j = _i.length; _h < _j; _h++) {
el = _i[_h];
el.length ? _g.push(el) : null;
}
return _g;
})();
if (filtered.length) {
obj = {
op: [],
reply: []
};
_l = filtered;
for (_k = 0, _m = _l.length; _k < _m; _k++) {
el = _l[_k];
if (/\ -\w+$/.test(el)) {
_n = el.match(/(.+) -(\w+)$/);
nop = _n[0];
el = _n[1];
match = _n[2];
if (match === 'o') {
key = 'op';
} else if (match === 'O') {
key = 'reply';
} }
return _d;
})();
filtered = trimmed.filter(function(el) {
return el.length;
});
if (filtered.length) {
obj = {
all: [],
op: [],
reply: []
};
_i = filtered;
for (_h = 0, _j = _i.length; _h < _j; _h++) {
el = _i[_h];
if (/\ -\w+$/.test(el)) {
_k = el.match(/(.+) -(\w+)$/);
nop = _k[0];
el = _k[1];
match = _k[2];
if (match === 'o') {
key = 'op';
} else if (match === 'O') {
key = 'reply';
}
} else {
key = 'all';
}
regex = new RegExp(el, 'i');
obj[key].push(regex);
}
compiled[filter][field] = obj;
return compiled[filter][field];
} }
})()); regex = new RegExp(el, 'i');
}} if (key) {
return _b; obj[key].push(regex);
})(); } else {
obj['op'].push(regex);
obj['reply'].push(regex);
}
}
compiled[klass][field] = obj;
}
}}
}} }}
_b = reset(); _o = reset();
replies = _b[0]; replies = _o[0];
threads = _b[1]; threads = _o[1];
num = threads.length ? replies.length + threads.length : $$('blockquote').length; num = threads.length ? replies.length + threads.length : $$('blockquote').length;
//these loops look combinable //these loops look combinable
_d = replies; _q = replies;
for (_c = 0, _e = _d.length; _c < _e; _c++) { for (_p = 0, _r = _q.length; _p < _r; _p++) {
reply = _d[_c]; reply = _q[_p];
_f = compiled; _s = compiled;
for (filter in _f) { if (__hasProp.call(_f, filter)) { for (klass in _s) { if (__hasProp.call(_s, klass)) {
filterReply(reply, compiled[filter]) ? reply.className += ' ' + filter : null; filterReply(reply, compiled[klass]) ? reply.className += ' ' + klass : null;
}} }}
} }
_h = threads; _u = threads;
for (_g = 0, _i = _h.length; _g < _i; _g++) { for (_t = 0, _v = _u.length; _t < _v; _t++) {
thread = _h[_g]; thread = _u[_t];
_j = compiled; _w = compiled;
for (filter in _j) { if (__hasProp.call(_j, filter)) { for (klass in _w) { if (__hasProp.call(_w, klass)) {
filterThread(thread, compiled[filter]) ? thread.className += ' ' + filter : null; filterThread(thread, compiled[klass]) ? thread.className += ' ' + klass : null;
}} }}
} }
imagesCount = $$('img[md5]').length; imageCount = $$('img[md5]').length;
box.firstChild.textContent = ("Images: " + imagesCount + " Posts: " + num); box.firstChild.textContent = ("Images: " + imageCount + " Posts: " + num);
return box.firstChild.textContent; return box.firstChild.textContent;
}; };
keydown = function keydown(e) { keydown = function(e) {
if (e.keyCode === 13) { if (e.keyCode === 13) {
//enter //enter
return filterAll(); return filterAll();
} }
}; };
reset = function reset() { reset = function() {
var _a, _b, _c, _d, _e, _f, form, table, tables, thread, threads; var _a, _b, _c, _d, _e, _f, form, table, tables, thread, threads;
form = $('form[name="delform"]'); form = $('form[name="delform"]');
tables = $$('table', form); tables = $$('table', form);
@ -331,11 +329,11 @@ display: none; \
} }
return [tables, threads]; return [tables, threads];
}; };
autoHide = function autoHide() { autoHide = function() {
box.className === 'reply' ? (box.className = 'reply autohide') : (box.className = 'reply'); box.className === 'reply' ? (box.className = 'reply autohide') : (box.className = 'reply');
return GM_setValue('className', box.className); return GM_setValue('className', box.className);
}; };
save = function save() { save = function() {
var _a, _b, _c, div, input, inputs, option, value; var _a, _b, _c, div, input, inputs, option, value;
div = this.parentNode.parentNode; div = this.parentNode.parentNode;
inputs = $$('input:enabled', div); inputs = $$('input:enabled', div);
@ -346,26 +344,26 @@ display: none; \
filters[value] = {}; filters[value] = {};
option = tag('option'); option = tag('option');
option.textContent = value; option.textContent = value;
select.appendChild(option); sKlass.appendChild(option);
} }
} }
option == undefined ? undefined : option.selected = true; typeof option === "undefined" || option == undefined ? undefined : option.selected = true;
loadFilters(); loadFilters();
GM_setValue('filters', JSON.stringify(filters)); GM_setValue('filters', JSON.stringify(filters));
return remove(div); return remove(div);
}; };
cancel = function cancel() { cancel = function() {
var div; var div;
div = this.parentNode.parentNode; div = this.parentNode.parentNode;
return remove(div); return remove(div);
}; };
optionKeydown = function optionKeydown(e) { optionKeydown = function(e) {
if (e.keyCode === 13) { if (e.keyCode === 13) {
//enter //enter
return save.call(this.parentNode); return save.call(this.parentNode);
} }
}; };
addClass = function addClass() { addClass = function() {
var div, input; var div, input;
div = tag('div'); div = tag('div');
input = tag('input'); input = tag('input');
@ -374,20 +372,20 @@ display: none; \
inBefore(this, div); inBefore(this, div);
return input.focus(); return input.focus();
}; };
del = function del() { del = function() {
var _a, _b, _c, option, value; var _a, _b, _c, option, value;
value = this.nextElementSibling.value; value = this.nextElementSibling.value;
delete filters[value]; delete filters[value];
GM_setValue('filters', JSON.stringify(filters)); GM_setValue('filters', JSON.stringify(filters));
remove(this.parentNode); remove(this.parentNode);
_b = select.options; _b = sKlass.options;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_a = 0, _c = _b.length; _a < _c; _a++) {
option = _b[_a]; option = _b[_a];
option.value === value ? remove(option) : null; option.value === value ? remove(option) : null;
} }
return loadFilters(); return loadFilters();
}; };
options = function options() { options = function() {
var _a, a, bar, div, filter, filters, input, opt; var _a, a, bar, div, filter, filters, input, opt;
if ((opt = $('#box_options'))) { if ((opt = $('#box_options'))) {
return remove(opt); return remove(opt);
@ -436,9 +434,9 @@ display: none; \
return document.body.appendChild(opt); return document.body.appendChild(opt);
} }
}; };
loadFilters = function loadFilters() { loadFilters = function() {
var _a, _b, _c, _d, filter, input, inputs; var _a, _b, _c, _d, filter, input, inputs;
filter = filters[select.value]; filter = filters[sKlass.value][sBoard.value];
inputs = $$('input', box); inputs = $$('input', box);
_a = []; _c = inputs; _a = []; _c = inputs;
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
@ -447,7 +445,7 @@ display: none; \
} }
return _a; return _a;
}; };
saveFilters = function saveFilters() { saveFilters = function() {
var _a, _b, _c, filter, input, inputs, value; var _a, _b, _c, filter, input, inputs, value;
filter = {}; filter = {};
inputs = $$('input', box); inputs = $$('input', box);
@ -456,7 +454,7 @@ display: none; \
input = _b[_a]; input = _b[_a];
(value = input.value) ? (filter[input.name] = value) : null; (value = input.value) ? (filter[input.name] = value) : null;
} }
filters[select.value] = filter; filters[sKlass.value][sBoard.value] = filter;
return GM_setValue('filters', JSON.stringify(filters)); return GM_setValue('filters', JSON.stringify(filters));
}; };
box = tag('div'); box = tag('div');
@ -467,21 +465,34 @@ display: none; \
bar.className = 'move top'; bar.className = 'move top';
bar.addEventListener('mousedown', mousedown, true); bar.addEventListener('mousedown', mousedown, true);
box.appendChild(bar); box.appendChild(bar);
select = tag('select'); sKlass = tag('select');
select.addEventListener('mousedown', saveFilters, true); sKlass.addEventListener('mousedown', saveFilters, true);
select.addEventListener('mouseup', loadFilters, true); sKlass.addEventListener('mouseup', loadFilters, true);
filters = JSON.parse(GM_getValue('filters', '{ "hide": {} }')); defaultValue = JSON.stringify({
'hide': {
'global': []
}
});
filters = JSON.parse(GM_getValue('filters', defaultValue));
_a = filters; _a = filters;
for (filter in _a) { if (__hasProp.call(_a, filter)) { for (klass in _a) { if (__hasProp.call(_a, klass)) {
option = tag('option'); option = tag('option');
option.textContent = filter; option.textContent = klass;
select.appendChild(option); sKlass.appendChild(option);
}} }}
box.appendChild(select); box.appendChild(sKlass);
sBoard = tag('select');
_b = filters[klass];
for (board in _b) { if (__hasProp.call(_b, board)) {
option = tag('option');
option.textContent = board;
sBoard.appendChild(option);
}}
box.appendChild(sBoard);
fields = ['Name', 'Tripcode', 'Email', 'Subject', 'Comment', 'File']; fields = ['Name', 'Tripcode', 'Email', 'Subject', 'Comment', 'File'];
_c = fields; _d = fields;
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_c = 0, _e = _d.length; _c < _e; _c++) {
field = _c[_b]; field = _d[_c];
div = tag('div'); div = tag('div');
label = tag('label'); label = tag('label');
label.textContent = field; label.textContent = field;
@ -495,9 +506,9 @@ display: none; \
loadFilters(); loadFilters();
div = tag('div'); div = tag('div');
div.className = 'bottom'; div.className = 'bottom';
_f = ['apply', 'reset', 'options', 'autohide']; _g = ['apply', 'reset', 'options', 'autohide'];
for (_e = 0, _g = _f.length; _e < _g; _e++) { for (_f = 0, _h = _g.length; _f < _h; _f++) {
name = _f[_e]; name = _g[_f];
a = tag('a'); a = tag('a');
a.textContent = name; a.textContent = name;
if (name === 'apply') { if (name === 'apply') {