From 2292ac2815638d0eaeb9ec03618f4df0dbad9168 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 15 Feb 2012 13:56:01 +0100 Subject: [PATCH] Add option to fix XXX'd post numbers. --- 4chan_x.user.js | 23 +++++++++++++++++++++-- changelog | 1 + script.coffee | 21 ++++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index c22a1920e..017680e90 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -71,13 +71,14 @@ */ (function() { - var $, $$, DAY, Favicon, HOUR, MINUTE, Main, NAMESPACE, SECOND, Time, VERSION, anonymize, conf, config, d, engine, expandComment, expandThread, filter, flatten, g, getTitle, imgExpand, imgGif, imgHover, key, keybinds, log, nav, options, qr, quoteBacklink, quoteDR, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, strikethroughQuotes, threadHiding, threadStats, threading, titlePost, ui, unread, updater, val, watcher, _base, + var $, $$, DAY, Favicon, HOUR, MINUTE, Main, NAMESPACE, SECOND, Time, VERSION, anonymize, conf, config, d, engine, expandComment, expandThread, filter, flatten, g, getTitle, imgExpand, imgGif, imgHover, key, keybinds, log, nav, options, qr, quoteBacklink, quoteDR, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, strikethroughQuotes, threadHiding, threadStats, threading, titlePost, ui, unread, unxify, updater, val, watcher, _base, __slice = Array.prototype.slice; config = { main: { Enhancing: { '404 Redirect': [true, 'Redirect dead threads and images'], + 'Fix XXX\'d Post Numbers': [true, 'Replace XXX\'d post numbers with their actual number'], 'Keybinds': [true, 'Binds actions to keys'], 'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'], 'Report Button': [true, 'Add report buttons'], @@ -1189,6 +1190,23 @@ } }; + unxify = { + init: function() { + return g.callbacks.push(this.node); + }, + node: function(root) { + var quote; + if (unxify.censor === false) return; + if (unxify.censor === void 0) { + unxify.censor = /\D/.test($('.quotejs + .quotejs', root).textContent); + unxify.node(root); + return; + } + quote = $('.quotejs + .quotejs', root); + return quote.textContent = quote.previousElementSibling.hash.slice(1); + } + }; + qr = { init: function() { var form, iframe, link, loadChecking; @@ -1348,7 +1366,7 @@ if (!g.REPLY) { $('select', qr.el).value = $.x('ancestor::div[@class="thread"]/div', this).id; } - id = this.hash.slice(2); + id = this.previousElementSibling.hash.slice(1); text = ">>" + id + "\n"; sel = window.getSelection(); if ((s = sel.toString()) && id === ((_ref = $.x('ancestor-or-self::blockquote/preceding-sibling::input', sel.anchorNode)) != null ? _ref.name : void 0)) { @@ -3562,6 +3580,7 @@ if (conf['Quote Backlinks']) quoteBacklink.init(); if (conf['Indicate OP quote']) quoteOP.init(); if (conf['Indicate Cross-thread Quotes']) quoteDR.init(); + if (conf['Fix XXX\'d Post Numbers']) unxify.init(); if (conf['Quick Reply'] && conf['Hide Original Post Form']) { Main.css += 'form[name=post] { display: none; }'; } diff --git a/changelog b/changelog index c06bd42ad..c166b8cd3 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ master - Mayhem + New option to fix XXX'd post numbers. Fix post number quoting on /b/ and /v/. Update archive redirection for /v/. diff --git a/script.coffee b/script.coffee index 0ef7eb769..5a6179787 100644 --- a/script.coffee +++ b/script.coffee @@ -2,6 +2,7 @@ config = main: Enhancing: '404 Redirect': [true, 'Redirect dead threads and images'] + 'Fix XXX\'d Post Numbers': [true, 'Replace XXX\'d post numbers with their actual number'] 'Keybinds': [true, 'Binds actions to keys'] 'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'] 'Report Button': [true, 'Add report buttons'] @@ -868,6 +869,21 @@ nav = {top} = nav.threads[i]?.getBoundingClientRect() window.scrollBy 0, top +unxify = + init: -> + g.callbacks.push @node + node: (root) -> + if unxify.censor is false + # Don't execute on safe boards + return + if unxify.censor is undefined + # Test if the board's censored + unxify.censor = /\D/.test $('.quotejs + .quotejs', root).textContent + unxify.node root + return + quote = $ '.quotejs + .quotejs', root + quote.textContent = quote.previousElementSibling.hash[1..] + qr = init: -> return unless $.id 'recaptcha_challenge_field_holder' @@ -997,7 +1013,7 @@ qr = $('select', qr.el).value = $.x('ancestor::div[@class="thread"]/div', @).id # Make sure we get the correct number, even with XXX censors - id = @hash[2..] + id = @previousElementSibling.hash[1..] text = ">>#{id}\n" sel = window.getSelection() @@ -2810,6 +2826,9 @@ Main = if conf['Indicate Cross-thread Quotes'] quoteDR.init() + if conf['Fix XXX\'d Post Numbers'] + unxify.init() + if conf['Quick Reply'] and conf['Hide Original Post Form'] Main.css += 'form[name=post] { display: none; }'