From c5ea31dd2b3c92798f1ccb6e9672ce50a9e255d7 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 24 Feb 2012 18:35:06 +0100 Subject: [PATCH 1/6] rm toString --- 4chan_x.user.js | 2 +- script.coffee | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 35c743969..8add77b3c 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2995,7 +2995,7 @@ size /= 1024; } } - if (size < 1 && size.toString().length > size.toFixed(2).toString.length) { + if (size < 1 && size.toString().length > size.toFixed(2).length) { size = size.toFixed(2); } } diff --git a/script.coffee b/script.coffee index 6342704d5..154e05661 100644 --- a/script.coffee +++ b/script.coffee @@ -2401,7 +2401,7 @@ Time = p: -> if Time.date.getHours() < 12 then 'AM' else 'PM' P: -> if Time.date.getHours() < 12 then 'am' else 'pm' y: -> Time.date.getFullYear() - 2000 - + FileInfo = init: -> return if g.BOARD is 'f' @@ -2444,13 +2444,13 @@ FileInfo = size *= 1024 while i-- > 0 else if i < 0 size /= 1024 while i++ < 0 - if size < 1 and size.toString().length > size.toFixed(2).toString.length + if size < 1 and size.toString().length > size.toFixed(2).length size = size.toFixed 2 "#{size} #{unitT}" formatters: B: -> FileInfo.convertUnit 'B' K: -> FileInfo.convertUnit 'KB' - l: -> if FileInfo.ffType is 0 + l: -> if FileInfo.ffType is 0 FileInfo.data.link.replace />\d+\.\w+' + FileInfo.formatters.n() + '<' else FileInfo.data.link @@ -3068,7 +3068,7 @@ Main = if conf['Time Formatting'] Time.init() - + if conf['File Info Formatting'] FileInfo.init() From 674e8ab41bf80db675872d16112d69ee4d0ab420 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 27 Feb 2012 01:52:38 +0100 Subject: [PATCH 2/6] Fix cross-thread quotes indicators after an OP quote. Derp. --- 4chan_x.user.js | 6 +++--- script.coffee | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 8add77b3c..e13553e39 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3320,13 +3320,13 @@ _ref = $$('.quotelink', root); for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - hash = quote.hash.slice(1); + if (!(hash = quote.hash.slice(1))) continue; if (conf['Indicate OP quote'] && hash === tid) { $.add(quote, $.tn('\u00A0(OP)')); - return; + continue; } path = quote.pathname; - if (conf['Indicate Cross-thread Quotes'] && hash && path.lastIndexOf("/" + tid) === -1 && path.indexOf("/" + g.BOARD + "/") === 0) { + if (conf['Indicate Cross-thread Quotes'] && path.lastIndexOf("/" + tid) === -1 && path.indexOf("/" + g.BOARD + "/") === 0) { $.add(quote, $.tn('\u00A0(Cross-thread)')); } } diff --git a/script.coffee b/script.coffee index 154e05661..6c258a4f1 100644 --- a/script.coffee +++ b/script.coffee @@ -2674,14 +2674,15 @@ quoteIndicators = # We use contains() so that it works with hidden threads tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]', root).firstChild.id for quote in $$ '.quotelink', root - hash = quote.hash[1..] + unless hash = quote.hash[1..] + continue if conf['Indicate OP quote'] and hash is tid # \u00A0 is nbsp $.add quote, $.tn '\u00A0(OP)' - return + continue path = quote.pathname #if quote leads to a different thread id and is located on the same board (index 0) - if conf['Indicate Cross-thread Quotes'] and hash and path.lastIndexOf("/#{tid}") is -1 and path.indexOf("/#{g.BOARD}/") is 0 + if conf['Indicate Cross-thread Quotes'] and path.lastIndexOf("/#{tid}") is -1 and path.indexOf("/#{g.BOARD}/") is 0 # \u00A0 is nbsp $.add quote, $.tn '\u00A0(Cross-thread)' return From 28dfa2b17cbaf28a9593c6ac4b83da4db6d9be56 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 27 Feb 2012 02:05:23 +0100 Subject: [PATCH 3/6] Get rid of the extra `test` function in the filter. --- 4chan_x.user.js | 21 ++++++++------------- script.coffee | 20 +++++++------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index e13553e39..7b73fbb9f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -602,25 +602,20 @@ }; }, node: function(root) { - var isOP, key, klass; + var Filter, isOP, key, klass, value, _i, _len, _ref; klass = root.className; if (/\binlined\b/.test(klass)) return; if (!(isOP = klass === 'op')) root = $('td[id]', root); for (key in filter.filters) { - if (filter.test(root, key, isOP)) return; + value = filter[key](root, isOP); + if (value === false) continue; + _ref = filter.filters[key]; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + Filter = _ref[_i]; + if (Filter(root, value, isOP)) return; + } } }, - test: function(root, key, isOP) { - var filter, value, _i, _len, _ref; - value = this[key](root, isOP); - if (value === false) return false; - _ref = this.filters[key]; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - filter = _ref[_i]; - if (filter(root, value, isOP)) return true; - } - return false; - }, name: function(root, isOP) { var name; name = isOP ? $('.postername', root) : $('.commentpostername', root); diff --git a/script.coffee b/script.coffee index 6c258a4f1..eb77a9b78 100644 --- a/script.coffee +++ b/script.coffee @@ -526,19 +526,13 @@ filter = unless isOP = klass is 'op' root = $ 'td[id]', root for key of filter.filters - if filter.test root, key, isOP - return - - test: (root, key, isOP) -> - value = @[key] root, isOP - if value is false - # Return if there's nothing to filter (no tripcode for example). - return false - - for filter in @filters[key] - if filter root, value, isOP - return true - false + value = filter[key] root, isOP + if value is false + # Continue if there's nothing to filter (no tripcode for example). + continue + for Filter in filter.filters[key] + if Filter root, value, isOP + return name: (root, isOP) -> name = if isOP then $ '.postername', root else $ '.commentpostername', root From cc71307ad654b750724b12488289397b6eac1222 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 27 Feb 2012 02:07:42 +0100 Subject: [PATCH 4/6] Use the .posttime selector only for the time formatting. I'm pretty sure every threads in every boards have updated since then. --- 4chan_x.user.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 7b73fbb9f..347e9fd61 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2847,7 +2847,7 @@ node: function(root) { var node, time; if (root.className === 'inline') return; - node = $('.posttime', root) || $('span[id]', root).previousSibling; + node = $('.posttime', root); Time.date = Time.parse(node); time = $.el('time', { textContent: ' ' + Time.funk(Time) + ' ' diff --git a/script.coffee b/script.coffee index eb77a9b78..89289dd98 100644 --- a/script.coffee +++ b/script.coffee @@ -2343,7 +2343,7 @@ Time = g.callbacks.push @node node: (root) -> return if root.className is 'inline' - node = $('.posttime', root) or $('span[id]', root).previousSibling + node = $ '.posttime', root Time.date = Time.parse node time = $.el 'time', textContent: ' ' + Time.funk(Time) + ' ' From f7d17467b8aef1b6ef317595d2385d4fe0c285e5 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 27 Feb 2012 02:10:15 +0100 Subject: [PATCH 5/6] XXXs are gone. --- 4chan_x.user.js | 25 +------------------------ script.coffee | 22 ---------------------- 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 347e9fd61..d1b18b079 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -72,13 +72,12 @@ */ (function() { - var $, $$, DAY, Favicon, FileInfo, 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, quoteIndicators, quoteInline, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, strikethroughQuotes, threadHiding, threadStats, threading, titlePost, ui, unread, unxify, updater, val, watcher, _base; + var $, $$, DAY, Favicon, FileInfo, 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, quoteIndicators, quoteInline, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, strikethroughQuotes, threadHiding, threadStats, threading, titlePost, ui, unread, updater, val, watcher, _base; 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'], 'File Info Formatting': [true, 'Reformats the file information'], @@ -1242,27 +1241,6 @@ } }; - unxify = { - init: function() { - return g.callbacks.push(this.node); - }, - node: function(root) { - var number, quote; - switch (unxify.censor) { - case true: - quote = $('.quotejs + .quotejs', root); - return quote.textContent = quote.previousElementSibling.hash.slice(1); - case false: - break; - default: - number = $('.quotejs + .quotejs', root).textContent; - if (number.length < 4) return; - unxify.censor = /\D/.test($('.quotejs + .quotejs', root).textContent); - return unxify.node(root); - } - } - }; - qr = { init: function() { var form, iframe, link, loadChecking, script; @@ -3814,7 +3792,6 @@ if (conf['Indicate OP quote'] || conf['Indicate Cross-thread Quotes']) { quoteIndicators.init(); } - if (conf['Fix XXX\'d Post Numbers']) unxify.init(); return $.ready(Main.ready); }, ready: function() { diff --git a/script.coffee b/script.coffee index 89289dd98..85b928eb4 100644 --- a/script.coffee +++ b/script.coffee @@ -2,7 +2,6 @@ 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'] 'File Info Formatting': [true, 'Reformats the file information'] @@ -984,24 +983,6 @@ nav = {top} = nav.threads[i]?.getBoundingClientRect() window.scrollBy 0, top -unxify = - init: -> - g.callbacks.push @node - node: (root) -> - switch unxify.censor - when true - quote = $ '.quotejs + .quotejs', root - quote.textContent = quote.previousElementSibling.hash[1..] - when false - # Don't execute on safe boards. - else - number = $('.quotejs + .quotejs', root).textContent - # 3 digits long post numbers are not censored. - return if number.length < 4 - # Test if the board's censored. - unxify.censor = /\D/.test $('.quotejs + .quotejs', root).textContent - unxify.node root - qr = init: -> return unless $.id 'recaptcha_challenge_field_holder' @@ -3094,9 +3075,6 @@ Main = if conf['Indicate OP quote'] or conf['Indicate Cross-thread Quotes'] quoteIndicators.init() - if conf['Fix XXX\'d Post Numbers'] - unxify.init() - $.ready Main.ready ready: -> From bf54dff77b1355b51c0a8853db1f11b4e164ee50 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 27 Feb 2012 02:52:30 +0100 Subject: [PATCH 6/6] Admin/mod filter. Close #290. --- 4chan_x.user.js | 9 +++++++++ changelog | 4 +++- script.coffee | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index d1b18b079..ff58e1446 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -139,6 +139,7 @@ filter: { name: ['# Filter any namefags:', '#/^(?!Anonymous$)/'].join('\n'), tripcode: ['# Filter any tripfags', '#/^!/'].join('\n'), + mod: ['# Set a custom class for mods:', '#/Mod$/;highlight:mod;op:yes', '# Set a custom class for moot:', '#/Admin$/;highlight:moot;op:yes'].join('\n'), email: ['# Filter any e-mails that are not `sage` on /a/ and /jp/:', '#/^(?!sage$)/;boards:a,jp'].join('\n'), subject: ['# Filter Generals on /v/:', '#/general/i;boards:v;op:only'].join('\n'), comment: ['# Filter Stallman copypasta on /g/:', '#/what you\'re refer+ing to as linux/i;boards:g'].join('\n'), @@ -625,6 +626,13 @@ if (trip = $('.postertrip', root)) return trip.textContent; return false; }, + mod: function(root, isOP) { + var mod; + if (mod = (isOP ? $('.commentpostername', root) : $('.commentpostername ~ .commentpostername', root))) { + return mod.textContent; + } + return false; + }, email: function(root) { var mail; if (mail = $('.linkmail', root)) return mail.href; @@ -2132,6 +2140,7 @@ \

Name:

\

Tripcode:

\ +

Admin/Mod:

\

E-mail:

\

Subject:

\

Comment:

\ diff --git a/changelog b/changelog index d1600ae15..8e8bf2bff 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,5 @@ master --ahodesuka +- ahodesuka Reply/Thread File Info Formatting: - Link: %l, %L (Original file names are shown inside threads). - Size: %B (Bytes), %K (KB), %M (MB), %s (4chan default). @@ -8,6 +8,8 @@ master - noface Update imagelimit for mlp. Fix stubs if poster has unique ID. +- Mayhem + You can now filter or highlight admin/mod posts. 2.27.1 - Mayhem diff --git a/script.coffee b/script.coffee index 85b928eb4..2326e0175 100644 --- a/script.coffee +++ b/script.coffee @@ -62,6 +62,12 @@ config = '# Filter any tripfags' '#/^!/' ].join '\n' + mod: [ + '# Set a custom class for mods:' + '#/Mod$/;highlight:mod;op:yes' + '# Set a custom class for moot:' + '#/Admin$/;highlight:moot;op:yes' + ].join '\n' email: [ '# Filter any e-mails that are not `sage` on /a/ and /jp/:' '#/^(?!sage$)/;boards:a,jp' @@ -540,6 +546,10 @@ filter = if trip = $ '.postertrip', root return trip.textContent false + mod: (root, isOP) -> + if mod = (if isOP then $ '.commentpostername', root else $ '.commentpostername ~ .commentpostername', root) + return mod.textContent + false email: (root) -> if mail = $ '.linkmail', root return mail.href @@ -1731,6 +1741,7 @@ options =

Name:

Tripcode:

+

Admin/Mod:

E-mail:

Subject:

Comment: