diff --git a/4chan_x.coffee b/4chan_x.coffee index d3cb19dfd..94156d8b8 100644 --- a/4chan_x.coffee +++ b/4chan_x.coffee @@ -138,11 +138,10 @@ $ = (selector, root=d.body) -> root.querySelector selector $$ = (selector, root=d.body) -> result = root.querySelectorAll selector - #magic that turns the results object into an array: node for node in result -addTo = (parent, children...) -> - for child in children - parent.appendChild child +mv = (args...) -> + parent = args.pop() + (parent.appendChild child) for child in args getConfig = (name) -> GM_getValue name, config[name][0] getTime = -> @@ -297,7 +296,7 @@ formSubmit = (e) -> span = n 'span', className: 'error' textContent: 'You forgot to type in the verification.' - addTo @parentNode, span + mv span, @parentNode alert 'You forgot to type in the verification.' recaptcha.focus() @@ -319,7 +318,7 @@ hideReply = (reply) -> className: 'pointer' listener: ['click', showReply] div = n 'div' - addTo div, a + mv a, div inBefore table, div hideThread = (div) -> @@ -355,7 +354,7 @@ iframeLoad = -> span = n 'span', textContent: error className: 'error' - addTo qr, span + mv span, qr $('input[title=autohide]:checked', qr)?.click() else if g.REPLY and getConfig 'Persistent QR' $('textarea', qr).value = '' @@ -571,7 +570,7 @@ onloadThread = (responseText, span) -> else#threading div = span.parentNode for reply in replies - addTo div, x 'ancestor::table', reply + mv x('ancestor::table', reply), div changeCheckbox = -> GM_setValue @name, @checked @@ -601,7 +600,7 @@ options = -> $('a.sauce', div).addEventListener 'click', editSauce, true $('textarea', div).addEventListener 'change', changeText, true $('input[type="button"]', div).addEventListener 'click', clearHidden, true - addTo d.body, div + mv div, d.body parseResponse = (responseText) -> body = n 'body', @@ -649,17 +648,17 @@ quickReply = (link, text) -> type: 'hidden' name: 'resto' value: x(xpath, link).name - addTo clone, input + mv input, clone else if getConfig 'Persistent QR' submit = $ 'input[type=submit]', clone auto = n 'label', textContent: 'Auto' autoBox = n 'input', type: 'checkbox' - addTo auto, autoBox + mv autoBox, auto inBefore submit, auto - addTo qr, clone - addTo d.body, qr + mv clone, qr + mv qr, d.body $('input[title=autohide]:checked', qr)?.click() textarea = $('textarea', qr) @@ -743,12 +742,12 @@ threadF = (current) -> textContent: '[ - ]' className: 'pointer' listener: ['click', hideThread] - addTo div, a + mv a, div inBefore current, div while (!current.clear)#
- addTo div, current + mv current, div current = div.nextSibling - addTo div, current + mv current, div current = div.nextSibling id = $('input[value="delete"]', div).name div.id = id @@ -909,7 +908,7 @@ watcherUpdate = -> link = n 'a', textContent: thread.text href: "/#{board}/res/#{thread.id}" - addTo div, a, tn(' '), link, n('br') + mv a, tn(' '), link, n('br'), div old = $('#watcher div:last-child') replace(old, div) @@ -1164,7 +1163,7 @@ if getConfig 'Sauce' link = n 'a', textContent: names[i] href: prefixes[i] + suffix - addTo span, tn(' '), link + mv tn(' '), link, span i++ if getConfig 'Reply Hiding' @@ -1188,7 +1187,7 @@ if getConfig 'Quick Reply' name: 'iframe' listener: ['load', iframeLoad] hide(iframe) - addTo d.body, iframe + mv iframe, d.body g.callbacks.push (root) -> quotes = $$('a.quotejs:not(:first-child)', root) @@ -1214,7 +1213,7 @@ if getConfig 'Thread Watcher' #create watcher html = '
Thread Watcher
' watcher = new Dialog('watcher', 'topleft', html).el - addTo d.body, watcher + mv watcher, d.body watcherUpdate() #add buttons @@ -1260,7 +1259,7 @@ if getConfig 'Reply Navigation' textContent: '▼' className: 'pointer' listener: ['click', replyNav] - addTo span, tn(' '), up, tn(' '), down + mv tn(' '), up, tn(' '), down, span inAfter el, span if getConfig 'Keybinds' @@ -1329,7 +1328,7 @@ else #not reply className: 'pointer' textContent: textContent href: href - addTo span, up, tn(' '), down + mv up, tn(' '), down, span inBefore el, span if location.hash is '#p0' window.location = window.location diff --git a/4chan_x.js b/4chan_x.js index 5fbb6cf29..893c0fc57 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1,5 +1,5 @@ (function() { - var $, $$, DAY, Dialog, a, addTo, arr, as, autoWatch, autohide, b, board, callback, changeCheckbox, changeText, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expand, expandComment, expandThread, formSubmit, g, getConfig, getThread, getTime, hide, hideReply, hideThread, href, html, i, id, iframe, iframeLoad, imageClick, imageExpandClick, imageFull, imageThumb, imageToggle, img, inAfter, inBefore, input, inputs, keyModeInsert, keyModeNormal, keydown, keypress, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, parseResponse, pathname, qrListener, qrText, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, replace, replyNav, report, request, rm, scroll, scrollThread, show, showReply, showThread, slice, span, src, start, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, tzOffset, up, updateAuto, updateCallback, updateFavicon, updateInterval, updateNow, updateTime, updateTitle, updaterMake, watch, watchX, watcher, watcherUpdate, x, zeroPad, _, _base, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4, _ref5; + var $, $$, DAY, Dialog, a, arr, as, autoWatch, autohide, b, board, callback, changeCheckbox, changeText, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expand, expandComment, expandThread, formSubmit, g, getConfig, getThread, getTime, hide, hideReply, hideThread, href, html, i, id, iframe, iframeLoad, imageClick, imageExpandClick, imageFull, imageThumb, imageToggle, img, inAfter, inBefore, input, inputs, keyModeInsert, keyModeNormal, keydown, keypress, l1, lastChecked, m, mv, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, parseResponse, pathname, qrListener, qrText, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, replace, replyNav, report, request, rm, scroll, scrollThread, show, showReply, showThread, slice, span, src, start, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, tzOffset, up, updateAuto, updateCallback, updateFavicon, updateInterval, updateNow, updateTime, updateTitle, updaterMake, watch, watchX, watcher, watcherUpdate, x, zeroPad, _, _base, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4, _ref5; var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = Array.prototype.slice; config = { '404 Redirect': [true, 'Redirect dead threads'], @@ -182,12 +182,13 @@ } return _results; }; - addTo = function() { - var child, children, parent, _i, _len, _results; - parent = arguments[0], children = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + mv = function() { + var args, child, parent, _i, _len, _results; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + parent = args.pop(); _results = []; - for (_i = 0, _len = children.length; _i < _len; _i++) { - child = children[_i]; + for (_i = 0, _len = args.length; _i < _len; _i++) { + child = args[_i]; _results.push(parent.appendChild(child)); } return _results; @@ -394,7 +395,7 @@ className: 'error', textContent: 'You forgot to type in the verification.' }); - addTo(this.parentNode, span); + mv(span, this.parentNode); alert('You forgot to type in the verification.'); return recaptcha.focus(); } @@ -420,7 +421,7 @@ listener: ['click', showReply] }); div = n('div'); - addTo(div, a); + mv(a, div); return inBefore(table, div); } }; @@ -465,7 +466,7 @@ textContent: error, className: 'error' }); - addTo(qr, span); + mv(span, qr); if ((_ref = $('input[title=autohide]:checked', qr)) != null) { _ref.click(); } @@ -748,7 +749,7 @@ _results2 = []; for (_j = 0, _len2 = replies.length; _j < _len2; _j++) { reply = replies[_j]; - _results2.push(addTo(div, x('ancestor::table', reply))); + _results2.push(mv(x('ancestor::table', reply), div)); } return _results2; } @@ -785,7 +786,7 @@ $('a.sauce', div).addEventListener('click', editSauce, true); $('textarea', div).addEventListener('change', changeText, true); $('input[type="button"]', div).addEventListener('click', clearHidden, true); - return addTo(d.body, div); + return mv(div, d.body); }; parseResponse = function(responseText) { var body, opbq, replies; @@ -839,7 +840,7 @@ name: 'resto', value: x(xpath, link).name }); - addTo(clone, input); + mv(input, clone); } else if (getConfig('Persistent QR')) { submit = $('input[type=submit]', clone); auto = n('label', { @@ -848,11 +849,11 @@ autoBox = n('input', { type: 'checkbox' }); - addTo(auto, autoBox); + mv(autoBox, auto); inBefore(submit, auto); } - addTo(qr, clone); - addTo(d.body, qr); + mv(clone, qr); + mv(qr, d.body); } if ((_ref2 = $('input[title=autohide]:checked', qr)) != null) { _ref2.click(); @@ -964,13 +965,13 @@ className: 'pointer', listener: ['click', hideThread] }); - addTo(div, a); + mv(a, div); inBefore(current, div); while (!current.clear) { - addTo(div, current); + mv(current, div); current = div.nextSibling; } - addTo(div, current); + mv(current, div); current = div.nextSibling; id = $('input[value="delete"]', div).name; div.id = id; @@ -1162,7 +1163,7 @@ textContent: thread.text, href: "/" + board + "/res/" + thread.id }); - addTo(div, a, tn(' '), link, n('br')); + mv(a, tn(' '), link, n('br'), div); } } old = $('#watcher div:last-child'); @@ -1454,7 +1455,7 @@ textContent: names[i], href: prefixes[i] + suffix }); - addTo(span, tn(' '), link); + mv(tn(' '), link, span); _results.push(i++); } return _results; @@ -1498,7 +1499,7 @@ listener: ['load', iframeLoad] }); hide(iframe); - addTo(d.body, iframe); + mv(iframe, d.body); g.callbacks.push(function(root) { var quote, quotes, _i, _len, _results; quotes = $$('a.quotejs:not(:first-child)', root); @@ -1532,7 +1533,7 @@ if (getConfig('Thread Watcher')) { html = '
Thread Watcher
'; watcher = new Dialog('watcher', 'topleft', html).el; - addTo(d.body, watcher); + mv(watcher, d.body); watcherUpdate(); threads = g.watched[g.BOARD] || []; inputs = $$('form > input[value="delete"], div > input[value="delete"]'); @@ -1592,7 +1593,7 @@ className: 'pointer', listener: ['click', replyNav] }); - addTo(span, tn(' '), up, tn(' '), down); + mv(tn(' '), up, tn(' '), down, span); _results.push(inAfter(el, span)); } return _results; @@ -1677,7 +1678,7 @@ textContent: textContent, href: href }); - addTo(span, up, tn(' '), down); + mv(up, tn(' '), down, span); inBefore(el, span); } if (location.hash === '#p0') {