too much stuff
This commit is contained in:
parent
0e907014f4
commit
1622c81c4c
@ -604,7 +604,7 @@ expandComment: (e) ->
|
||||
|
||||
|
||||
report: ->
|
||||
input: x('preceding-sibling::input', this)
|
||||
input: x('preceding-sibling::input[1]', this)
|
||||
input.click()
|
||||
$('input[value="Report"]').click()
|
||||
input.click()
|
||||
@ -660,7 +660,7 @@ if getValue('Quick Reply')
|
||||
document.body.appendChild(iframe)
|
||||
|
||||
callbacks.push((root) ->
|
||||
quotes: $$('a.quotejs:not(:first-child)')
|
||||
quotes: $$('a.quotejs:not(:first-child)', root)
|
||||
for quote in quotes
|
||||
quote.addEventListener('click', quickReply, true)
|
||||
)
|
||||
|
||||
@ -18,18 +18,18 @@
|
||||
'Auto Watch': true,
|
||||
'Anonymize': false
|
||||
};
|
||||
getValue = function getValue(name) {
|
||||
getValue = function(name) {
|
||||
return GM_getValue(name, config[name]);
|
||||
};
|
||||
x = function x(path, root) {
|
||||
x = function(path, root) {
|
||||
root = root || document.body;
|
||||
return document.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
};
|
||||
$ = function $(selector, root) {
|
||||
$ = function(selector, root) {
|
||||
root = root || document.body;
|
||||
return root.querySelector(selector);
|
||||
};
|
||||
$$ = function $$(selector, root) {
|
||||
$$ = function(selector, root) {
|
||||
var _a, _b, _c, _d, node, result;
|
||||
root = root || document.body;
|
||||
result = root.querySelectorAll(selector);
|
||||
@ -41,33 +41,33 @@
|
||||
}
|
||||
return _a;
|
||||
};
|
||||
inBefore = function inBefore(root, el) {
|
||||
inBefore = function(root, el) {
|
||||
return root.parentNode.insertBefore(el, root);
|
||||
};
|
||||
inAfter = function inAfter(root, el) {
|
||||
inAfter = function(root, el) {
|
||||
return root.parentNode.insertBefore(el, root.nextSibling);
|
||||
};
|
||||
tag = function tag(el) {
|
||||
tag = function(el) {
|
||||
return document.createElement(el);
|
||||
};
|
||||
hide = function hide(el) {
|
||||
hide = function(el) {
|
||||
el.style.display = 'none';
|
||||
return el.style.display;
|
||||
};
|
||||
show = function show(el) {
|
||||
show = function(el) {
|
||||
el.style.display = '';
|
||||
return el.style.display;
|
||||
};
|
||||
remove = function remove(el) {
|
||||
remove = function(el) {
|
||||
return el.parentNode.removeChild(el);
|
||||
};
|
||||
replace = function replace(root, el) {
|
||||
replace = function(root, el) {
|
||||
return root.parentNode.replaceChild(el, root);
|
||||
};
|
||||
getTime = function getTime() {
|
||||
getTime = function() {
|
||||
return Math.floor(new Date().getTime() / 1000);
|
||||
};
|
||||
slice = function slice(arr, id) {
|
||||
slice = function(arr, id) {
|
||||
var i, l;
|
||||
// the while loop is the only low-level loop left in coffeescript.
|
||||
// we need to use it to see the index.
|
||||
@ -81,7 +81,7 @@
|
||||
i++;
|
||||
}
|
||||
};
|
||||
position = function position(el) {
|
||||
position = function(el) {
|
||||
var id, left, top;
|
||||
id = el.id;
|
||||
(left = GM_getValue(("" + (id) + "Left"), '0px')) ? (el.style.left = left) : (el.style.right = '0px');
|
||||
@ -94,11 +94,11 @@
|
||||
}
|
||||
};
|
||||
if (typeof GM_deleteValue === 'undefined') {
|
||||
this.GM_setValue = function GM_setValue(name, value) {
|
||||
this.GM_setValue = function(name, value) {
|
||||
value = (typeof value)[0] + value;
|
||||
return localStorage.setItem(name, value);
|
||||
};
|
||||
this.GM_getValue = function GM_getValue(name, defaultValue) {
|
||||
this.GM_getValue = function(name, defaultValue) {
|
||||
var type, value;
|
||||
if (!(value = localStorage.getItem(name))) {
|
||||
return defaultValue;
|
||||
@ -113,7 +113,7 @@
|
||||
return value;
|
||||
}
|
||||
};
|
||||
this.GM_addStyle = function GM_addStyle(css) {
|
||||
this.GM_addStyle = function(css) {
|
||||
var style;
|
||||
style = tag('style');
|
||||
style.type = 'text/css';
|
||||
@ -245,7 +245,7 @@ cursor: move; \
|
||||
cursor: pointer; \
|
||||
} \
|
||||
');
|
||||
options = function options() {
|
||||
options = function() {
|
||||
var _c, checked, div, option;
|
||||
if ((div = $('#options'))) {
|
||||
return remove(div);
|
||||
@ -268,7 +268,7 @@ cursor: pointer; \
|
||||
return document.body.appendChild(div);
|
||||
}
|
||||
};
|
||||
mousedown = function mousedown(e) {
|
||||
mousedown = function(e) {
|
||||
var div;
|
||||
div = this.parentNode;
|
||||
move.div = div;
|
||||
@ -281,7 +281,7 @@ cursor: pointer; \
|
||||
window.addEventListener('mousemove', mousemove, true);
|
||||
return window.addEventListener('mouseup', mouseup, true);
|
||||
};
|
||||
mousemove = function mousemove(e) {
|
||||
mousemove = function(e) {
|
||||
var div, left, realX, realY, top;
|
||||
div = move.div;
|
||||
realX = move.divX + (e.clientX - move.clientX);
|
||||
@ -307,14 +307,14 @@ cursor: pointer; \
|
||||
return div.style.bottom;
|
||||
}
|
||||
};
|
||||
mouseup = function mouseup() {
|
||||
mouseup = function() {
|
||||
id = move.div.id;
|
||||
GM_setValue(("" + (id) + "Left"), move.div.style.left);
|
||||
GM_setValue(("" + (id) + "Top"), move.div.style.top);
|
||||
window.removeEventListener('mousemove', mousemove, true);
|
||||
return window.removeEventListener('mouseup', mouseup, true);
|
||||
};
|
||||
showThread = function showThread() {
|
||||
showThread = function() {
|
||||
var div;
|
||||
div = this.nextSibling;
|
||||
show(div);
|
||||
@ -323,7 +323,7 @@ cursor: pointer; \
|
||||
slice(hiddenThreads, id);
|
||||
return GM_setValue(("hiddenThreads/" + BOARD + "/"), JSON.stringify(hiddenThreads));
|
||||
};
|
||||
hideThread = function hideThread(div) {
|
||||
hideThread = function(div) {
|
||||
var _c, a, n, name, p, span, text, trip;
|
||||
if ((p = this.parentNode)) {
|
||||
div = p;
|
||||
@ -340,14 +340,14 @@ cursor: pointer; \
|
||||
n += $$('table', div).length;
|
||||
text = n === 1 ? "1 reply" : ("" + n + " replies");
|
||||
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.className = 'pointer';
|
||||
a.addEventListener('click', showThread, true);
|
||||
return inBefore(div, a);
|
||||
}
|
||||
};
|
||||
threadF = function threadF(current) {
|
||||
threadF = function(current) {
|
||||
var _c, _d, _e, a, div, hidden;
|
||||
div = tag('div');
|
||||
a = tag('a');
|
||||
@ -376,7 +376,7 @@ cursor: pointer; \
|
||||
return threadF(current);
|
||||
}
|
||||
};
|
||||
showReply = function showReply() {
|
||||
showReply = function() {
|
||||
var div, table;
|
||||
div = this.parentNode;
|
||||
table = div.nextSibling;
|
||||
@ -386,7 +386,7 @@ cursor: pointer; \
|
||||
slice(hiddenReplies, id);
|
||||
return GM_setValue(("hiddenReplies/" + BOARD + "/"), JSON.stringify(hiddenReplies));
|
||||
};
|
||||
hideReply = function hideReply(reply) {
|
||||
hideReply = function(reply) {
|
||||
var _c, a, div, name, p, table, trip;
|
||||
if ((p = this.parentNode)) {
|
||||
reply = p.nextSibling;
|
||||
@ -397,7 +397,7 @@ cursor: pointer; \
|
||||
GM_setValue(("hiddenReplies/" + BOARD + "/"), JSON.stringify(hiddenReplies));
|
||||
}
|
||||
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);
|
||||
hide(table);
|
||||
if (getValue('Show Stubs')) {
|
||||
@ -410,7 +410,7 @@ cursor: pointer; \
|
||||
return inBefore(table, div);
|
||||
}
|
||||
};
|
||||
optionsSave = function optionsSave() {
|
||||
optionsSave = function() {
|
||||
var _c, _d, _e, div, input, inputs;
|
||||
div = this.parentNode.parentNode;
|
||||
inputs = $$('input', div);
|
||||
@ -421,12 +421,12 @@ cursor: pointer; \
|
||||
}
|
||||
return remove(div);
|
||||
};
|
||||
close = function close() {
|
||||
close = function() {
|
||||
var div;
|
||||
div = this.parentNode.parentNode;
|
||||
return remove(div);
|
||||
};
|
||||
iframeLoad = function iframeLoad() {
|
||||
iframeLoad = function() {
|
||||
var error, qr, span;
|
||||
if ((iframeLoop = !iframeLoop)) {
|
||||
return null;
|
||||
@ -443,14 +443,14 @@ cursor: pointer; \
|
||||
return remove(qr);
|
||||
}
|
||||
};
|
||||
submit = function submit() {
|
||||
submit = function() {
|
||||
var span;
|
||||
this.style.visibility = 'collapse';
|
||||
if ((span = this.nextSibling)) {
|
||||
return remove(span);
|
||||
}
|
||||
};
|
||||
minimize = function minimize() {
|
||||
minimize = function() {
|
||||
var form;
|
||||
form = this.parentNode.nextSibling;
|
||||
if (form.style.visibility) {
|
||||
@ -461,7 +461,7 @@ cursor: pointer; \
|
||||
return form.style.visibility;
|
||||
}
|
||||
};
|
||||
quickReply = function quickReply(e) {
|
||||
quickReply = function(e) {
|
||||
var _c, a, clone, div, input, qr, selText, selection, textarea, xpath;
|
||||
e.preventDefault();
|
||||
if (!(qr = $('#qr'))) {
|
||||
@ -506,11 +506,11 @@ cursor: pointer; \
|
||||
//xx
|
||||
textarea.value += '>>' + this.parentNode.id.match(/\d+$/)[0] + '\n';
|
||||
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;
|
||||
return textarea.focus();
|
||||
};
|
||||
watch = function watch() {
|
||||
watch = function() {
|
||||
var text;
|
||||
id = this.nextSibling.name;
|
||||
if (this.src[0] === 'd') {
|
||||
@ -529,7 +529,7 @@ cursor: pointer; \
|
||||
GM_setValue('watched', JSON.stringify(watched));
|
||||
return watcherUpdate();
|
||||
};
|
||||
watchX = function watchX() {
|
||||
watchX = function() {
|
||||
var _c, img, input;
|
||||
_c = this.nextElementSibling.getAttribute('href').split('/');
|
||||
nop = _c[0];
|
||||
@ -545,7 +545,7 @@ cursor: pointer; \
|
||||
return img.src;
|
||||
}
|
||||
};
|
||||
watcherUpdate = function watcherUpdate() {
|
||||
watcherUpdate = function() {
|
||||
var _c, _d, _e, _f, a, div, old;
|
||||
div = tag('div');
|
||||
_c = watched;
|
||||
@ -569,7 +569,7 @@ cursor: pointer; \
|
||||
old = $('#watcher div:last-child');
|
||||
return replace(old, div);
|
||||
};
|
||||
parseResponse = function parseResponse(responseText) {
|
||||
parseResponse = function(responseText) {
|
||||
var body, opbq, replies;
|
||||
body = tag('body');
|
||||
body.innerHTML = responseText;
|
||||
@ -577,7 +577,7 @@ cursor: pointer; \
|
||||
opbq = $('blockquote', body);
|
||||
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;
|
||||
_c = parseResponse(responseText);
|
||||
replies = _c[0];
|
||||
@ -607,7 +607,7 @@ cursor: pointer; \
|
||||
return _h;
|
||||
}
|
||||
};
|
||||
expandThread = function expandThread() {
|
||||
expandThread = function() {
|
||||
var _c, _d, _e, num, prev, span, table, xhr;
|
||||
id = x('preceding-sibling::input[1]', this).name;
|
||||
span = this;
|
||||
@ -635,7 +635,7 @@ cursor: pointer; \
|
||||
}
|
||||
//create new request
|
||||
r = new XMLHttpRequest();
|
||||
r.onload = function onload() {
|
||||
r.onload = function() {
|
||||
return onloadThread(this.responseText, span);
|
||||
};
|
||||
r.open('GET', ("res/" + id), true);
|
||||
@ -645,7 +645,7 @@ cursor: pointer; \
|
||||
id: id
|
||||
});
|
||||
};
|
||||
onloadComment = function onloadComment(responseText, a, href) {
|
||||
onloadComment = function(responseText, a, href) {
|
||||
var _c, _d, _e, _f, _g, bq, op, opbq, replies, reply;
|
||||
_c = href.match(/(\d+)#(\d+)/);
|
||||
nop = _c[0];
|
||||
@ -669,13 +669,13 @@ cursor: pointer; \
|
||||
bq.innerHTML = html;
|
||||
return bq.innerHTML;
|
||||
};
|
||||
expandComment = function expandComment(e) {
|
||||
expandComment = function(e) {
|
||||
var a, href;
|
||||
e.preventDefault();
|
||||
a = this;
|
||||
href = a.getAttribute('href');
|
||||
r = new XMLHttpRequest();
|
||||
r.onload = function onload() {
|
||||
r.onload = function() {
|
||||
return onloadComment(this.responseText, a, href);
|
||||
};
|
||||
r.open('GET', href, true);
|
||||
@ -685,14 +685,14 @@ cursor: pointer; \
|
||||
id: href.match(/\d+/)[0]
|
||||
});
|
||||
};
|
||||
report = function report() {
|
||||
report = function() {
|
||||
var input;
|
||||
input = x('preceding-sibling::input', this);
|
||||
input = x('preceding-sibling::input[1]', this);
|
||||
input.click();
|
||||
$('input[value="Report"]').click();
|
||||
return input.click();
|
||||
};
|
||||
nodeInserted = function nodeInserted(e) {
|
||||
nodeInserted = function(e) {
|
||||
var _c, _d, _e, _f, callback, target;
|
||||
target = e.target;
|
||||
if (target.nodeName === 'TABLE') {
|
||||
@ -704,15 +704,15 @@ cursor: pointer; \
|
||||
return _c;
|
||||
}
|
||||
};
|
||||
autoWatch = function autoWatch() {
|
||||
autoWatch = function() {
|
||||
var autoText;
|
||||
autoText = $('textarea', this).value.slice(0, 25);
|
||||
return GM_setValue('autoText', ("/" + BOARD + "/ - " + autoText));
|
||||
};
|
||||
stopPropagation = function stopPropagation(e) {
|
||||
stopPropagation = function(e) {
|
||||
return e.stopPropagation();
|
||||
};
|
||||
replyNav = function replyNav() {
|
||||
replyNav = function() {
|
||||
var direction, op;
|
||||
if (REPLY) {
|
||||
window.location = this.textContent === '▲' ? '#navtop' : '#navbot';
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// @name 4chan x
|
||||
// @namespace aeosynth
|
||||
// @description Adds various features; replaces the extension / fychan.
|
||||
// @version 1.0.10
|
||||
// @version 1.0.11
|
||||
// @copyright 2009, 2010 James Campos
|
||||
// @license MIT; http://en.wikipedia.org/wiki/Mit_license
|
||||
// @include http://boards.4chan.org/*
|
||||
|
||||
@ -139,8 +139,8 @@ GM_addStyle('
|
||||
#duplicated code. sigh.
|
||||
# we could try threading the op, but that might affect other scripts.
|
||||
# also, I really want to try out *gasp* eval().
|
||||
filterThread: (thread, filter) ->
|
||||
for field of filter
|
||||
filterThread: (thread, fields) ->
|
||||
for field of fields
|
||||
switch field
|
||||
when 'Name'
|
||||
s: $('span.postername', thread).textContent
|
||||
@ -154,29 +154,27 @@ filterThread: (thread, filter) ->
|
||||
s: $('blockquote', thread).textContent
|
||||
when 'File'
|
||||
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)
|
||||
return true
|
||||
|
||||
|
||||
filterReply: (table, filter) ->
|
||||
for field of filter
|
||||
filterReply: (table, fields) ->
|
||||
for field of fields
|
||||
switch field
|
||||
when 'Name'
|
||||
s: $('span.commentpostername', table).textContent
|
||||
when 'Tripcode'
|
||||
s: $('span.postertrip', table)?.textContent || ''
|
||||
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'
|
||||
s: $('span.filetitle', table)?.textContent || ''
|
||||
when 'Comment'
|
||||
s: $('blockquote', table).textContent
|
||||
when 'File'
|
||||
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)
|
||||
return true
|
||||
|
||||
@ -184,19 +182,18 @@ filterReply: (table, filter) ->
|
||||
filterAll: ->
|
||||
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: {}
|
||||
for filter of filters
|
||||
compiled[filter]: {}
|
||||
for field of filters[filter]
|
||||
s: filters[filter][field]
|
||||
for klass of filters
|
||||
compiled[klass]: {}
|
||||
boards: filters[klass]
|
||||
#for ['global', BOARD] of boards
|
||||
for field of boards['global']
|
||||
s: boards['global'][field]
|
||||
split: s.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
|
||||
obj: {
|
||||
all: []
|
||||
op: []
|
||||
reply: []
|
||||
}
|
||||
@ -206,27 +203,29 @@ filterAll: ->
|
||||
switch match
|
||||
when 'o' then key: 'op'
|
||||
when 'O' then key: 'reply'
|
||||
else
|
||||
key: 'all'
|
||||
regex: new RegExp(el, 'i')
|
||||
obj[key].push(regex)
|
||||
compiled[filter][field]: obj
|
||||
if key
|
||||
obj[key].push(regex)
|
||||
else
|
||||
obj['op'].push(regex)
|
||||
obj['reply'].push(regex)
|
||||
compiled[klass][field]: obj
|
||||
|
||||
[replies, threads]: reset()
|
||||
num: if threads.length then replies.length + threads.length else $$('blockquote').length
|
||||
|
||||
#these loops look combinable
|
||||
for reply in replies
|
||||
for filter of compiled
|
||||
if filterReply(reply, compiled[filter])
|
||||
reply.className+= ' ' + filter
|
||||
for klass of compiled
|
||||
if filterReply(reply, compiled[klass])
|
||||
reply.className+= ' ' + klass
|
||||
for thread in threads
|
||||
for filter of compiled
|
||||
if filterThread(thread, compiled[filter])
|
||||
thread.className+= ' ' + filter
|
||||
for klass of compiled
|
||||
if filterThread(thread, compiled[klass])
|
||||
thread.className+= ' ' + klass
|
||||
|
||||
imagesCount: $$('img[md5]').length
|
||||
box.firstChild.textContent: "Images: $imagesCount Posts: $num"
|
||||
imageCount: $$('img[md5]').length
|
||||
box.firstChild.textContent: "Images: $imageCount Posts: $num"
|
||||
|
||||
|
||||
keydown: (e) ->
|
||||
@ -266,7 +265,7 @@ save: ->
|
||||
filters[value]: {}
|
||||
option: tag('option')
|
||||
option.textContent: value
|
||||
select.appendChild(option)
|
||||
sKlass.appendChild(option)
|
||||
option?.selected: true
|
||||
loadFilters()
|
||||
GM_setValue('filters', JSON.stringify(filters))
|
||||
@ -297,7 +296,7 @@ del: ->
|
||||
delete filters[value]
|
||||
GM_setValue('filters', JSON.stringify(filters))
|
||||
remove @parentNode
|
||||
for option in select.options
|
||||
for option in sKlass.options
|
||||
if option.value is value
|
||||
remove option
|
||||
loadFilters()
|
||||
@ -354,7 +353,7 @@ options: ->
|
||||
|
||||
|
||||
loadFilters: ->
|
||||
filter: filters[select.value]
|
||||
filter: filters[sKlass.value][sBoard.value]
|
||||
inputs: $$('input', box)
|
||||
for input in inputs
|
||||
input.value: filter[input.name] || ''
|
||||
@ -366,7 +365,7 @@ saveFilters: ->
|
||||
for input in inputs
|
||||
if value: input.value
|
||||
filter[input.name]: value
|
||||
filters[select.value]: filter
|
||||
filters[sKlass.value][sBoard.value]: filter
|
||||
GM_setValue('filters', JSON.stringify(filters))
|
||||
|
||||
|
||||
@ -380,15 +379,27 @@ bar.className: 'move top'
|
||||
bar.addEventListener('mousedown', mousedown, true)
|
||||
box.appendChild(bar)
|
||||
|
||||
select: tag('select')
|
||||
select.addEventListener('mousedown', saveFilters, true)
|
||||
select.addEventListener('mouseup', loadFilters, true)
|
||||
filters: JSON.parse(GM_getValue('filters', '{ "hide": {} }'))
|
||||
for filter of filters
|
||||
sKlass: tag('select')
|
||||
sKlass.addEventListener('mousedown', saveFilters, true)
|
||||
sKlass.addEventListener('mouseup', loadFilters, true)
|
||||
defaultValue: JSON.stringify({
|
||||
'hide': {
|
||||
'global': []
|
||||
}
|
||||
})
|
||||
filters: JSON.parse(GM_getValue('filters', defaultValue))
|
||||
for klass of filters
|
||||
option: tag('option')
|
||||
option.textContent: filter
|
||||
select.appendChild(option)
|
||||
box.appendChild(select)
|
||||
option.textContent: klass
|
||||
sKlass.appendChild(option)
|
||||
box.appendChild(sKlass)
|
||||
|
||||
sBoard: tag('select')
|
||||
for board of filters[klass]
|
||||
option: tag('option')
|
||||
option.textContent: board
|
||||
sBoard.appendChild(option)
|
||||
box.appendChild(sBoard)
|
||||
|
||||
fields: [
|
||||
'Name',
|
||||
|
||||
275
foltor/foltor.js
275
foltor/foltor.js
@ -1,15 +1,15 @@
|
||||
(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;
|
||||
x = function x(path, root) {
|
||||
x = function(path, root) {
|
||||
root = root || document.body;
|
||||
return document.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
};
|
||||
$ = function $(selector, root) {
|
||||
$ = function(selector, root) {
|
||||
root = root || document.body;
|
||||
return root.querySelector(selector);
|
||||
};
|
||||
$$ = function $$(selector, root) {
|
||||
$$ = function(selector, root) {
|
||||
var _a, _b, _c, _d, node, result;
|
||||
root = root || document.body;
|
||||
result = root.querySelectorAll(selector);
|
||||
@ -21,19 +21,19 @@
|
||||
}
|
||||
return _a;
|
||||
};
|
||||
inBefore = function inBefore(root, el) {
|
||||
inBefore = function(root, el) {
|
||||
return root.parentNode.insertBefore(el, root);
|
||||
};
|
||||
tag = function tag(el) {
|
||||
tag = function(el) {
|
||||
return document.createElement(el);
|
||||
};
|
||||
text = function text(s) {
|
||||
text = function(s) {
|
||||
return document.createTextNode(s);
|
||||
};
|
||||
remove = function remove(root) {
|
||||
remove = function(root) {
|
||||
return root.parentNode.removeChild(root);
|
||||
};
|
||||
position = function position(el) {
|
||||
position = function(el) {
|
||||
var id, left, top;
|
||||
id = el.id;
|
||||
(left = GM_getValue(("" + (id) + "Left"), '0px')) ? (el.style.left = left) : (el.style.right = '0px');
|
||||
@ -46,7 +46,7 @@
|
||||
}
|
||||
};
|
||||
move = {};
|
||||
mousedown = function mousedown(e) {
|
||||
mousedown = function(e) {
|
||||
var div;
|
||||
div = this.parentNode;
|
||||
move.div = div;
|
||||
@ -59,7 +59,7 @@
|
||||
window.addEventListener('mousemove', mousemove, true);
|
||||
return window.addEventListener('mouseup', mouseup, true);
|
||||
};
|
||||
mousemove = function mousemove(e) {
|
||||
mousemove = function(e) {
|
||||
var div, left, realX, realY, top;
|
||||
div = move.div;
|
||||
realX = move.divX + (e.clientX - move.clientX);
|
||||
@ -85,7 +85,7 @@
|
||||
return div.style.bottom;
|
||||
}
|
||||
};
|
||||
mouseup = function mouseup() {
|
||||
mouseup = function() {
|
||||
var id;
|
||||
id = move.div.id;
|
||||
GM_setValue(("" + (id) + "Left"), move.div.style.left);
|
||||
@ -95,11 +95,11 @@
|
||||
};
|
||||
//x-browser
|
||||
if (typeof GM_deleteValue === 'undefined') {
|
||||
this.GM_setValue = function GM_setValue(name, value) {
|
||||
this.GM_setValue = function(name, value) {
|
||||
value = (typeof value)[0] + value;
|
||||
return localStorage.setItem(name, value);
|
||||
};
|
||||
this.GM_getValue = function GM_getValue(name, defaultValue) {
|
||||
this.GM_getValue = function(name, defaultValue) {
|
||||
var type, value;
|
||||
if (!(value = localStorage.getItem(name))) {
|
||||
return defaultValue;
|
||||
@ -114,7 +114,7 @@
|
||||
return value;
|
||||
}
|
||||
};
|
||||
this.GM_addStyle = function GM_addStyle(css) {
|
||||
this.GM_addStyle = function(css) {
|
||||
var style;
|
||||
style = tag('style');
|
||||
style.type = 'text/css';
|
||||
@ -166,24 +166,24 @@ display: none; \
|
||||
//duplicated code. sigh.
|
||||
// we could try threading the op, but that might affect other scripts.
|
||||
// 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;
|
||||
_a = filter;
|
||||
_a = fields;
|
||||
for (field in _a) { if (__hasProp.call(_a, field)) {
|
||||
if (field === 'Name') {
|
||||
s = $('span.postername', thread).textContent;
|
||||
} 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') {
|
||||
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') {
|
||||
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') {
|
||||
s = $('blockquote', thread).textContent;
|
||||
} 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++) {
|
||||
regex = _g[_f];
|
||||
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;
|
||||
_a = filter;
|
||||
_a = fields;
|
||||
for (field in _a) { if (__hasProp.call(_a, field)) {
|
||||
if (field === 'Name') {
|
||||
s = $('span.commentpostername', table).textContent;
|
||||
} 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') {
|
||||
//http://github.com/jashkenas/coffee-script/issues#issue/342
|
||||
//s: $('a.linkmail', table)?.href.slice(7) || ''
|
||||
s = ((_c = $('a.linkmail', table)) == undefined ? undefined : _c.href.slice(7)) || '';
|
||||
s = (typeof (_c = ($('a.linkmail', table))) === "undefined" || _c == undefined ? undefined : _c.href.slice(7)) || '';
|
||||
} 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') {
|
||||
s = $('blockquote', table).textContent;
|
||||
} 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++) {
|
||||
regex = _g[_f];
|
||||
if (regex.test(s)) {
|
||||
@ -220,98 +218,98 @@ display: none; \
|
||||
}
|
||||
}}
|
||||
};
|
||||
filterAll = function filterAll() {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, compiled, filter, imagesCount, num, replies, reply, thread, threads;
|
||||
filterAll = function() {
|
||||
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();
|
||||
//better way of doing this? if we just say `compiled: filters`,
|
||||
//changing a prop in one will change a prop in the other.
|
||||
compiled = {};
|
||||
_a = filters;
|
||||
for (filter in _a) { if (__hasProp.call(_a, filter)) {
|
||||
(function() {
|
||||
var _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, el, field, filtered, key, match, nop, obj, regex, s, split, trimmed;
|
||||
compiled[filter] = {};
|
||||
_b = []; _c = filters[filter];
|
||||
for (field in _c) { if (__hasProp.call(_c, field)) {
|
||||
_b.push((function() {
|
||||
s = filters[filter][field];
|
||||
split = s.split(';');
|
||||
trimmed = (function() {
|
||||
_d = []; _f = split;
|
||||
for (_e = 0, _g = _f.length; _e < _g; _e++) {
|
||||
el = _f[_e];
|
||||
_d.push(el.trimLeft());
|
||||
for (klass in _a) { if (__hasProp.call(_a, klass)) {
|
||||
compiled[klass] = {};
|
||||
boards = filters[klass];
|
||||
//for ['global', BOARD] of boards
|
||||
_b = boards['global'];
|
||||
for (field in _b) { if (__hasProp.call(_b, field)) {
|
||||
s = boards['global'][field];
|
||||
split = s.split(';');
|
||||
trimmed = (function() {
|
||||
_c = []; _e = split;
|
||||
for (_d = 0, _f = _e.length; _d < _f; _d++) {
|
||||
el = _e[_d];
|
||||
_c.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];
|
||||
}
|
||||
})());
|
||||
}}
|
||||
return _b;
|
||||
})();
|
||||
regex = new RegExp(el, 'i');
|
||||
if (key) {
|
||||
obj[key].push(regex);
|
||||
} else {
|
||||
obj['op'].push(regex);
|
||||
obj['reply'].push(regex);
|
||||
}
|
||||
}
|
||||
compiled[klass][field] = obj;
|
||||
}
|
||||
}}
|
||||
}}
|
||||
_b = reset();
|
||||
replies = _b[0];
|
||||
threads = _b[1];
|
||||
_o = reset();
|
||||
replies = _o[0];
|
||||
threads = _o[1];
|
||||
num = threads.length ? replies.length + threads.length : $$('blockquote').length;
|
||||
//these loops look combinable
|
||||
_d = replies;
|
||||
for (_c = 0, _e = _d.length; _c < _e; _c++) {
|
||||
reply = _d[_c];
|
||||
_f = compiled;
|
||||
for (filter in _f) { if (__hasProp.call(_f, filter)) {
|
||||
filterReply(reply, compiled[filter]) ? reply.className += ' ' + filter : null;
|
||||
_q = replies;
|
||||
for (_p = 0, _r = _q.length; _p < _r; _p++) {
|
||||
reply = _q[_p];
|
||||
_s = compiled;
|
||||
for (klass in _s) { if (__hasProp.call(_s, klass)) {
|
||||
filterReply(reply, compiled[klass]) ? reply.className += ' ' + klass : null;
|
||||
}}
|
||||
}
|
||||
_h = threads;
|
||||
for (_g = 0, _i = _h.length; _g < _i; _g++) {
|
||||
thread = _h[_g];
|
||||
_j = compiled;
|
||||
for (filter in _j) { if (__hasProp.call(_j, filter)) {
|
||||
filterThread(thread, compiled[filter]) ? thread.className += ' ' + filter : null;
|
||||
_u = threads;
|
||||
for (_t = 0, _v = _u.length; _t < _v; _t++) {
|
||||
thread = _u[_t];
|
||||
_w = compiled;
|
||||
for (klass in _w) { if (__hasProp.call(_w, klass)) {
|
||||
filterThread(thread, compiled[klass]) ? thread.className += ' ' + klass : null;
|
||||
}}
|
||||
}
|
||||
imagesCount = $$('img[md5]').length;
|
||||
box.firstChild.textContent = ("Images: " + imagesCount + " Posts: " + num);
|
||||
imageCount = $$('img[md5]').length;
|
||||
box.firstChild.textContent = ("Images: " + imageCount + " Posts: " + num);
|
||||
return box.firstChild.textContent;
|
||||
};
|
||||
keydown = function keydown(e) {
|
||||
keydown = function(e) {
|
||||
if (e.keyCode === 13) {
|
||||
//enter
|
||||
return filterAll();
|
||||
}
|
||||
};
|
||||
reset = function reset() {
|
||||
reset = function() {
|
||||
var _a, _b, _c, _d, _e, _f, form, table, tables, thread, threads;
|
||||
form = $('form[name="delform"]');
|
||||
tables = $$('table', form);
|
||||
@ -331,11 +329,11 @@ display: none; \
|
||||
}
|
||||
return [tables, threads];
|
||||
};
|
||||
autoHide = function autoHide() {
|
||||
autoHide = function() {
|
||||
box.className === 'reply' ? (box.className = 'reply autohide') : (box.className = 'reply');
|
||||
return GM_setValue('className', box.className);
|
||||
};
|
||||
save = function save() {
|
||||
save = function() {
|
||||
var _a, _b, _c, div, input, inputs, option, value;
|
||||
div = this.parentNode.parentNode;
|
||||
inputs = $$('input:enabled', div);
|
||||
@ -346,26 +344,26 @@ display: none; \
|
||||
filters[value] = {};
|
||||
option = tag('option');
|
||||
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();
|
||||
GM_setValue('filters', JSON.stringify(filters));
|
||||
return remove(div);
|
||||
};
|
||||
cancel = function cancel() {
|
||||
cancel = function() {
|
||||
var div;
|
||||
div = this.parentNode.parentNode;
|
||||
return remove(div);
|
||||
};
|
||||
optionKeydown = function optionKeydown(e) {
|
||||
optionKeydown = function(e) {
|
||||
if (e.keyCode === 13) {
|
||||
//enter
|
||||
return save.call(this.parentNode);
|
||||
}
|
||||
};
|
||||
addClass = function addClass() {
|
||||
addClass = function() {
|
||||
var div, input;
|
||||
div = tag('div');
|
||||
input = tag('input');
|
||||
@ -374,20 +372,20 @@ display: none; \
|
||||
inBefore(this, div);
|
||||
return input.focus();
|
||||
};
|
||||
del = function del() {
|
||||
del = function() {
|
||||
var _a, _b, _c, option, value;
|
||||
value = this.nextElementSibling.value;
|
||||
delete filters[value];
|
||||
GM_setValue('filters', JSON.stringify(filters));
|
||||
remove(this.parentNode);
|
||||
_b = select.options;
|
||||
_b = sKlass.options;
|
||||
for (_a = 0, _c = _b.length; _a < _c; _a++) {
|
||||
option = _b[_a];
|
||||
option.value === value ? remove(option) : null;
|
||||
}
|
||||
return loadFilters();
|
||||
};
|
||||
options = function options() {
|
||||
options = function() {
|
||||
var _a, a, bar, div, filter, filters, input, opt;
|
||||
if ((opt = $('#box_options'))) {
|
||||
return remove(opt);
|
||||
@ -436,9 +434,9 @@ display: none; \
|
||||
return document.body.appendChild(opt);
|
||||
}
|
||||
};
|
||||
loadFilters = function loadFilters() {
|
||||
loadFilters = function() {
|
||||
var _a, _b, _c, _d, filter, input, inputs;
|
||||
filter = filters[select.value];
|
||||
filter = filters[sKlass.value][sBoard.value];
|
||||
inputs = $$('input', box);
|
||||
_a = []; _c = inputs;
|
||||
for (_b = 0, _d = _c.length; _b < _d; _b++) {
|
||||
@ -447,7 +445,7 @@ display: none; \
|
||||
}
|
||||
return _a;
|
||||
};
|
||||
saveFilters = function saveFilters() {
|
||||
saveFilters = function() {
|
||||
var _a, _b, _c, filter, input, inputs, value;
|
||||
filter = {};
|
||||
inputs = $$('input', box);
|
||||
@ -456,7 +454,7 @@ display: none; \
|
||||
input = _b[_a];
|
||||
(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));
|
||||
};
|
||||
box = tag('div');
|
||||
@ -467,21 +465,34 @@ display: none; \
|
||||
bar.className = 'move top';
|
||||
bar.addEventListener('mousedown', mousedown, true);
|
||||
box.appendChild(bar);
|
||||
select = tag('select');
|
||||
select.addEventListener('mousedown', saveFilters, true);
|
||||
select.addEventListener('mouseup', loadFilters, true);
|
||||
filters = JSON.parse(GM_getValue('filters', '{ "hide": {} }'));
|
||||
sKlass = tag('select');
|
||||
sKlass.addEventListener('mousedown', saveFilters, true);
|
||||
sKlass.addEventListener('mouseup', loadFilters, true);
|
||||
defaultValue = JSON.stringify({
|
||||
'hide': {
|
||||
'global': []
|
||||
}
|
||||
});
|
||||
filters = JSON.parse(GM_getValue('filters', defaultValue));
|
||||
_a = filters;
|
||||
for (filter in _a) { if (__hasProp.call(_a, filter)) {
|
||||
for (klass in _a) { if (__hasProp.call(_a, klass)) {
|
||||
option = tag('option');
|
||||
option.textContent = filter;
|
||||
select.appendChild(option);
|
||||
option.textContent = klass;
|
||||
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'];
|
||||
_c = fields;
|
||||
for (_b = 0, _d = _c.length; _b < _d; _b++) {
|
||||
field = _c[_b];
|
||||
_d = fields;
|
||||
for (_c = 0, _e = _d.length; _c < _e; _c++) {
|
||||
field = _d[_c];
|
||||
div = tag('div');
|
||||
label = tag('label');
|
||||
label.textContent = field;
|
||||
@ -495,9 +506,9 @@ display: none; \
|
||||
loadFilters();
|
||||
div = tag('div');
|
||||
div.className = 'bottom';
|
||||
_f = ['apply', 'reset', 'options', 'autohide'];
|
||||
for (_e = 0, _g = _f.length; _e < _g; _e++) {
|
||||
name = _f[_e];
|
||||
_g = ['apply', 'reset', 'options', 'autohide'];
|
||||
for (_f = 0, _h = _g.length; _f < _h; _f++) {
|
||||
name = _g[_f];
|
||||
a = tag('a');
|
||||
a.textContent = name;
|
||||
if (name === 'apply') {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user