This commit is contained in:
No Face 2012-02-27 15:35:26 +01:00
commit 3e5f9c3d24
3 changed files with 53 additions and 86 deletions

View File

@ -72,13 +72,12 @@
*/ */
(function() { (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 = { config = {
main: { main: {
Enhancing: { Enhancing: {
'404 Redirect': [true, 'Redirect dead threads and images'], '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'], 'Keybinds': [true, 'Binds actions to keys'],
'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'], 'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'],
'File Info Formatting': [true, 'Reformats the file information'], 'File Info Formatting': [true, 'Reformats the file information'],
@ -140,6 +139,7 @@
filter: { filter: {
name: ['# Filter any namefags:', '#/^(?!Anonymous$)/'].join('\n'), name: ['# Filter any namefags:', '#/^(?!Anonymous$)/'].join('\n'),
tripcode: ['# Filter any tripfags', '#/^!/'].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'), 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'), 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'), 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) { node: function(root) {
var isOP, key, klass; var Filter, isOP, key, klass, value, _i, _len, _ref;
klass = root.className; klass = root.className;
if (/\binlined\b/.test(klass)) return; if (/\binlined\b/.test(klass)) return;
if (!(isOP = klass === 'op')) root = $('td[id]', root); if (!(isOP = klass === 'op')) root = $('td[id]', root);
for (key in filter.filters) { 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) { name: function(root, isOP) {
var name; var name;
name = isOP ? $('.postername', root) : $('.commentpostername', root); name = isOP ? $('.postername', root) : $('.commentpostername', root);
@ -631,6 +626,13 @@
if (trip = $('.postertrip', root)) return trip.textContent; if (trip = $('.postertrip', root)) return trip.textContent;
return false; return false;
}, },
mod: function(root, isOP) {
var mod;
if (mod = (isOP ? $('.commentpostername', root) : $('.commentpostername ~ .commentpostername', root))) {
return mod.textContent;
}
return false;
},
email: function(root) { email: function(root) {
var mail; var mail;
if (mail = $('.linkmail', root)) return mail.href; 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 = { qr = {
init: function() { init: function() {
var form, iframe, link, loadChecking, script; var form, iframe, link, loadChecking, script;
@ -2159,6 +2140,7 @@
</ul>\ </ul>\
<p>Name:<br><textarea name=name></textarea></p>\ <p>Name:<br><textarea name=name></textarea></p>\
<p>Tripcode:<br><textarea name=tripcode></textarea></p>\ <p>Tripcode:<br><textarea name=tripcode></textarea></p>\
<p>Admin/Mod:<br><textarea name=mod></textarea></p>\
<p>E-mail:<br><textarea name=email></textarea></p>\ <p>E-mail:<br><textarea name=email></textarea></p>\
<p>Subject:<br><textarea name=subject></textarea></p>\ <p>Subject:<br><textarea name=subject></textarea></p>\
<p>Comment:<br><textarea name=comment></textarea></p>\ <p>Comment:<br><textarea name=comment></textarea></p>\
@ -2852,7 +2834,7 @@
node: function(root) { node: function(root) {
var node, time; var node, time;
if (root.className === 'inline') return; if (root.className === 'inline') return;
node = $('.posttime', root) || $('span[id]', root).previousSibling; node = $('.posttime', root);
Time.date = Time.parse(node); Time.date = Time.parse(node);
time = $.el('time', { time = $.el('time', {
textContent: ' ' + Time.funk(Time) + ' ' textContent: ' ' + Time.funk(Time) + ' '
@ -2995,7 +2977,7 @@
size /= 1024; 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); size = size.toFixed(2);
} }
} }
@ -3320,13 +3302,13 @@
_ref = $$('.quotelink', root); _ref = $$('.quotelink', root);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i]; quote = _ref[_i];
hash = quote.hash.slice(1); if (!(hash = quote.hash.slice(1))) continue;
if (conf['Indicate OP quote'] && hash === tid) { if (conf['Indicate OP quote'] && hash === tid) {
$.add(quote, $.tn('\u00A0(OP)')); $.add(quote, $.tn('\u00A0(OP)'));
return; continue;
} }
path = quote.pathname; 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)')); $.add(quote, $.tn('\u00A0(Cross-thread)'));
} }
} }
@ -3819,7 +3801,6 @@
if (conf['Indicate OP quote'] || conf['Indicate Cross-thread Quotes']) { if (conf['Indicate OP quote'] || conf['Indicate Cross-thread Quotes']) {
quoteIndicators.init(); quoteIndicators.init();
} }
if (conf['Fix XXX\'d Post Numbers']) unxify.init();
return $.ready(Main.ready); return $.ready(Main.ready);
}, },
ready: function() { ready: function() {

View File

@ -1,5 +1,5 @@
master master
-ahodesuka - ahodesuka
Reply/Thread File Info Formatting: Reply/Thread File Info Formatting:
- Link: %l, %L (Original file names are shown inside threads). - Link: %l, %L (Original file names are shown inside threads).
- Size: %B (Bytes), %K (KB), %M (MB), %s (4chan default). - Size: %B (Bytes), %K (KB), %M (MB), %s (4chan default).
@ -8,6 +8,8 @@ master
- noface - noface
Update imagelimit for mlp. Update imagelimit for mlp.
Fix stubs if poster has unique ID. Fix stubs if poster has unique ID.
- Mayhem
You can now filter or highlight admin/mod posts.
2.27.1 2.27.1
- Mayhem - Mayhem

View File

@ -2,7 +2,6 @@ config =
main: main:
Enhancing: Enhancing:
'404 Redirect': [true, 'Redirect dead threads and images'] '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'] 'Keybinds': [true, 'Binds actions to keys']
'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'] 'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time']
'File Info Formatting': [true, 'Reformats the file information'] 'File Info Formatting': [true, 'Reformats the file information']
@ -63,6 +62,12 @@ config =
'# Filter any tripfags' '# Filter any tripfags'
'#/^!/' '#/^!/'
].join '\n' ].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: [ email: [
'# Filter any e-mails that are not `sage` on /a/ and /jp/:' '# Filter any e-mails that are not `sage` on /a/ and /jp/:'
'#/^(?!sage$)/;boards:a,jp' '#/^(?!sage$)/;boards:a,jp'
@ -526,19 +531,13 @@ filter =
unless isOP = klass is 'op' unless isOP = klass is 'op'
root = $ 'td[id]', root root = $ 'td[id]', root
for key of filter.filters for key of filter.filters
if filter.test root, key, isOP value = filter[key] root, isOP
return if value is false
# Continue if there's nothing to filter (no tripcode for example).
test: (root, key, isOP) -> continue
value = @[key] root, isOP for Filter in filter.filters[key]
if value is false if Filter root, value, isOP
# Return if there's nothing to filter (no tripcode for example). return
return false
for filter in @filters[key]
if filter root, value, isOP
return true
false
name: (root, isOP) -> name: (root, isOP) ->
name = if isOP then $ '.postername', root else $ '.commentpostername', root name = if isOP then $ '.postername', root else $ '.commentpostername', root
@ -547,6 +546,10 @@ filter =
if trip = $ '.postertrip', root if trip = $ '.postertrip', root
return trip.textContent return trip.textContent
false false
mod: (root, isOP) ->
if mod = (if isOP then $ '.commentpostername', root else $ '.commentpostername ~ .commentpostername', root)
return mod.textContent
false
email: (root) -> email: (root) ->
if mail = $ '.linkmail', root if mail = $ '.linkmail', root
return mail.href return mail.href
@ -990,24 +993,6 @@ nav =
{top} = nav.threads[i]?.getBoundingClientRect() {top} = nav.threads[i]?.getBoundingClientRect()
window.scrollBy 0, top 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 = qr =
init: -> init: ->
return unless $.id 'recaptcha_challenge_field_holder' return unless $.id 'recaptcha_challenge_field_holder'
@ -1756,6 +1741,7 @@ options =
</ul> </ul>
<p>Name:<br><textarea name=name></textarea></p> <p>Name:<br><textarea name=name></textarea></p>
<p>Tripcode:<br><textarea name=tripcode></textarea></p> <p>Tripcode:<br><textarea name=tripcode></textarea></p>
<p>Admin/Mod:<br><textarea name=mod></textarea></p>
<p>E-mail:<br><textarea name=email></textarea></p> <p>E-mail:<br><textarea name=email></textarea></p>
<p>Subject:<br><textarea name=subject></textarea></p> <p>Subject:<br><textarea name=subject></textarea></p>
<p>Comment:<br><textarea name=comment></textarea></p> <p>Comment:<br><textarea name=comment></textarea></p>
@ -2349,7 +2335,7 @@ Time =
g.callbacks.push @node g.callbacks.push @node
node: (root) -> node: (root) ->
return if root.className is 'inline' return if root.className is 'inline'
node = $('.posttime', root) or $('span[id]', root).previousSibling node = $ '.posttime', root
Time.date = Time.parse node Time.date = Time.parse node
time = $.el 'time', time = $.el 'time',
textContent: ' ' + Time.funk(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'
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 y: -> Time.date.getFullYear() - 2000
FileInfo = FileInfo =
init: -> init: ->
return if g.BOARD is 'f' return if g.BOARD is 'f'
@ -2444,13 +2430,13 @@ FileInfo =
size *= 1024 while i-- > 0 size *= 1024 while i-- > 0
else if i < 0 else if i < 0
size /= 1024 while 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 = size.toFixed 2
"#{size} #{unitT}" "#{size} #{unitT}"
formatters: formatters:
B: -> FileInfo.convertUnit 'B' B: -> FileInfo.convertUnit 'B'
K: -> FileInfo.convertUnit 'KB' 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() + '<' FileInfo.data.link.replace />\d+\.\w+</, '>' + FileInfo.formatters.n() + '<'
else else
FileInfo.data.link FileInfo.data.link
@ -2674,14 +2660,15 @@ quoteIndicators =
# We use contains() so that it works with hidden threads # We use contains() so that it works with hidden threads
tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]', root).firstChild.id tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]', root).firstChild.id
for quote in $$ '.quotelink', root for quote in $$ '.quotelink', root
hash = quote.hash[1..] unless hash = quote.hash[1..]
continue
if conf['Indicate OP quote'] and hash is tid if conf['Indicate OP quote'] and hash is tid
# \u00A0 is nbsp # \u00A0 is nbsp
$.add quote, $.tn '\u00A0(OP)' $.add quote, $.tn '\u00A0(OP)'
return continue
path = quote.pathname path = quote.pathname
#if quote leads to a different thread id and is located on the same board (index 0) #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 # \u00A0 is nbsp
$.add quote, $.tn '\u00A0(Cross-thread)' $.add quote, $.tn '\u00A0(Cross-thread)'
return return
@ -3068,7 +3055,7 @@ Main =
if conf['Time Formatting'] if conf['Time Formatting']
Time.init() Time.init()
if conf['File Info Formatting'] if conf['File Info Formatting']
FileInfo.init() FileInfo.init()
@ -3099,9 +3086,6 @@ Main =
if conf['Indicate OP quote'] or conf['Indicate Cross-thread Quotes'] if conf['Indicate OP quote'] or conf['Indicate Cross-thread Quotes']
quoteIndicators.init() quoteIndicators.init()
if conf['Fix XXX\'d Post Numbers']
unxify.init()
$.ready Main.ready $.ready Main.ready
ready: -> ready: ->