start using make
This commit is contained in:
parent
ca8832e670
commit
cae39703d7
@ -49,9 +49,16 @@ replace: (root, el) ->
|
|||||||
root.parentNode.replaceChild(el, root)
|
root.parentNode.replaceChild(el, root)
|
||||||
getTime: ->
|
getTime: ->
|
||||||
Math.floor(new Date().getTime() / 1000)
|
Math.floor(new Date().getTime() / 1000)
|
||||||
|
make: (tag, obj) ->
|
||||||
|
el: document.createElement(tag)
|
||||||
|
if obj
|
||||||
|
for key of obj
|
||||||
|
el[key]: obj[key]
|
||||||
|
return el
|
||||||
slice: (arr, id) ->
|
slice: (arr, id) ->
|
||||||
# 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.
|
||||||
|
# would it be better to just use objects and the `delete` keyword?
|
||||||
i: 0
|
i: 0
|
||||||
l: arr.length
|
l: arr.length
|
||||||
while (i < l)
|
while (i < l)
|
||||||
@ -71,6 +78,7 @@ position: (el) ->
|
|||||||
el.style.bottom: '0px'
|
el.style.bottom: '0px'
|
||||||
|
|
||||||
|
|
||||||
|
# x-browser
|
||||||
if typeof GM_deleteValue == 'undefined'
|
if typeof GM_deleteValue == 'undefined'
|
||||||
this.GM_setValue: (name, value) ->
|
this.GM_setValue: (name, value) ->
|
||||||
value: (typeof value)[0] + value
|
value: (typeof value)[0] + value
|
||||||
@ -121,7 +129,6 @@ else
|
|||||||
PAGENUM: parseInt(magic) || 0
|
PAGENUM: parseInt(magic) || 0
|
||||||
xhrs: []
|
xhrs: []
|
||||||
r: null
|
r: null
|
||||||
head: $('head', document)
|
|
||||||
iframeLoop: false
|
iframeLoop: false
|
||||||
move: { }
|
move: { }
|
||||||
callbacks: []
|
callbacks: []
|
||||||
@ -224,6 +231,7 @@ clearHidden: ->
|
|||||||
|
|
||||||
|
|
||||||
options: ->
|
options: ->
|
||||||
|
#redo this
|
||||||
if div: $('#options')
|
if div: $('#options')
|
||||||
remove(div)
|
remove(div)
|
||||||
else
|
else
|
||||||
@ -445,19 +453,21 @@ quickReply: (e) ->
|
|||||||
div.addEventListener('mousedown', mousedown, true)
|
div.addEventListener('mousedown', mousedown, true)
|
||||||
qr.appendChild(div)
|
qr.appendChild(div)
|
||||||
|
|
||||||
a: tag('a')
|
minimizeB: make('a', {
|
||||||
a.textContent: '_'
|
textContent: '_'
|
||||||
a.className: 'pointer'
|
className: 'pointer'
|
||||||
a.title: 'minimize'
|
title: 'minimize'
|
||||||
a.addEventListener('click', minimize, true)
|
})
|
||||||
div.appendChild(a)
|
minimizeB.addEventListener('click', minimize, true)
|
||||||
|
div.appendChild(minimizeB)
|
||||||
div.appendChild(document.createTextNode(' '))
|
div.appendChild(document.createTextNode(' '))
|
||||||
a: tag('a')
|
closeB: make('a', {
|
||||||
a.textContent: 'X'
|
textContent: 'X'
|
||||||
a.className: 'pointer'
|
className: 'pointer'
|
||||||
a.title: 'close'
|
title: 'close'
|
||||||
a.addEventListener('click', close, true)
|
})
|
||||||
div.appendChild(a)
|
closeB.addEventListener('click', close, true)
|
||||||
|
div.appendChild(closeB)
|
||||||
|
|
||||||
clone: $('form[name="post"]').cloneNode(true)
|
clone: $('form[name="post"]').cloneNode(true)
|
||||||
clone.addEventListener('submit', submit, true)
|
clone.addEventListener('submit', submit, true)
|
||||||
@ -504,14 +514,14 @@ watch: ->
|
|||||||
|
|
||||||
|
|
||||||
watchX: ->
|
watchX: ->
|
||||||
[nop, board, nop, id]:
|
[board, nop, id]:
|
||||||
this.nextElementSibling.getAttribute('href').split('/')
|
this.nextElementSibling.getAttribute('href').substring(1).split('/')
|
||||||
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\"]")
|
||||||
img: input.previousSibling
|
favicon: input.previousSibling
|
||||||
img.src: favEmpty
|
favicon.src: favEmpty
|
||||||
|
|
||||||
|
|
||||||
watcherUpdate: ->
|
watcherUpdate: ->
|
||||||
@ -524,18 +534,19 @@ watcherUpdate: ->
|
|||||||
a.addEventListener('click', watchX, true)
|
a.addEventListener('click', watchX, true)
|
||||||
div.appendChild(a)
|
div.appendChild(a)
|
||||||
div.appendChild(document.createTextNode(' '))
|
div.appendChild(document.createTextNode(' '))
|
||||||
a: tag('a')
|
link: tag('a')
|
||||||
a.textContent: thread.text
|
link.textContent: thread.text
|
||||||
a.href: "/$board/res/${thread.id}"
|
link.href: "/$board/res/${thread.id}"
|
||||||
div.appendChild(a)
|
div.appendChild(link)
|
||||||
div.appendChild(tag('br'))
|
div.appendChild(tag('br'))
|
||||||
old: $('#watcher div:last-child')
|
old: $('#watcher div:last-child')
|
||||||
replace(old, div)
|
replace(old, div)
|
||||||
|
|
||||||
|
|
||||||
parseResponse: (responseText) ->
|
parseResponse: (responseText) ->
|
||||||
body: tag('body')
|
body: make('body', {
|
||||||
body.innerHTML: responseText
|
innerHTML: responseText
|
||||||
|
})
|
||||||
replies: $$('td.reply', body)
|
replies: $$('td.reply', body)
|
||||||
opbq: $('blockquote', body)
|
opbq: $('blockquote', body)
|
||||||
return [replies, opbq]
|
return [replies, opbq]
|
||||||
|
|||||||
77
4chan_x.js
77
4chan_x.js
@ -1,5 +1,5 @@
|
|||||||
(function(){
|
(function(){
|
||||||
var $, $$, BOARD, DAY, PAGENUM, REPLY, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, a, arr, as, autoWatch, b, board, callback, callbacks, clearHidden, close, config, cutoff, delform, down, el, expandComment, expandThread, favEmpty, favNormal, favicon, getTime, getValue, head, hiddenReplies, hiddenThreads, hide, hideReply, hideThread, html, i, i1, id, iframe, iframeLoad, iframeLoop, img, inAfter, inBefore, input, inputs, l, l1, lastChecked, magic, minimize, mousedown, mousemove, mouseup, move, nodeInserted, nop, now, omitted, onloadComment, onloadThread, options, optionsSave, parseResponse, position, quickReply, r, remove, replace, replyNav, report, show, showReply, showThread, slice, span, stopPropagation, submit, tag, text, thread, threadF, threads, up, watch, watchX, watched, watcher, watcherUpdate, x, xhrs;
|
var $, $$, BOARD, DAY, PAGENUM, REPLY, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, a, arr, as, autoWatch, b, board, callback, callbacks, clearHidden, close, config, cutoff, delform, down, el, expandComment, expandThread, favEmpty, favNormal, favicon, getTime, getValue, head, hiddenReplies, hiddenThreads, hide, hideReply, hideThread, html, i, i1, id, iframe, iframeLoad, iframeLoop, img, inAfter, inBefore, input, inputs, l, l1, lastChecked, magic, make, minimize, mousedown, mousemove, mouseup, move, nodeInserted, nop, now, omitted, onloadComment, onloadThread, options, optionsSave, parseResponse, position, quickReply, r, remove, replace, replyNav, report, show, showReply, showThread, slice, span, stopPropagation, submit, tag, text, thread, threadF, threads, up, watch, watchX, watched, watcher, watcherUpdate, x, xhrs;
|
||||||
var __hasProp = Object.prototype.hasOwnProperty;
|
var __hasProp = Object.prototype.hasOwnProperty;
|
||||||
//todo: remove close()?, make hiddenReplies/hiddenThreads local, comments, gc
|
//todo: remove close()?, make hiddenReplies/hiddenThreads local, comments, gc
|
||||||
//todo: remove stupid 'obj', arr el, make hidden an object, smarter xhr, text(), @this, images, clear hidden
|
//todo: remove stupid 'obj', arr el, make hidden an object, smarter xhr, text(), @this, images, clear hidden
|
||||||
@ -69,10 +69,22 @@
|
|||||||
getTime = function() {
|
getTime = function() {
|
||||||
return Math.floor(new Date().getTime() / 1000);
|
return Math.floor(new Date().getTime() / 1000);
|
||||||
};
|
};
|
||||||
|
make = function(tag, obj) {
|
||||||
|
var _a, el, key;
|
||||||
|
el = document.createElement(tag);
|
||||||
|
if (obj) {
|
||||||
|
_a = obj;
|
||||||
|
for (key in _a) { if (__hasProp.call(_a, key)) {
|
||||||
|
el[key] = obj[key];
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
return el;
|
||||||
|
};
|
||||||
slice = function(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.
|
||||||
|
// would it be better to just use objects and the `delete` keyword?
|
||||||
i = 0;
|
i = 0;
|
||||||
l = arr.length;
|
l = arr.length;
|
||||||
while ((i < l)) {
|
while ((i < l)) {
|
||||||
@ -95,6 +107,7 @@
|
|||||||
return el.style.bottom;
|
return el.style.bottom;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// x-browser
|
||||||
if (typeof GM_deleteValue === 'undefined') {
|
if (typeof GM_deleteValue === 'undefined') {
|
||||||
this.GM_setValue = function(name, value) {
|
this.GM_setValue = function(name, value) {
|
||||||
value = (typeof value)[0] + value;
|
value = (typeof value)[0] + value;
|
||||||
@ -155,7 +168,6 @@
|
|||||||
magic === 'res' ? (REPLY = magic) : (PAGENUM = parseInt(magic) || 0);
|
magic === 'res' ? (REPLY = magic) : (PAGENUM = parseInt(magic) || 0);
|
||||||
xhrs = [];
|
xhrs = [];
|
||||||
r = null;
|
r = null;
|
||||||
head = $('head', document);
|
|
||||||
iframeLoop = false;
|
iframeLoop = false;
|
||||||
move = {};
|
move = {};
|
||||||
callbacks = [];
|
callbacks = [];
|
||||||
@ -259,6 +271,7 @@ cursor: pointer; \
|
|||||||
};
|
};
|
||||||
options = function() {
|
options = function() {
|
||||||
var _c, checked, div, hiddenNum, option;
|
var _c, checked, div, hiddenNum, option;
|
||||||
|
//redo this
|
||||||
if ((div = $('#options'))) {
|
if ((div = $('#options'))) {
|
||||||
return remove(div);
|
return remove(div);
|
||||||
} else {
|
} else {
|
||||||
@ -480,7 +493,7 @@ cursor: pointer; \
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
quickReply = function(e) {
|
quickReply = function(e) {
|
||||||
var _c, a, clone, div, input, qr, selText, selection, textarea, xpath;
|
var _c, clone, closeB, div, input, minimizeB, qr, selText, selection, textarea, xpath;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!(qr = $('#qr'))) {
|
if (!(qr = $('#qr'))) {
|
||||||
qr = tag('div');
|
qr = tag('div');
|
||||||
@ -492,19 +505,21 @@ cursor: pointer; \
|
|||||||
div.className = 'move';
|
div.className = 'move';
|
||||||
div.addEventListener('mousedown', mousedown, true);
|
div.addEventListener('mousedown', mousedown, true);
|
||||||
qr.appendChild(div);
|
qr.appendChild(div);
|
||||||
a = tag('a');
|
minimizeB = make('a', {
|
||||||
a.textContent = '_';
|
textContent: '_',
|
||||||
a.className = 'pointer';
|
className: 'pointer',
|
||||||
a.title = 'minimize';
|
title: 'minimize'
|
||||||
a.addEventListener('click', minimize, true);
|
});
|
||||||
div.appendChild(a);
|
minimizeB.addEventListener('click', minimize, true);
|
||||||
|
div.appendChild(minimizeB);
|
||||||
div.appendChild(document.createTextNode(' '));
|
div.appendChild(document.createTextNode(' '));
|
||||||
a = tag('a');
|
closeB = make('a', {
|
||||||
a.textContent = 'X';
|
textContent: 'X',
|
||||||
a.className = 'pointer';
|
className: 'pointer',
|
||||||
a.title = 'close';
|
title: 'close'
|
||||||
a.addEventListener('click', close, true);
|
});
|
||||||
div.appendChild(a);
|
closeB.addEventListener('click', close, true);
|
||||||
|
div.appendChild(closeB);
|
||||||
clone = $('form[name="post"]').cloneNode(true);
|
clone = $('form[name="post"]').cloneNode(true);
|
||||||
clone.addEventListener('submit', submit, true);
|
clone.addEventListener('submit', submit, true);
|
||||||
clone.target = 'iframe';
|
clone.target = 'iframe';
|
||||||
@ -548,23 +563,22 @@ cursor: pointer; \
|
|||||||
return watcherUpdate();
|
return watcherUpdate();
|
||||||
};
|
};
|
||||||
watchX = function() {
|
watchX = function() {
|
||||||
var _c, img, input;
|
var _c, input;
|
||||||
_c = this.nextElementSibling.getAttribute('href').split('/');
|
_c = this.nextElementSibling.getAttribute('href').substring(1).split('/');
|
||||||
nop = _c[0];
|
board = _c[0];
|
||||||
board = _c[1];
|
nop = _c[1];
|
||||||
nop = _c[2];
|
id = _c[2];
|
||||||
id = _c[3];
|
|
||||||
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 + "\"]")))) {
|
||||||
img = input.previousSibling;
|
favicon = input.previousSibling;
|
||||||
img.src = favEmpty;
|
favicon.src = favEmpty;
|
||||||
return img.src;
|
return favicon.src;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
watcherUpdate = function() {
|
watcherUpdate = function() {
|
||||||
var _c, _d, _e, _f, a, div, old;
|
var _c, _d, _e, _f, a, div, link, old;
|
||||||
div = tag('div');
|
div = tag('div');
|
||||||
_c = watched;
|
_c = watched;
|
||||||
for (board in _c) { if (__hasProp.call(_c, board)) {
|
for (board in _c) { if (__hasProp.call(_c, board)) {
|
||||||
@ -577,10 +591,10 @@ cursor: pointer; \
|
|||||||
a.addEventListener('click', watchX, true);
|
a.addEventListener('click', watchX, true);
|
||||||
div.appendChild(a);
|
div.appendChild(a);
|
||||||
div.appendChild(document.createTextNode(' '));
|
div.appendChild(document.createTextNode(' '));
|
||||||
a = tag('a');
|
link = tag('a');
|
||||||
a.textContent = thread.text;
|
link.textContent = thread.text;
|
||||||
a.href = ("/" + board + "/res/" + (thread.id));
|
link.href = ("/" + board + "/res/" + (thread.id));
|
||||||
div.appendChild(a);
|
div.appendChild(link);
|
||||||
div.appendChild(tag('br'));
|
div.appendChild(tag('br'));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@ -589,8 +603,9 @@ cursor: pointer; \
|
|||||||
};
|
};
|
||||||
parseResponse = function(responseText) {
|
parseResponse = function(responseText) {
|
||||||
var body, opbq, replies;
|
var body, opbq, replies;
|
||||||
body = tag('body');
|
body = make('body', {
|
||||||
body.innerHTML = responseText;
|
innerHTML: responseText
|
||||||
|
});
|
||||||
replies = $$('td.reply', body);
|
replies = $$('td.reply', body);
|
||||||
opbq = $('blockquote', body);
|
opbq = $('blockquote', body);
|
||||||
return [replies, opbq];
|
return [replies, opbq];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user