From b8abb2b16d4e19d6da7326c9984cb3434464574e Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 4 Sep 2011 22:39:56 -0700 Subject: [PATCH 1/3] rm $.show, $.hide --- 4chan_x.user.js | 30 ++++++++++++------------------ script.coffee | 28 ++++++++++++---------------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 6aef2d495..f72c95355 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -375,12 +375,6 @@ replace: function(root, el) { return root.parentNode.replaceChild(el, root); }, - hide: function(el) { - return el.hidden = true; - }, - show: function(el) { - return el.hidden = false; - }, addClass: function(el, className) { return el.classList.add(className); }, @@ -728,7 +722,7 @@ hide: function(reply) { var a, div, id, name, table, trip, _ref; table = reply.parentNode.parentNode.parentNode; - $.hide(table); + table.hidden = true; if (conf['Show Stubs']) { name = $('span.commentpostername', reply).textContent; trip = ((_ref = $('span.postertrip', reply)) != null ? _ref.textContent : void 0) || ''; @@ -748,7 +742,7 @@ }, show: function(table) { var id; - $.show(table); + table.hidden = false; id = $('td[id]', table).id; delete g.hiddenReplies[id]; return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); @@ -1658,16 +1652,16 @@ $.append(thread, div); return $.addClass(thread, 'stub'); } else { - $.hide(thread); - return $.hide(thread.nextSibling); + thread.hidden = true; + return thread.nextSibling.hidden = true; } }, show: function(thread) { var hiddenThreads, id; $.rm($('div.block', thread)); $.removeClass(thread, 'stub'); - $.show(thread); - $.show(thread.nextSibling); + thread.hidden = false; + thread.nextSibling.hidden = false; id = thread.firstChild.id; hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); delete hiddenThreads[id]; @@ -1735,13 +1729,13 @@ verbose: function() { if (conf['Verbose']) { updater.count.textContent = '+0'; - return $.show(updater.timer); + return updater.timer.hidden = false; } else { $.extend(updater.count, { className: '', textContent: 'Thread Updater' }); - return $.hide(updater.timer); + return updater.timer.hidden = true; } }, autoUpdate: function() { @@ -2208,7 +2202,7 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { inlined = _ref[_i]; if (hidden = $.id(inlined.name)) { - $.show($.x('ancestor::table[1]', hidden)); + $.x('ancestor::table[1]', hidden).hidden = true; } } return; @@ -2221,7 +2215,7 @@ return; } $.after(this.parentNode, inline); - $.hide($.x('ancestor::table[1]', el)); + $.x('ancestor::table[1]', el).hidden = true; } else { $.after(root, inline); } @@ -2713,12 +2707,12 @@ } }, contract: function(thumb) { - $.show(thumb); + thumb.hidden = false; return $.rm(thumb.nextSibling); }, expand: function(thumb) { var a, filesize, img, max, _, _ref2; - $.hide(thumb); + thumb.hidden = true; a = thumb.parentNode; img = $.el('img', { src: a.href diff --git a/script.coffee b/script.coffee index 30f8ba407..0707a5b80 100644 --- a/script.coffee +++ b/script.coffee @@ -254,10 +254,6 @@ $.extend $, d.createTextNode s replace: (root, el) -> root.parentNode.replaceChild el, root - hide: (el) -> - el.hidden = true - show: (el) -> - el.hidden = false addClass: (el, className) -> el.classList.add className removeClass: (el, className) -> @@ -517,7 +513,7 @@ replyHiding = hide: (reply) -> table = reply.parentNode.parentNode.parentNode - $.hide table + table.hidden = true if conf['Show Stubs'] name = $('span.commentpostername', reply).textContent @@ -536,7 +532,7 @@ replyHiding = $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies show: (table) -> - $.show table + table.hidden = false id = $('td[id]', table).id delete g.hiddenReplies[id] @@ -1354,14 +1350,14 @@ threadHiding = $.append thread, div $.addClass thread, 'stub' else - $.hide thread - $.hide thread.nextSibling + thread.hidden = true + thread.nextSibling.hidden = true show: (thread) -> $.rm $ 'div.block', thread $.removeClass thread, 'stub' - $.show thread - $.show thread.nextSibling + thread.hidden = false + thread.nextSibling.hidden = false id = thread.firstChild.id @@ -1418,12 +1414,12 @@ updater = verbose: -> if conf['Verbose'] updater.count.textContent = '+0' - $.show updater.timer + updater.timer.hidden = false else $.extend updater.count, className: '' textContent: 'Thread Updater' - $.hide updater.timer + updater.timer.hidden = true autoUpdate: -> if @checked updater.timeoutID = setTimeout updater.timeout, 1000 @@ -1741,7 +1737,7 @@ quoteInline = $.removeClass @, 'inlined' for inlined in $$ 'input', table if hidden = $.id inlined.name - $.show $.x 'ancestor::table[1]', hidden + $.x('ancestor::table[1]', hidden).hidden = false return root = if @parentNode.nodeName is 'FONT' then @parentNode else if @nextSibling then @nextSibling else @ if el = $.id id @@ -1749,7 +1745,7 @@ quoteInline = if @className is 'backlink' return if $("a.backlink[href='##{id}']", el) $.after @parentNode, inline - $.hide $.x 'ancestor::table[1]', el + $.x('ancestor::table[1]', el).hidden = true else $.after root, inline else @@ -2056,11 +2052,11 @@ imgExpand = imgExpand.expand thumb contract: (thumb) -> - $.show thumb + thumb.hidden = false $.rm thumb.nextSibling expand: (thumb) -> - $.hide thumb + thumb.hidden = true a = thumb.parentNode img = $.el 'img', src: a.href From ef086934f1fb0c33ad07b66b70050e78e3340d9b Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 4 Sep 2011 22:42:36 -0700 Subject: [PATCH 2/3] $.append -> $.add --- 4chan_x.user.js | 62 ++++++++++++++++++++++++------------------------- script.coffee | 60 +++++++++++++++++++++++------------------------ 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index f72c95355..40fd2c217 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -311,7 +311,7 @@ script = $.el('script', { textContent: "(" + code + ")()" }); - $.append(d.head, script); + $.add(d.head, script); return $.rm(script); }, xhr: function(url, cb) { @@ -360,7 +360,7 @@ style = $.el('style', { textContent: css }); - $.append(d.head, style); + $.add(d.head, style); return style; }, x: function(path, root) { @@ -384,7 +384,7 @@ rm: function(el) { return el.parentNode.removeChild(el); }, - append: function() { + add: function() { var child, children, parent, _i, _len, _results; parent = arguments[0], children = 2 <= arguments.length ? __slice.call(arguments, 1) : []; _results = []; @@ -733,7 +733,7 @@ div = $.el('div', { className: 'stub' }); - $.append(div, a); + $.add(div, a); $.before(table, div); } id = reply.id; @@ -994,8 +994,8 @@ }); $.bind(prev, 'click', nav.prev); $.bind(next, 'click', nav.next); - $.append(span, prev, $.tn(' '), next); - return $.append(d.body, span); + $.add(span, prev, $.tn(' '), next); + return $.add(d.body, span); }, prev: function() { return nav.scroll(-1); @@ -1096,15 +1096,15 @@ innerHTML: ": " + description + "" }); $.bind($('input', li), 'click', $.cb.checked); - $.append(ul, li); + $.add(ul, li); } - $.append(main, ul); + $.add(main, ul); } li = $.el('li', { innerHTML: " : Forget all hidden posts. Useful if you accidentally hide a post and have `show stubs` disabled." }); $.bind($('button', li), 'click', options.clearHidden); - $.append($('ul:nth-child(2)', dialog), li); + $.add($('ul:nth-child(2)', dialog), li); $.bind($('#flavors', dialog), 'change', $.cb.value); $.bind($('input[name=time]', dialog), 'keyup', options.time); $.bind($('input[name=backlink]', dialog), 'keyup', options.backlink); @@ -1123,8 +1123,8 @@ overlay = $.el('div', { id: 'overlay' }); - $.append(overlay, dialog); - $.append(d.body, overlay); + $.add(overlay, dialog); + $.add(d.body, overlay); options.time.call($('input[name=time]', dialog)); options.backlink.call($('input[name=backlink]', dialog)); $.bind(overlay, 'click', function() { @@ -1241,7 +1241,7 @@ name: 'iframe', hidden: true }); - $.append(d.body, iframe); + $.add(d.body, iframe); return $('#recaptcha_response_field').id = ''; }, attach: function() { @@ -1253,7 +1253,7 @@ $.bind(fileDiv.lastChild, 'click', (function() { return $.rm(this.parentNode); })); - return $.append($('#files', qr.el), fileDiv); + return $.add($('#files', qr.el), fileDiv); }, attachNext: function() { var file, fileDiv, oldFile; @@ -1324,7 +1324,7 @@ $.bind($('img', qr.el), 'click', Recaptcha.reload); $.bind($('#dummy', qr.el), 'keydown', Recaptcha.listener); $.bind($('#dummy', qr.el), 'keydown', qr.captchaKeydown); - return $.append(d.body, qr.el); + return $.add(d.body, qr.el); }, message: function(e) { var data, duration, fileCount; @@ -1557,10 +1557,10 @@ }); $.before(node, op); while (node.nodeName !== 'BLOCKQUOTE') { - $.append(op, node); + $.add(op, node); node = op.nextSibling; } - $.append(op, node); + $.add(op, node); op.id = $('input[name]', op).name; return op; }, @@ -1575,7 +1575,7 @@ }); $.before(node, div); while (node.nodeName !== 'HR') { - $.append(div, node); + $.add(div, node); node = div.nextSibling; } node = node.nextElementSibling; @@ -1648,8 +1648,8 @@ div = $.el('div', { className: 'block' }); - $.append(div, a); - $.append(thread, div); + $.add(div, a); + $.add(thread, div); return $.addClass(thread, 'stub'); } else { thread.hidden = true; @@ -1723,7 +1723,7 @@ $.bind(input, 'click', updater.updateNow); } } - return $.append(d.body, dialog); + return $.add(d.body, dialog); }, cb: { verbose: function() { @@ -1827,7 +1827,7 @@ top: '50px', left: '0px' }, html); - $.append(d.body, watcher.dialog); + $.add(d.body, watcher.dialog); inputs = $$('.op input'); for (_i = 0, _len = inputs.length; _i < _len; _i++) { input = inputs[_i]; @@ -1869,8 +1869,8 @@ }); $.bind(x, 'click', watcher.cb.x); link = $.el('a', props); - $.append(div, x, $.tn(' '), link); - $.append(watcher.dialog, div); + $.add(div, x, $.tn(' '), link); + $.add(watcher.dialog, div); } } watchedBoard = watched[g.BOARD] || {}; @@ -1980,7 +1980,7 @@ href: prefix + suffix, target: '_blank' }); - _results.push($.append(span, $.tn(' '), link)); + _results.push($.add(span, $.tn(' '), link)); } return _results; } @@ -2165,7 +2165,7 @@ root = $('.reportbutton', el) || $('span[id^=no]', el); $.after(root, container); } - _results.push($.append(container, $.tn(' '), link)); + _results.push($.add(container, $.tn(' '), link)); } return _results; }); @@ -2202,7 +2202,7 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { inlined = _ref[_i]; if (hidden = $.id(inlined.name)) { - $.x('ancestor::table[1]', hidden).hidden = true; + $.x('ancestor::table[1]', hidden).hidden = false; } } return; @@ -2305,7 +2305,7 @@ id: 'qp', className: 'replyhl' }); - $.append(d.body, qp); + $.add(d.body, qp); id = this.hash.slice(1); if (el = $.id(id)) { qp.innerHTML = el.innerHTML; @@ -2422,7 +2422,7 @@ dialog.className = 'dialog'; threadStats.postcountEl = $('#postcount', dialog); threadStats.imagecountEl = $('#imagecount', dialog); - $.append(d.body, dialog); + $.add(d.body, dialog); return g.callbacks.push(threadStats.node); }, node: function(root) { @@ -2601,7 +2601,7 @@ id: 'iHover', src: this.parentNode.href }); - return $.append(d.body, ui.el); + return $.add(d.body, ui.el); } }; imgPreloading = { @@ -2722,7 +2722,7 @@ _ref2 = filesize.textContent.match(/(\d+)x/), _ = _ref2[0], max = _ref2[1]; img.style.maxWidth = "-moz-calc(" + max + "px)"; } - return $.append(a, img); + return $.add(a, img); }, dialog: function() { var controls, delform, imageType, option, select, _i, _len, _ref2; @@ -2761,7 +2761,7 @@ className: 'firstrun', innerHTML: "

Click the 4chan X buttons for options; they are at the top and bottom of the page.

Updater options are in the updater dialog in replies at the bottom-right corner of the window.

If you don't see the buttons, try disabling your userstyles.

" }); - $.append(d.body, dialog); + $.add(d.body, dialog); return $.bind(window, 'click', firstRun.close); }, close: function() { diff --git a/script.coffee b/script.coffee index 0707a5b80..2a3b22831 100644 --- a/script.coffee +++ b/script.coffee @@ -217,7 +217,7 @@ $.extend $, globalEval: (code) -> script = $.el 'script', textContent: "(#{code})()" - $.append d.head, script + $.add d.head, script $.rm script xhr: (url, cb) -> r = new XMLHttpRequest() @@ -245,7 +245,7 @@ $.extend $, addStyle: (css) -> style = $.el 'style', textContent: css - $.append d.head, style + $.add d.head, style style x: (path, root=d.body) -> d.evaluate(path, root, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null). @@ -260,7 +260,7 @@ $.extend $, el.classList.remove className rm: (el) -> el.parentNode.removeChild el - append: (parent, children...) -> + add: (parent, children...) -> for child in children parent.appendChild child prepend: (parent, child) -> @@ -524,7 +524,7 @@ replyHiding = div = $.el 'div', className: 'stub' - $.append div, a + $.add div, a $.before table, div id = reply.id @@ -717,8 +717,8 @@ nav = $.bind prev, 'click', nav.prev $.bind next, 'click', nav.next - $.append span, prev, $.tn(' '), next - $.append d.body, span + $.add span, prev, $.tn(' '), next + $.add d.body, span prev: -> nav.scroll -1 @@ -870,13 +870,13 @@ options = li = $.el 'li', innerHTML: ": #{description}" $.bind $('input', li), 'click', $.cb.checked - $.append ul, li - $.append main, ul + $.add ul, li + $.add main, ul li = $.el 'li', innerHTML: " : Forget all hidden posts. Useful if you accidentally hide a post and have `show stubs` disabled." $.bind $('button', li), 'click', options.clearHidden - $.append $('ul:nth-child(2)', dialog), li + $.add $('ul:nth-child(2)', dialog), li $.bind $('#flavors', dialog), 'change', $.cb.value $.bind $('input[name=time]', dialog), 'keyup', options.time @@ -892,8 +892,8 @@ options = https://bugzilla.mozilla.org/show_bug.cgi?id=579776 ### overlay = $.el 'div', id: 'overlay' - $.append overlay, dialog - $.append d.body, overlay + $.add overlay, dialog + $.add d.body, overlay options.time.call $('input[name=time]', dialog) options.backlink.call $('input[name=backlink]', dialog) @@ -981,7 +981,7 @@ qr = iframe = $.el 'iframe', name: 'iframe' hidden: true - $.append d.body, iframe + $.add d.body, iframe #hack - nuke id so it doesn't grab focus when reloading $('#recaptcha_response_field').id = '' @@ -990,7 +990,7 @@ qr = fileDiv = $.el 'div', innerHTML: "X" $.bind fileDiv.firstChild, 'change', qr.validateFileSize $.bind fileDiv.lastChild, 'click', (-> $.rm @parentNode) - $.append $('#files', qr.el), fileDiv + $.add $('#files', qr.el), fileDiv attachNext: -> fileDiv = $.rm $('#files div', qr.el) @@ -1076,7 +1076,7 @@ qr = $.bind $('#dummy', qr.el), 'keydown', Recaptcha.listener $.bind $('#dummy', qr.el), 'keydown', qr.captchaKeydown - $.append d.body, qr.el + $.add d.body, qr.el message: (e) -> $('iframe[name=iframe]').src = 'about:blank' @@ -1268,9 +1268,9 @@ threading = className: 'op' $.before node, op while node.nodeName isnt 'BLOCKQUOTE' - $.append op, node + $.add op, node node = op.nextSibling - $.append op, node #add the blockquote + $.add op, node #add the blockquote op.id = $('input[name]', op).name op @@ -1284,7 +1284,7 @@ threading = $.before node, div while node.nodeName isnt 'HR' - $.append div, node + $.add div, node node = div.nextSibling node = node.nextElementSibling #skip text node @@ -1346,8 +1346,8 @@ threadHiding = div = $.el 'div', className: 'block' - $.append div, a - $.append thread, div + $.add div, a + $.add thread, div $.addClass thread, 'stub' else thread.hidden = true @@ -1408,7 +1408,7 @@ updater = else if input.type is 'button' $.bind input, 'click', updater.updateNow - $.append d.body, dialog + $.add d.body, dialog cb: verbose: -> @@ -1495,7 +1495,7 @@ watcher = init: -> html = '
Thread Watcher
' watcher.dialog = ui.dialog 'watcher', top: '50px', left: '0px', html - $.append d.body, watcher.dialog + $.add d.body, watcher.dialog #add watch buttons inputs = $$ '.op input' @@ -1528,8 +1528,8 @@ watcher = $.bind x, 'click', watcher.cb.x link = $.el 'a', props - $.append div, x, $.tn(' '), link - $.append watcher.dialog, div + $.add div, x, $.tn(' '), link + $.add watcher.dialog, div watchedBoard = watched[g.BOARD] or {} for favicon in $$ 'img.favicon' @@ -1596,7 +1596,7 @@ sauce = textContent: sauce.names[i] href: prefix + suffix target: '_blank' - $.append span, $.tn(' '), link + $.add span, $.tn(' '), link revealSpoilers = init: -> @@ -1718,7 +1718,7 @@ quoteBacklink = container = $.el 'span', className: 'container' root = $('.reportbutton', el) or $('span[id^=no]', el) $.after root, container - $.append container, $.tn(' '), link + $.add container, $.tn(' '), link quoteInline = init: -> @@ -1802,7 +1802,7 @@ quotePreview = qp = ui.el = $.el 'div', id: 'qp' className: 'replyhl' - $.append d.body, qp + $.add d.body, qp id = @hash[1..] if el = $.id id @@ -1876,7 +1876,7 @@ threadStats = dialog.className = 'dialog' threadStats.postcountEl = $ '#postcount', dialog threadStats.imagecountEl = $ '#imagecount', dialog - $.append d.body, dialog + $.add d.body, dialog g.callbacks.push threadStats.node node: (root) -> return if root.className @@ -1986,7 +1986,7 @@ imgHover = ui.el = $.el 'img' id: 'iHover' src: @parentNode.href - $.append d.body, ui.el + $.add d.body, ui.el imgPreloading = init: -> @@ -2064,7 +2064,7 @@ imgExpand = filesize = $ 'span.filesize', a.parentNode [_, max] = filesize.textContent.match /(\d+)x/ img.style.maxWidth = "-moz-calc(#{max}px)" - $.append a, img + $.add a, img dialog: -> controls = $.el 'div', @@ -2159,7 +2159,7 @@ firstRun =

If you don't see the buttons, try disabling your userstyles.

" - $.append d.body, dialog + $.add d.body, dialog $.bind window, 'click', firstRun.close From 8fcb23d7b2a9140d3b83e17bec9c897777c943ba Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 4 Sep 2011 22:49:45 -0700 Subject: [PATCH 3/3] $.xhr -> $.ajax --- 4chan_x.user.js | 11 +++++++---- script.coffee | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 40fd2c217..a3f99e9ee 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -314,11 +314,14 @@ $.add(d.head, script); return $.rm(script); }, - xhr: function(url, cb) { + ajax: function(url, cb, type) { var r; + if (type == null) { + type = 'get'; + } r = new XMLHttpRequest(); r.onload = cb; - r.open('get', url, true); + r.open(type, url, true); r.send(); return r; }, @@ -331,7 +334,7 @@ return req.callbacks.push(cb); } } else { - req = $.xhr(url, (function() { + req = $.ajax(url, (function() { var cb, _i, _len, _ref, _results; _ref = this.callbacks; _results = []; @@ -1816,7 +1819,7 @@ } url = location.pathname + '?' + Date.now(); cb = updater.cb.update; - return updater.request = $.xhr(url, cb); + return updater.request = $.ajax(url, cb); } }; watcher = { diff --git a/script.coffee b/script.coffee index 2a3b22831..28a836d9c 100644 --- a/script.coffee +++ b/script.coffee @@ -219,10 +219,10 @@ $.extend $, textContent: "(#{code})()" $.add d.head, script $.rm script - xhr: (url, cb) -> + ajax: (url, cb, type='get') -> r = new XMLHttpRequest() r.onload = cb - r.open 'get', url, true + r.open type, url, true r.send() r cache: (url, cb) -> @@ -232,7 +232,7 @@ $.extend $, else req.callbacks.push cb else - req = $.xhr url, (-> cb.call @ for cb in @callbacks) + req = $.ajax url, (-> cb.call @ for cb in @callbacks) req.callbacks = [cb] $.cache.requests[url] = req cb: @@ -1489,7 +1489,7 @@ updater = updater.request?.abort() url = location.pathname + '?' + Date.now() # fool the cache cb = updater.cb.update - updater.request = $.xhr url, cb + updater.request = $.ajax url, cb watcher = init: ->