diff --git a/4chan_x.user.js b/4chan_x.user.js index 35c743969..ff58e1446 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'], @@ -140,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'), @@ -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); @@ -631,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; @@ -1247,27 +1249,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; @@ -2159,6 +2140,7 @@ \

Name:

\

Tripcode:

\ +

Admin/Mod:

\

E-mail:

\

Subject:

\

Comment:

\ @@ -2852,7 +2834,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) + ' ' @@ -2995,7 +2977,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); } } @@ -3320,13 +3302,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)')); } } @@ -3819,7 +3801,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/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 6342704d5..2326e0175 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'] @@ -63,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' @@ -526,19 +531,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 @@ -547,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 @@ -990,24 +993,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' @@ -1756,6 +1741,7 @@ options =

Name:

Tripcode:

+

Admin/Mod:

E-mail:

Subject:

Comment:

@@ -2349,7 +2335,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) + ' ' @@ -2401,7 +2387,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 +2430,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 @@ -2674,14 +2660,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 @@ -3068,7 +3055,7 @@ Main = if conf['Time Formatting'] Time.init() - + if conf['File Info Formatting'] FileInfo.init() @@ -3099,9 +3086,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: ->