From e43d6d4431ed2d6676c3473e8919adf52e855a57 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 11 Oct 2011 14:05:57 +0200 Subject: [PATCH 1/4] Report Button: simpler selector, use xpath to avoid problems next year with silly hats. --- 4chan_x.user.js | 4 ++-- script.coffee | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 51c9264be..d2f2a7bbf 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2598,7 +2598,7 @@ return g.callbacks.push(function(root) { var a, span; if (!(a = $('.reportbutton', root))) { - span = $('span[id^=no]', root); + span = $('span[id]', root); a = $.el('a', { className: 'reportbutton', innerHTML: '[ ! ]' @@ -2611,7 +2611,7 @@ }, report: function() { var id, set, url; - url = "http://sys.4chan.org/" + g.BOARD + "/imgboard.php?mode=report&no=" + this.previousElementSibling.childNodes[1].textContent; + url = "http://sys.4chan.org/" + g.BOARD + "/imgboard.php?mode=report&no=" + ($.x('preceding-sibling::input', this).name); id = "" + NAMESPACE + "popup"; set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200"; return window.open(url, id, set); diff --git a/script.coffee b/script.coffee index 8595c8a2a..8b325e807 100644 --- a/script.coffee +++ b/script.coffee @@ -1919,7 +1919,7 @@ reportButton = init: -> g.callbacks.push (root) -> if not a = $ '.reportbutton', root - span = $ 'span[id^=no]', root + span = $ 'span[id]', root a = $.el 'a', className: 'reportbutton' innerHTML: '[ ! ]' @@ -1927,7 +1927,7 @@ reportButton = $.after span, $.tn(' ') $.bind a, 'click', reportButton.report report: -> - url = "http://sys.4chan.org/#{g.BOARD}/imgboard.php?mode=report&no=#{@previousElementSibling.childNodes[1].textContent}" + url = "http://sys.4chan.org/#{g.BOARD}/imgboard.php?mode=report&no=#{$.x('preceding-sibling::input', @).name}" id = "#{NAMESPACE}popup" set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200" window.open url, id, set From 2e43059f3e6d2c928e5ba8d5dd0924bed9957a0c Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 11 Oct 2011 14:32:42 +0200 Subject: [PATCH 2/4] Time formatting boost. God damn, that was easy. --- 4chan_x.user.js | 8 ++------ script.coffee | 9 +-------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index d2f2a7bbf..b0f635309 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2203,16 +2203,12 @@ return g.callbacks.push(Time.node); }, node: function(root) { - var day, hour, min, month, node, posttime, time, year, _, _ref; + var node, posttime, time; if (root.className === 'inline') { return; } node = (posttime = $('.posttime', root)) ? posttime : $('span[id]', root).previousSibling; - _ref = node.textContent.match(/(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/), _ = _ref[0], month = _ref[1], day = _ref[2], year = _ref[3], hour = _ref[4], min = _ref[5]; - year = "20" + year; - month -= 1; - hour = g.chanOffset + Number(hour); - Time.date = new Date(year, month, day, hour, min); + Time.date = new Date(Date.parse(node.textContent) + g.chanOffset * HOUR); time = $.el('time', { textContent: ' ' + Time.funk(Time) + ' ' }); diff --git a/script.coffee b/script.coffee index 8b325e807..35154d53f 100644 --- a/script.coffee +++ b/script.coffee @@ -1669,14 +1669,7 @@ Time = node: (root) -> return if root.className is 'inline' node = if posttime = $('.posttime', root) then posttime else $('span[id]', root).previousSibling - [_, month, day, year, hour, min] = - node.textContent.match /(\d+)\/(\d+)\/(\d+)\(\w+\)(\d+):(\d+)/ - year = "20#{year}" - month -= 1 #months start at 0 - hour = g.chanOffset + Number hour - Time.date = new Date year, month, day, hour, min - #XXX /b/ will have seconds cut off - + Time.date = new Date Date.parse(node.textContent) + g.chanOffset*HOUR time = $.el 'time', textContent: ' ' + Time.funk(Time) + ' ' $.replace node, time From 0828f8ed3f7585ef709119e1bd056bf7acf9dddb Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 11 Oct 2011 15:15:28 +0200 Subject: [PATCH 3/4] Tiny improvements: use classList, simpler selectors, simpler xpath. --- 4chan_x.user.js | 10 +++++----- script.coffee | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index b0f635309..a37314a92 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2316,10 +2316,10 @@ quoteBacklink.funk = Function('id', "return'" + format + "'"); return g.callbacks.push(function(root) { var container, el, id, link, qid, quote, quotes, _i, _len, _ref, _results; - if (/inline/.test(root.className)) { + if (root.classList.contains('inline')) { return; } - id = root.id || $('td[id]', root).id; + id = $('input', root).name; quotes = {}; _ref = $$('.quotelink', root); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -2354,7 +2354,7 @@ container = $.el('span', { className: 'container' }); - root = $('.reportbutton', el) || $('span[id^=no]', el); + root = $('.reportbutton', el) || $('span[id]', el); $.after(root, container); } _results.push($.add(container, $.tn(' '), link)); @@ -2516,8 +2516,8 @@ if (conf['Quote Highlighting']) { $.addClass(el, 'qphl'); } - if (/backlink/.test(this.className)) { - replyID = $.x('ancestor::*[@id][1]', this).id.match(/\d+/)[0]; + if (this.classList.contains('backlink')) { + replyID = $.x('preceding::input', this).name; _ref = $$('.quotelink', qp); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { diff --git a/script.coffee b/script.coffee index 35154d53f..816dddc51 100644 --- a/script.coffee +++ b/script.coffee @@ -1739,9 +1739,9 @@ quoteBacklink = format = conf['backlink'].replace /%id/, "' + id + '" quoteBacklink.funk = Function 'id', "return'#{format}'" g.callbacks.push (root) -> - return if /inline/.test root.className + return if root.classList.contains 'inline' # op or reply - id = root.id or $('td[id]', root).id + id = $('input', root).name quotes = {} for quote in $$ '.quotelink', root #don't process >>>/b/ @@ -1764,7 +1764,7 @@ quoteBacklink = $.bind link, 'click', quoteInline.toggle unless (container = $ '.container', el) and container.parentNode is el container = $.el 'span', className: 'container' - root = $('.reportbutton', el) or $('span[id^=no]', el) + root = $('.reportbutton', el) or $('span[id]', el) $.after root, container $.add container, $.tn(' '), link @@ -1866,8 +1866,8 @@ quotePreview = if el = $.id id qp.innerHTML = el.innerHTML $.addClass el, 'qphl' if conf['Quote Highlighting'] - if /backlink/.test @className - replyID = $.x('ancestor::*[@id][1]', @).id.match(/\d+/)[0] + if @classList.contains 'backlink' + replyID = $.x('preceding::input', @).name for quote in $$ '.quotelink', qp if quote.hash[1..] is replyID quote.className = 'forwardlink' From 8570cd6eabbfdd49f7eb9b0d444d48607c586cdf Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 11 Oct 2011 15:45:10 +0200 Subject: [PATCH 4/4] We do not support the normal post form anymore. --- 4chan_x.user.js | 7 ------- script.coffee | 6 ------ 2 files changed, 13 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a37314a92..99de3d963 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2055,13 +2055,6 @@ $.before(input, favicon); } watcher.refresh(); - if (conf['Auto Watch']) { - if (!g.REPLY) { - $('.postarea form').action += '?watch'; - } else if (/watch/.test(location.search) && $('img.favicon').src === Favicon.empty) { - watcher.watch(null, g.THREAD_ID); - } - } return $.bind(window, 'storage', function(e) { if (e.key === ("" + NAMESPACE + "watched")) { return watcher.refresh(); diff --git a/script.coffee b/script.coffee index 816dddc51..e8348d65d 100644 --- a/script.coffee +++ b/script.coffee @@ -1564,12 +1564,6 @@ watcher = #populate watcher, display watch buttons watcher.refresh() - if conf['Auto Watch'] - unless g.REPLY - $('.postarea form').action += '?watch' - else if /watch/.test(location.search) and $('img.favicon').src is Favicon.empty - watcher.watch null, g.THREAD_ID - $.bind window, 'storage', (e) -> watcher.refresh() if e.key is "#{NAMESPACE}watched" refresh: ->