From 43530b0302ce8181f9173721109955c26bd2287c Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 24 Feb 2013 16:40:01 +0100 Subject: [PATCH] Don't open the QR in closed threads. Ideally I'd make the QR independant of the DOM but it's impossible without captcha and known board configs. --- 4chan_x.user.js | 28 +++++++++++++++++++--------- src/features.coffee | 2 +- src/qr.coffee | 16 ++++++++++++---- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 7f1647b66..da2b3568f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2832,7 +2832,7 @@ return key; }, qr: function(thread, quote) { - if (!Conf['Quick Reply']) { + if (!(Conf['Quick Reply'] && QR.postingIsEnable)) { return; } QR.open(); @@ -5641,7 +5641,6 @@ QR = { init: function() { - var link; if (g.VIEW === 'catalog' || !Conf['Quick Reply']) { return; } @@ -5650,6 +5649,18 @@ if (Conf['Hide Original Post Form']) { $.addClass(doc, 'hide-original-post-form'); } + $.on(d, '4chanXInitFinished', this.initReady); + return Post.prototype.callbacks.push({ + name: 'Quick Reply', + cb: this.node + }); + }, + initReady: function() { + var link; + QR.postingIsEnable = !!$.id('postForm'); + if (!QR.postingIsEnable) { + return; + } link = $.el('a', { className: 'qr-shortcut', textContent: 'Quick Reply', @@ -5669,9 +5680,6 @@ $.on(d, 'dragover', QR.dragOver); $.on(d, 'drop', QR.dropFile); $.on(d, 'dragstart dragend', QR.drag); - if (Conf['Persistent QR']) { - $.on(d, '4chanXInitFinished', QR.persist); - } $.on(d, 'ThreadUpdate', function() { if (g.DEAD) { return QR.abort(); @@ -5679,10 +5687,9 @@ return QR.status(); } }); - return Post.prototype.callbacks.push({ - name: 'Quick Reply', - cb: this.node - }); + if (Conf['Persistent QR']) { + return QR.persist(); + } }, node: function() { return $.on($('a[title="Quote this post"]', this.nodes.info), 'click', QR.quote); @@ -5922,6 +5929,9 @@ if (e != null) { e.preventDefault(); } + if (!QR.postingIsEnable) { + return; + } text = ""; sel = d.getSelection(); selectionRoot = $.x('ancestor::div[contains(@class,"postContainer")][1]', sel.anchorNode); diff --git a/src/features.coffee b/src/features.coffee index 167f17602..558bd0b4d 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -1554,7 +1554,7 @@ Keybinds = key qr: (thread, quote) -> - return unless Conf['Quick Reply'] + return unless Conf['Quick Reply'] and QR.postingIsEnable QR.open() if quote QR.quote.call $ 'input', $('.post.highlight', thread) or thread diff --git a/src/qr.coffee b/src/qr.coffee index ca10ac12e..505899b76 100644 --- a/src/qr.coffee +++ b/src/qr.coffee @@ -8,6 +8,16 @@ QR = if Conf['Hide Original Post Form'] $.addClass doc, 'hide-original-post-form' + $.on d, '4chanXInitFinished', @initReady + + Post::callbacks.push + name: 'Quick Reply' + cb: @node + + initReady: -> + QR.postingIsEnable = !!$.id 'postForm' + return unless QR.postingIsEnable + link = $.el 'a', className: 'qr-shortcut' textContent: 'Quick Reply' @@ -25,16 +35,13 @@ QR = $.on d, 'dragover', QR.dragOver $.on d, 'drop', QR.dropFile $.on d, 'dragstart dragend', QR.drag - $.on d, '4chanXInitFinished', QR.persist if Conf['Persistent QR'] $.on d, 'ThreadUpdate', -> if g.DEAD QR.abort() else QR.status() - Post::callbacks.push - name: 'Quick Reply' - cb: @node + QR.persist() if Conf['Persistent QR'] node: -> $.on $('a[title="Quote this post"]', @nodes.info), 'click', QR.quote @@ -229,6 +236,7 @@ QR = quote: (e) -> e?.preventDefault() + return unless QR.postingIsEnable text = "" sel = d.getSelection()