From 5c8c7be4babedf7c08e1982e2622e8747665c1cc Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 18:54:23 +0100 Subject: [PATCH 01/14] Replace auto-GIF thumbnails once the GIF has finished loading. --- 4chan_x.user.js | 10 ++++++++-- script.coffee | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index ff58e1446..4bdf446de 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3556,10 +3556,16 @@ return g.callbacks.push(this.node); }, node: function(root) { - var src, thumb; + var img, src, thumb; if (root.hidden || !(thumb = $('img[md5]', root))) return; src = thumb.parentNode.href; - if (/gif$/.test(src) && !/spoiler/.test(src)) return thumb.src = src; + if (/gif$/.test(src) && !/spoiler/.test(src)) { + img = $.el('img'); + $.on(img, 'load', function() { + return thumb.src = src; + }); + return img.src = src; + } } }; diff --git a/script.coffee b/script.coffee index 2326e0175..92c6ca415 100644 --- a/script.coffee +++ b/script.coffee @@ -2862,7 +2862,11 @@ imgGif = return if root.hidden or !thumb = $ 'img[md5]', root src = thumb.parentNode.href if /gif$/.test(src) and !/spoiler/.test src - thumb.src = src + img = $.el 'img' + $.on img, 'load', -> + # Replace the thumbnail once the GIF has finished loading. + thumb.src = src + img.src = src imgExpand = init: -> From 795032c2650ddd498e30adc81daf4a011cf97119 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 18:57:25 +0100 Subject: [PATCH 02/14] Add an extra space at the end of the captcha response. --- 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 4bdf446de..ce47054d8 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1856,7 +1856,7 @@ mode: 'regist', pwd: (m = d.cookie.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $('[name=pwd]').value, recaptcha_challenge_field: challenge, - recaptcha_response_field: response + recaptcha_response_field: response + ' ' }; qr.status({ progress: '...' diff --git a/script.coffee b/script.coffee index 92c6ca415..5901d473e 100644 --- a/script.coffee +++ b/script.coffee @@ -1490,7 +1490,7 @@ qr = mode: 'regist' pwd: if m = d.cookie.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('[name=pwd]').value recaptcha_challenge_field: challenge - recaptcha_response_field: response + recaptcha_response_field: response + ' ' # Starting to upload might take some time. # Provide some feedback that we're starting to submit. From 154cec7ee00d505eb4e995821826880a18b1cd25 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 19:03:40 +0100 Subject: [PATCH 03/14] Fix #289. --- 4chan_x.user.js | 9 +++++++-- script.coffee | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index ce47054d8..9e8de9c1d 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -584,7 +584,11 @@ return false; } if (hl) { - $.addClass(root, hl); + if (isOP) { + $.addClass(root, hl); + } else { + $.addClass(root.parentNode, hl); + } if (isOP && top && !g.REPLY) { thisThread = root.parentNode; if (firstThread = $('div[class=op]')) { @@ -4268,7 +4272,8 @@ td > .filesize > img[md5] {\ .filetitle, .replytitle, .postername, .commentpostername, .postertrip {\ background: none;\ }\ -.filter_highlight {\ +.filter_highlight.op,\ +.filter_highlight > td[id] {\ box-shadow: -5px 0 rgba(255,0,0,0.5);\ }\ .filtered {\ diff --git a/script.coffee b/script.coffee index 5901d473e..4f2056a2d 100644 --- a/script.coffee +++ b/script.coffee @@ -509,7 +509,10 @@ filter = else unless regexp.test value return false if hl - $.addClass root, hl + if isOP + $.addClass root, hl + else + $.addClass root.parentNode, hl if isOP and top and not g.REPLY # Put the highlighted OPs' threads on top of the board pages... thisThread = root.parentNode @@ -3557,7 +3560,8 @@ td > .filesize > img[md5] { .filetitle, .replytitle, .postername, .commentpostername, .postertrip { background: none; } -.filter_highlight { +.filter_highlight.op, +.filter_highlight > td[id] { box-shadow: -5px 0 rgba(255,0,0,0.5); } .filtered { From fe1991a68a93785cf9800de91925c843f95f3bdf Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 19:12:52 +0100 Subject: [PATCH 04/14] Fix #297. --- 4chan_x.user.js | 6 ++++-- script.coffee | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 9e8de9c1d..1ae3e8393 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -664,8 +664,10 @@ return false; }, dimensions: function(root) { - var span; - if (span = $('.filesize', root)) return span.textContent.match(/\d+x\d+/)[0]; + var match, span; + if ((span = $('.filesize', root)) && (match = span.textContent.match(/\d+x\d+/))) { + return match[0]; + } return false; }, filesize: function(root) { diff --git a/script.coffee b/script.coffee index 4f2056a2d..66c26ab0e 100644 --- a/script.coffee +++ b/script.coffee @@ -574,8 +574,8 @@ filter = return file.title false dimensions: (root) -> - if span = $ '.filesize', root - return span.textContent.match(/\d+x\d+/)[0] + if (span = $ '.filesize', root) and match = span.textContent.match /\d+x\d+/ + return match[0] return false filesize: (root) -> if img = $ 'img[md5]', root From 6a006c8afebc75e434c3c510c7feb0dd01d73c95 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 19:18:43 +0100 Subject: [PATCH 05/14] God. Fucking. Damn it. --- 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 1ae3e8393..039ba1c74 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2825,7 +2825,7 @@ Time.foo(); chanOffset = 5 - new Date().getTimezoneOffset() / 60; if ($.isDST()) chanOffset--; - this.parse = Date.parse('10/11/11(Tue)18:53' === 1318351980000) ? function(node) { + this.parse = Date.parse('10/11/11(Tue)18:53') === 1318351980000 ? function(node) { return new Date(Date.parse(node.textContent) + chanOffset * HOUR); } : function(node) { var day, hour, min, month, year, _, _ref; diff --git a/script.coffee b/script.coffee index 66c26ab0e..d1111fd2d 100644 --- a/script.coffee +++ b/script.coffee @@ -2324,7 +2324,7 @@ Time = chanOffset-- if $.isDST() @parse = - if Date.parse '10/11/11(Tue)18:53' is 1318351980000 + if Date.parse('10/11/11(Tue)18:53') is 1318351980000 (node) -> new Date Date.parse(node.textContent) + chanOffset*HOUR else # Firefox and Opera do not parse 4chan's time format correctly (node) -> From 3de9684dba26aaa55be639b524826020a2bc1355 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 19:24:20 +0100 Subject: [PATCH 06/14] Fix #296. --- 4chan_x.user.js | 2 +- script.coffee | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 039ba1c74..7612e9c4b 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2840,7 +2840,7 @@ node: function(root) { var node, time; if (root.className === 'inline') return; - node = $('.posttime', root); + node = $('.posttime', root) || $('span[id]', root).previousSibling; Time.date = Time.parse(node); time = $.el('time', { textContent: ' ' + Time.funk(Time) + ' ' diff --git a/script.coffee b/script.coffee index d1111fd2d..01547fd3f 100644 --- a/script.coffee +++ b/script.coffee @@ -2338,7 +2338,8 @@ Time = g.callbacks.push @node node: (root) -> return if root.className is 'inline' - node = $ '.posttime', root + # .posttime exists on every board except /f/ + node = $('.posttime', root) or $('span[id]', root).previousSibling Time.date = Time.parse node time = $.el 'time', textContent: ' ' + Time.funk(Time) + ' ' From 558d65b15d4181ed9781136baabd0935d4e369c2 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 20:17:29 +0100 Subject: [PATCH 07/14] Add current board sauce parameter. Close #298. --- 4chan_x.user.js | 15 +++++++++------ changelog | 1 + script.coffee | 17 ++++++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 7612e9c4b..9ff5fe3be 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -148,7 +148,7 @@ filesize: [''].join('\n'), md5: [''].join('\n') }, - sauces: ['http://iqdb.org/?url=$1', 'http://www.google.com/searchbyimage?image_url=$1', '#http://tineye.com/search?url=$1', '#http://saucenao.com/search.php?db=999&url=$1', '#http://3d.iqdb.org/?url=$1', '#http://regex.info/exif.cgi?imgurl=$2', '# uploaders:', '#http://imgur.com/upload?url=$2', '#http://omploader.org/upload?url1=$2', '# "View Same" in archives:', '#http://archive.foolz.us/a/image/$3/', '#http://archive.installgentoo.net/g/image/$3'].join('\n'), + sauces: ['http://iqdb.org/?url=$1', 'http://www.google.com/searchbyimage?image_url=$1', '#http://tineye.com/search?url=$1', '#http://saucenao.com/search.php?db=999&url=$1', '#http://3d.iqdb.org/?url=$1', '#http://regex.info/exif.cgi?imgurl=$2', '# uploaders:', '#http://imgur.com/upload?url=$2', '#http://omploader.org/upload?url1=$2', '# "View Same" in archives:', '#http://archive.foolz.us/$4/image/$3/', '#http://archive.installgentoo.net/$4/image/$3'].join('\n'), time: '%m/%d/%y(%a)%H:%M', backlink: '>>%id', fileInfoR: '%l, %s, %r', @@ -2125,10 +2125,11 @@
\
Sauce is disabled.
\ Lines starting with a # will be ignored.\ -
    These variables will be replaced by the corresponding url:\ -
  • $1: Thumbnail.
  • \ -
  • $2: Full image.
  • \ +
      These parameters will be replaced by their corresponding values:\ +
    • $1: Thumbnail url.
    • \ +
    • $2: Full image url.
    • \
    • $3: MD5 hash.
    • \ +
    • $4: Current board.
    • \
    \ \
\ @@ -2771,14 +2772,16 @@ funk: function(link) { var domain, href; domain = link.match(/(\w+)\.\w+\//)[1]; - href = link.replace(/(\$\d)/, function(fragment) { - switch (fragment) { + href = link.replace(/(\$\d)/g, function(parameter) { + switch (parameter) { case '$1': return "http://thumbs.4chan.org' + img.pathname.replace(/src(\\/\\d+).+$/, 'thumb$1s.jpg') + '"; case '$2': return "' + img.href + '"; case '$3': return "' + img.firstChild.getAttribute('md5').replace(/\=*$/, '') + '"; + case '$4': + return g.BOARD; } }); href = Function('img', "return '" + href + "'"); diff --git a/changelog b/changelog index 8e8bf2bff..9cf7de130 100644 --- a/changelog +++ b/changelog @@ -10,6 +10,7 @@ master Fix stubs if poster has unique ID. - Mayhem You can now filter or highlight admin/mod posts. + New sauce parameter. $4: Current board. 2.27.1 - Mayhem diff --git a/script.coffee b/script.coffee index 01547fd3f..f5a6d48ea 100644 --- a/script.coffee +++ b/script.coffee @@ -104,8 +104,8 @@ config = '#http://imgur.com/upload?url=$2' '#http://omploader.org/upload?url1=$2' '# "View Same" in archives:' - '#http://archive.foolz.us/a/image/$3/' - '#http://archive.installgentoo.net/g/image/$3' + '#http://archive.foolz.us/$4/image/$3/' + '#http://archive.installgentoo.net/$4/image/$3' ].join '\n' time: '%m/%d/%y(%a)%H:%M' backlink: '>>%id' @@ -1723,10 +1723,11 @@ options =
Sauce is disabled.
Lines starting with a # will be ignored. -
    These variables will be replaced by the corresponding url: -
  • $1: Thumbnail.
  • -
  • $2: Full image.
  • +
      These parameters will be replaced by their corresponding values: +
    • $1: Thumbnail url.
    • +
    • $2: Full image url.
    • $3: MD5 hash.
    • +
    • $4: Current board.
@@ -2282,14 +2283,16 @@ sauce = funk: (link) -> domain = link.match(/(\w+)\.\w+\//)[1] - href = link.replace /(\$\d)/, (fragment) -> - switch fragment + href = link.replace /(\$\d)/g, (parameter) -> + switch parameter when '$1' "http://thumbs.4chan.org' + img.pathname.replace(/src(\\/\\d+).+$/, 'thumb$1s.jpg') + '" when '$2' "' + img.href + '" when '$3' "' + img.firstChild.getAttribute('md5').replace(/\=*$/, '') + '" + when '$4' + g.BOARD href = Function 'img', "return '#{href}'" (img) -> $.el 'a', From b3dd24ed2ec9a26ca38fb9bff9afb8d862c14952 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 20:44:52 +0100 Subject: [PATCH 08/14] Add "textInput" and "paste" events to the list of event listeners used to save inputs' values. "textInput" is supposed to be enough, but, well, you know... >2012 >Gecko Close #269. --- 4chan_x.user.js | 15 ++++++++------- script.coffee | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 9ff5fe3be..bb9aca8b1 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1704,7 +1704,7 @@ } }, dialog: function() { - var e, fileInput, input, mimeTypes, name, spoiler, ta, thread, threads, _i, _j, _len, _len2, _ref, _ref2; + var e, event, fileInput, input, mimeTypes, name, spoiler, ta, thread, threads, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3; qr.el = ui.dialog('qr', 'top:0;right:0;', '\
\ Quick Reply \ @@ -1780,12 +1780,13 @@ for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { name = _ref2[_j]; input = $("[name=" + name + "]", qr.el); - $.on(input, 'keyup', function() { - return qr.selected[this.name] = this.value; - }); - $.on(input, 'change', function() { - return qr.selected[this.name] = this.value; - }); + _ref3 = ['textInput', 'keyup', 'change', 'paste']; + for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) { + event = _ref3[_k]; + $.on(input, event, function() { + return qr.selected[this.name] = this.value; + }); + } } $.sync('qr.persona', function(persona) { var key, val, _results; diff --git a/script.coffee b/script.coffee index f5a6d48ea..387dc4eb9 100644 --- a/script.coffee +++ b/script.coffee @@ -1414,8 +1414,8 @@ qr = # save selected reply's data for name in ['name', 'email', 'sub', 'com'] input = $ "[name=#{name}]", qr.el - $.on input, 'keyup', -> qr.selected[@name] = @value - $.on input, 'change', -> qr.selected[@name] = @value + for event in ['textInput', 'keyup', 'change', 'paste'] + $.on input, event, -> qr.selected[@name] = @value # sync between tabs $.sync 'qr.persona', (persona) -> return unless qr.el.hidden From 28923042ababc34fb5eb57ac915577b8035b660a Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 21:23:03 +0100 Subject: [PATCH 09/14] Keep the File Info Formatting default settings closer to 4chan's original layout. --- 4chan_x.user.js | 4 ++-- script.coffee | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index bb9aca8b1..bd1116c56 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -151,8 +151,8 @@ sauces: ['http://iqdb.org/?url=$1', 'http://www.google.com/searchbyimage?image_url=$1', '#http://tineye.com/search?url=$1', '#http://saucenao.com/search.php?db=999&url=$1', '#http://3d.iqdb.org/?url=$1', '#http://regex.info/exif.cgi?imgurl=$2', '# uploaders:', '#http://imgur.com/upload?url=$2', '#http://omploader.org/upload?url1=$2', '# "View Same" in archives:', '#http://archive.foolz.us/$4/image/$3/', '#http://archive.installgentoo.net/$4/image/$3'].join('\n'), time: '%m/%d/%y(%a)%H:%M', backlink: '>>%id', - fileInfoR: '%l, %s, %r', - fileInfoT: '%l, %s, %r', + fileInfoR: '%l (%s, %r)', + fileInfoT: '%l (%s, %r)', favicon: 'ferongr', hotkeys: { openOptions: ['ctrl+o', 'Open Options'], diff --git a/script.coffee b/script.coffee index 387dc4eb9..76ead9e0f 100644 --- a/script.coffee +++ b/script.coffee @@ -109,8 +109,8 @@ config = ].join '\n' time: '%m/%d/%y(%a)%H:%M' backlink: '>>%id' - fileInfoR: '%l, %s, %r' - fileInfoT: '%l, %s, %r' + fileInfoR: '%l (%s, %r)' + fileInfoT: '%l (%s, %r)' favicon: 'ferongr' hotkeys: openOptions: ['ctrl+o', 'Open Options'] From 9d0594312e90f1240d7b4b53aa1fedffd77fe9e2 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 22:24:49 +0100 Subject: [PATCH 10/14] Some FileInfo refactoring. Fix FileInfo preview in options when it was disabled. --- 4chan_x.user.js | 32 ++++++++++++-------------- script.coffee | 60 ++++++++++++++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index bd1116c56..63d2ca4fc 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2931,29 +2931,22 @@ FileInfo = { init: function() { if (g.BOARD === 'f') return; - FileInfo.ffConf = ['fileInfoR', 'fileInfoT']; - FileInfo.ffMtrs = [/%([BKlLMnNrs])/g, /%([BKlMrs])/g]; - FileInfo.ffRgex = [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/]; - this.parse = function(node) { - var filename, link, resolution, size, unit, _, _ref; - FileInfo.ffType = node.childNodes.length > 3 ? 0 : 1; - _ref = node.innerHTML.match(FileInfo.ffRgex[FileInfo.ffType]), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], filename = _ref[5]; - return { - link: link, - size: size, - unit: unit, - resolution: resolution, - filename: filename - }; - }; FileInfo.funks = FileInfo.setFormats(); return g.callbacks.push(this.node); }, node: function(root) { - var node; + var filename, link, node, resolution, size, unit, _, _ref; if (root.className === 'inline' || !(node = $('.filesize', root))) return; - FileInfo.data = FileInfo.parse(node); - return node.innerHTML = FileInfo.funks[FileInfo.ffType](FileInfo) + ' '; + FileInfo.ffType = node.childElementCount === 2 ? 0 : 1; + _ref = node.innerHTML.match(FileInfo.ffRgex[FileInfo.ffType]), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], filename = _ref[5]; + FileInfo.data = { + link: link, + size: size, + unit: unit, + resolution: resolution, + filename: filename + }; + return node.innerHTML = FileInfo.funks[FileInfo.ffType](FileInfo); }, setFormats: function() { var code, i, _results; @@ -2993,6 +2986,9 @@ } return "" + size + " " + unitT; }, + ffConf: ['fileInfoR', 'fileInfoT'], + ffMtrs: [/%([BKlLMnNrs])/g, /%([BKlMrs])/g], + ffRgex: [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/], formatters: { B: function() { return FileInfo.convertUnit('B'); diff --git a/script.coffee b/script.coffee index 76ead9e0f..0d99f65d9 100644 --- a/script.coffee +++ b/script.coffee @@ -2398,26 +2398,20 @@ Time = FileInfo = init: -> return if g.BOARD is 'f' - FileInfo.ffConf = [ 'fileInfoR', 'fileInfoT' ] - FileInfo.ffMtrs = [ /%([BKlLMnNrs])/g, /%([BKlMrs])/g ] - FileInfo.ffRgex = [ /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/, - /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/ ] - @parse = (node) -> - FileInfo.ffType = if node.childNodes.length > 3 then 0 else 1 - [_, link, size, unit, resolution, filename] = - node.innerHTML.match FileInfo.ffRgex[FileInfo.ffType] - link : link - size : size - unit : unit - resolution: resolution - filename : filename - FileInfo.funks = FileInfo.setFormats() g.callbacks.push @node node: (root) -> return if root.className is 'inline' or not node = $ '.filesize', root - FileInfo.data = FileInfo.parse node - node.innerHTML = FileInfo.funks[FileInfo.ffType](FileInfo) + ' ' + FileInfo.ffType = if node.childElementCount is 2 then 0 else 1 + [_, link, size, unit, resolution, filename] = + node.innerHTML.match FileInfo.ffRgex[FileInfo.ffType] + FileInfo.data = + link: link + size: size + unit: unit + resolution: resolution + filename: filename + node.innerHTML = FileInfo.funks[FileInfo.ffType] FileInfo setFormats: -> for i in [0..1] code = conf[FileInfo.ffConf[i]].replace FileInfo.ffMtrs[i], (s, c) -> @@ -2430,8 +2424,8 @@ FileInfo = size = FileInfo.data.size unitF = FileInfo.data.unit if unitF isnt unitT - units = [ 'B', 'KB', 'MB' ] - i = units.indexOf(unitF) - units.indexOf(unitT) + units = ['B', 'KB', 'MB'] + i = units.indexOf(unitF) - units.indexOf unitT unitT = 'Bytes' if unitT is 'B' if i > 0 size *= 1024 while i-- > 0 @@ -2440,19 +2434,33 @@ FileInfo = if size < 1 and size.toString().length > size.toFixed(2).length size = size.toFixed 2 "#{size} #{unitT}" + ffConf: [ + 'fileInfoR' + 'fileInfoT' + ] + ffMtrs: [ + /%([BKlLMnNrs])/g + /%([BKlMrs])/g + ] + ffRgex: [ + /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/ + /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/ + ] formatters: B: -> FileInfo.convertUnit 'B' K: -> FileInfo.convertUnit 'KB' - l: -> if FileInfo.ffType is 0 - FileInfo.data.link.replace />\d+\.\w+' + FileInfo.formatters.n() + '<' - else - FileInfo.data.link + l: -> + if FileInfo.ffType is 0 + FileInfo.data.link.replace />\d+\.\w+' + FileInfo.formatters.n() + '<' + else + FileInfo.data.link L: -> FileInfo.data.link.replace />\d+\.\w+' + FileInfo.data.filename + '<' M: -> FileInfo.convertUnit 'MB' - n: -> if (ext = FileInfo.data.filename.lastIndexOf '.') > 38 - '' + FileInfo.data.filename + '' + FileInfo.data.filename.substr(0, 32) + ' (...)' + FileInfo.data.filename.substr(ext) + '' - else - FileInfo.data.filename + n: -> + if (ext = FileInfo.data.filename.lastIndexOf '.') > 38 + '' + FileInfo.data.filename + '' + FileInfo.data.filename.substr(0, 32) + ' (...)' + FileInfo.data.filename.substr(ext) + '' + else + FileInfo.data.filename N: -> FileInfo.data.filename r: -> FileInfo.data.resolution s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}" From 23766e8ef916584eeea567407b8cc7c96e66f51a Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 22:29:38 +0100 Subject: [PATCH 11/14] Drop 'ff' prefixes in FileInfo values. It's already prefixed you aho. --- 4chan_x.user.js | 20 ++++++++++---------- script.coffee | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 63d2ca4fc..025489f63 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2320,7 +2320,7 @@ return $.id('backlinkPreview').textContent = conf['backlink'].replace(/%id/, '123456789'); }, fileInfo: function() { - FileInfo.ffType = this.name === 'fileInfoR' ? 0 : 1; + FileInfo.type = this.name === 'fileInfoR' ? 0 : 1; FileInfo.data = { link: '1329791824.png', size: 996, @@ -2329,7 +2329,7 @@ filename: 'Untitled.png' }; FileInfo.funks = FileInfo.setFormats(); - return $.id("" + this.name + "Preview").innerHTML = FileInfo.funks[FileInfo.ffType](FileInfo); + return $.id("" + this.name + "Preview").innerHTML = FileInfo.funks[FileInfo.type](FileInfo); }, favicon: function() { Favicon["switch"](); @@ -2937,8 +2937,8 @@ node: function(root) { var filename, link, node, resolution, size, unit, _, _ref; if (root.className === 'inline' || !(node = $('.filesize', root))) return; - FileInfo.ffType = node.childElementCount === 2 ? 0 : 1; - _ref = node.innerHTML.match(FileInfo.ffRgex[FileInfo.ffType]), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], filename = _ref[5]; + FileInfo.type = node.childElementCount === 2 ? 0 : 1; + _ref = node.innerHTML.match(FileInfo.regexp[FileInfo.type]), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], filename = _ref[5]; FileInfo.data = { link: link, size: size, @@ -2946,13 +2946,13 @@ resolution: resolution, filename: filename }; - return node.innerHTML = FileInfo.funks[FileInfo.ffType](FileInfo); + return node.innerHTML = FileInfo.funks[FileInfo.type](FileInfo); }, setFormats: function() { var code, i, _results; _results = []; for (i = 0; i <= 1; i++) { - code = conf[FileInfo.ffConf[i]].replace(FileInfo.ffMtrs[i], function(s, c) { + code = conf[FileInfo.conf[i]].replace(FileInfo.param[i], function(s, c) { if (c in FileInfo.formatters) { return "' + FileInfo.formatters." + c + "() + '"; } else { @@ -2986,9 +2986,9 @@ } return "" + size + " " + unitT; }, - ffConf: ['fileInfoR', 'fileInfoT'], - ffMtrs: [/%([BKlLMnNrs])/g, /%([BKlMrs])/g], - ffRgex: [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/], + conf: ['fileInfoR', 'fileInfoT'], + param: [/%([BKlLMnNrs])/g, /%([BKlMrs])/g], + regexp: [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/], formatters: { B: function() { return FileInfo.convertUnit('B'); @@ -2997,7 +2997,7 @@ return FileInfo.convertUnit('KB'); }, l: function() { - if (FileInfo.ffType === 0) { + if (FileInfo.type === 0) { return FileInfo.data.link.replace(/>\d+\.\w+' + FileInfo.formatters.n() + '<'); } else { return FileInfo.data.link; diff --git a/script.coffee b/script.coffee index 0d99f65d9..1d21f7489 100644 --- a/script.coffee +++ b/script.coffee @@ -1904,7 +1904,7 @@ options = backlink: -> $.id('backlinkPreview').textContent = conf['backlink'].replace /%id/, '123456789' fileInfo: -> - FileInfo.ffType = if @name is 'fileInfoR' then 0 else 1 + FileInfo.type = if @name is 'fileInfoR' then 0 else 1 FileInfo.data = link : '1329791824.png' size : 996 @@ -1912,7 +1912,7 @@ options = resolution: '1366x768' filename : 'Untitled.png' FileInfo.funks = FileInfo.setFormats() - $.id("#{@name}Preview").innerHTML = FileInfo.funks[FileInfo.ffType] FileInfo + $.id("#{@name}Preview").innerHTML = FileInfo.funks[FileInfo.type] FileInfo favicon: -> Favicon.switch() unread.update true @@ -2402,19 +2402,19 @@ FileInfo = g.callbacks.push @node node: (root) -> return if root.className is 'inline' or not node = $ '.filesize', root - FileInfo.ffType = if node.childElementCount is 2 then 0 else 1 + FileInfo.type = if node.childElementCount is 2 then 0 else 1 [_, link, size, unit, resolution, filename] = - node.innerHTML.match FileInfo.ffRgex[FileInfo.ffType] + node.innerHTML.match FileInfo.regexp[FileInfo.type] FileInfo.data = link: link size: size unit: unit resolution: resolution filename: filename - node.innerHTML = FileInfo.funks[FileInfo.ffType] FileInfo + node.innerHTML = FileInfo.funks[FileInfo.type] FileInfo setFormats: -> for i in [0..1] - code = conf[FileInfo.ffConf[i]].replace FileInfo.ffMtrs[i], (s, c) -> + code = conf[FileInfo.conf[i]].replace FileInfo.param[i], (s, c) -> if c of FileInfo.formatters "' + FileInfo.formatters.#{c}() + '" else @@ -2434,15 +2434,15 @@ FileInfo = if size < 1 and size.toString().length > size.toFixed(2).length size = size.toFixed 2 "#{size} #{unitT}" - ffConf: [ + conf: [ 'fileInfoR' 'fileInfoT' ] - ffMtrs: [ + param: [ /%([BKlLMnNrs])/g /%([BKlMrs])/g ] - ffRgex: [ + regexp: [ /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/ /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/ ] @@ -2450,7 +2450,7 @@ FileInfo = B: -> FileInfo.convertUnit 'B' K: -> FileInfo.convertUnit 'KB' l: -> - if FileInfo.ffType is 0 + if FileInfo.type is 0 FileInfo.data.link.replace />\d+\.\w+' + FileInfo.formatters.n() + '<' else FileInfo.data.link From 27a40c46cf47c74dd1326761438df1fef958c028 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 23:49:01 +0100 Subject: [PATCH 12/14] Deeper FileInfo refactoring. --- 4chan_x.user.js | 63 +++++++++++++++++++++++++----------------------- script.coffee | 64 ++++++++++++++++++++++++------------------------- 2 files changed, 64 insertions(+), 63 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 025489f63..400a7e729 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2320,16 +2320,18 @@ return $.id('backlinkPreview').textContent = conf['backlink'].replace(/%id/, '123456789'); }, fileInfo: function() { - FileInfo.type = this.name === 'fileInfoR' ? 0 : 1; + var type; + type = this.name === 'fileInfoR' ? 0 : 1; FileInfo.data = { link: '1329791824.png', size: 996, unit: 'KB', resolution: '1366x768', - filename: 'Untitled.png' + filename: 'Untitled.png', + type: type }; - FileInfo.funks = FileInfo.setFormats(); - return $.id("" + this.name + "Preview").innerHTML = FileInfo.funks[FileInfo.type](FileInfo); + FileInfo.setFormats(); + return $.id("" + this.name + "Preview").innerHTML = FileInfo.funks[type](FileInfo); }, favicon: function() { Favicon["switch"](); @@ -2931,42 +2933,46 @@ FileInfo = { init: function() { if (g.BOARD === 'f') return; - FileInfo.funks = FileInfo.setFormats(); + this.setFormats(); return g.callbacks.push(this.node); }, node: function(root) { - var filename, link, node, resolution, size, unit, _, _ref; + var filename, link, node, regexp, resolution, size, type, unit, _, _ref; if (root.className === 'inline' || !(node = $('.filesize', root))) return; - FileInfo.type = node.childElementCount === 2 ? 0 : 1; - _ref = node.innerHTML.match(FileInfo.regexp[FileInfo.type]), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], filename = _ref[5]; + type = node.childElementCount === 2 ? 0 : 1; + regexp = [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/][type]; + _ref = node.innerHTML.match(regexp), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], filename = _ref[5]; FileInfo.data = { link: link, size: size, unit: unit, resolution: resolution, - filename: filename + filename: filename, + type: type }; - return node.innerHTML = FileInfo.funks[FileInfo.type](FileInfo); + return node.innerHTML = FileInfo.funks[type](FileInfo); }, setFormats: function() { - var code, i, _results; - _results = []; + var code, format, funks, i, param; + funks = []; for (i = 0; i <= 1; i++) { - code = conf[FileInfo.conf[i]].replace(FileInfo.param[i], function(s, c) { + format = conf[['fileInfoR', 'fileInfoT'][i]]; + param = [/%([BKlLMnNrs])/g, /%([BKlMrs])/g][i]; + code = format.replace(param, function(s, c) { if (c in FileInfo.formatters) { - return "' + FileInfo.formatters." + c + "() + '"; + return "' + f.formatters." + c + "() + '"; } else { return s; } }); - _results.push(Function('FileInfo', "return '" + code + "'")); + funks.push(Function('f', "return '" + code + "'")); } - return _results; + return this.funks = funks; }, convertUnit: function(unitT) { var i, size, unitF, units; - size = FileInfo.data.size; - unitF = FileInfo.data.unit; + size = this.data.size; + unitF = this.data.unit; if (unitF !== unitT) { units = ['B', 'KB', 'MB']; i = units.indexOf(unitF) - units.indexOf(unitT); @@ -2986,9 +2992,6 @@ } return "" + size + " " + unitT; }, - conf: ['fileInfoR', 'fileInfoT'], - param: [/%([BKlLMnNrs])/g, /%([BKlMrs])/g], - regexp: [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/], formatters: { B: function() { return FileInfo.convertUnit('B'); @@ -2996,9 +2999,15 @@ K: function() { return FileInfo.convertUnit('KB'); }, + M: function() { + return FileInfo.convertUnit('MB'); + }, + s: function() { + return "" + FileInfo.data.size + " " + FileInfo.data.unit; + }, l: function() { - if (FileInfo.type === 0) { - return FileInfo.data.link.replace(/>\d+\.\w+' + FileInfo.formatters.n() + '<'); + if (FileInfo.data.type === 0) { + return FileInfo.data.link.replace(/>\d+\.\w+' + this.n() + '<'); } else { return FileInfo.data.link; } @@ -3006,13 +3015,10 @@ L: function() { return FileInfo.data.link.replace(/>\d+\.\w+' + FileInfo.data.filename + '<'); }, - M: function() { - return FileInfo.convertUnit('MB'); - }, n: function() { var ext; if ((ext = FileInfo.data.filename.lastIndexOf('.')) > 38) { - return '' + FileInfo.data.filename + '' + FileInfo.data.filename.substr(0, 32) + ' (...)' + FileInfo.data.filename.substr(ext) + ''; + return "" + FileInfo.data.filename + "" + (FileInfo.data.filename.substr(0, 32)) + "(...)" + (FileInfo.data.filename.substr(ext)) + ""; } else { return FileInfo.data.filename; } @@ -3022,9 +3028,6 @@ }, r: function() { return FileInfo.data.resolution; - }, - s: function() { - return "" + FileInfo.data.size + " " + FileInfo.data.unit; } } }; diff --git a/script.coffee b/script.coffee index 1d21f7489..2cf4239a4 100644 --- a/script.coffee +++ b/script.coffee @@ -1904,15 +1904,16 @@ options = backlink: -> $.id('backlinkPreview').textContent = conf['backlink'].replace /%id/, '123456789' fileInfo: -> - FileInfo.type = if @name is 'fileInfoR' then 0 else 1 + type = if @name is 'fileInfoR' then 0 else 1 FileInfo.data = - link : '1329791824.png' - size : 996 - unit : 'KB' + link: '1329791824.png' + size: 996 + unit: 'KB' resolution: '1366x768' - filename : 'Untitled.png' - FileInfo.funks = FileInfo.setFormats() - $.id("#{@name}Preview").innerHTML = FileInfo.funks[FileInfo.type] FileInfo + filename: 'Untitled.png' + type: type + FileInfo.setFormats() + $.id("#{@name}Preview").innerHTML = FileInfo.funks[type] FileInfo favicon: -> Favicon.switch() unread.update true @@ -2398,31 +2399,40 @@ Time = FileInfo = init: -> return if g.BOARD is 'f' - FileInfo.funks = FileInfo.setFormats() + @setFormats() g.callbacks.push @node node: (root) -> return if root.className is 'inline' or not node = $ '.filesize', root - FileInfo.type = if node.childElementCount is 2 then 0 else 1 + type = if node.childElementCount is 2 then 0 else 1 + regexp = [ + /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/ + /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/ + ][type] [_, link, size, unit, resolution, filename] = - node.innerHTML.match FileInfo.regexp[FileInfo.type] + node.innerHTML.match regexp FileInfo.data = link: link size: size unit: unit resolution: resolution filename: filename - node.innerHTML = FileInfo.funks[FileInfo.type] FileInfo + type: type + node.innerHTML = FileInfo.funks[type] FileInfo setFormats: -> + funks = [] for i in [0..1] - code = conf[FileInfo.conf[i]].replace FileInfo.param[i], (s, c) -> + format = conf[['fileInfoR', 'fileInfoT'][i]] + param = [/%([BKlLMnNrs])/g, /%([BKlMrs])/g][i] + code = format.replace param, (s, c) -> if c of FileInfo.formatters - "' + FileInfo.formatters.#{c}() + '" + "' + f.formatters.#{c}() + '" else s - Function 'FileInfo', "return '#{code}'" + funks.push Function 'f', "return '#{code}'" + @funks = funks convertUnit: (unitT) -> - size = FileInfo.data.size - unitF = FileInfo.data.unit + size = @data.size + unitF = @data.unit if unitF isnt unitT units = ['B', 'KB', 'MB'] i = units.indexOf(unitF) - units.indexOf unitT @@ -2434,36 +2444,24 @@ FileInfo = if size < 1 and size.toString().length > size.toFixed(2).length size = size.toFixed 2 "#{size} #{unitT}" - conf: [ - 'fileInfoR' - 'fileInfoT' - ] - param: [ - /%([BKlLMnNrs])/g - /%([BKlMrs])/g - ] - regexp: [ - /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/ - /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/ - ] formatters: B: -> FileInfo.convertUnit 'B' K: -> FileInfo.convertUnit 'KB' + M: -> FileInfo.convertUnit 'MB' + s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}" l: -> - if FileInfo.type is 0 - FileInfo.data.link.replace />\d+\.\w+' + FileInfo.formatters.n() + '<' + if FileInfo.data.type is 0 + FileInfo.data.link.replace />\d+\.\w+' + @n() + '<' else FileInfo.data.link L: -> FileInfo.data.link.replace />\d+\.\w+' + FileInfo.data.filename + '<' - M: -> FileInfo.convertUnit 'MB' n: -> if (ext = FileInfo.data.filename.lastIndexOf '.') > 38 - '' + FileInfo.data.filename + '' + FileInfo.data.filename.substr(0, 32) + ' (...)' + FileInfo.data.filename.substr(ext) + '' + "#{FileInfo.data.filename}#{FileInfo.data.filename.substr 0, 32}(...)#{FileInfo.data.filename.substr ext}" else FileInfo.data.filename N: -> FileInfo.data.filename r: -> FileInfo.data.resolution - s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}" getTitle = (thread) -> el = $ '.filetitle', thread From 6cc786cba6b68205069bd6b22bcc3e8c9d13d4ea Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 1 Mar 2012 00:26:35 +0100 Subject: [PATCH 13/14] Simpler filename truncated/full. --- 4chan_x.user.js | 62 +++++++++++++++++++++++++------------------------ script.coffee | 39 +++++++++++++++++-------------- 2 files changed, 53 insertions(+), 48 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 400a7e729..e5e2d61e2 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2327,7 +2327,8 @@ size: 996, unit: 'KB', resolution: '1366x768', - filename: 'Untitled.png', + fullname: '[a.f.k.] Sayonara Zetsubou Sensei - 09.avi_snapshot_03.34_[2011.02.20_06.58.00].jpg', + shortname: '[a.f.k.] Sayonara Zetsubou Sen(...).jpg', type: type }; FileInfo.setFormats(); @@ -2937,17 +2938,18 @@ return g.callbacks.push(this.node); }, node: function(root) { - var filename, link, node, regexp, resolution, size, type, unit, _, _ref; + var fullname, link, node, regexp, resolution, shortname, size, type, unit, _, _ref; if (root.className === 'inline' || !(node = $('.filesize', root))) return; type = node.childElementCount === 2 ? 0 : 1; - regexp = [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/][type]; - _ref = node.innerHTML.match(regexp), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], filename = _ref[5]; + regexp = [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s([^<]+)/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/][type]; + _ref = node.innerHTML.match(regexp), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], fullname = _ref[5], shortname = _ref[6]; FileInfo.data = { link: link, size: size, unit: unit, resolution: resolution, - filename: filename, + fullname: fullname, + shortname: shortname, type: type }; return node.innerHTML = FileInfo.funks[type](FileInfo); @@ -2993,6 +2995,29 @@ return "" + size + " " + unitT; }, formatters: { + l: function() { + if (FileInfo.data.type === 0) { + return FileInfo.data.link.replace(/>\d+\.\w+" + (this.n()) + "<"); + } else { + return FileInfo.data.link; + } + }, + L: function() { + return FileInfo.data.link.replace(/>\d+\.\w+" + FileInfo.data.fullname + "<"); + }, + n: function() { + if (FileInfo.data.fullname === FileInfo.data.shortname) { + return FileInfo.data.fullname; + } else { + return "" + FileInfo.data.fullname + "" + FileInfo.data.shortname + ""; + } + }, + N: function() { + return FileInfo.data.fullname; + }, + s: function() { + return "" + FileInfo.data.size + " " + FileInfo.data.unit; + }, B: function() { return FileInfo.convertUnit('B'); }, @@ -3002,30 +3027,6 @@ M: function() { return FileInfo.convertUnit('MB'); }, - s: function() { - return "" + FileInfo.data.size + " " + FileInfo.data.unit; - }, - l: function() { - if (FileInfo.data.type === 0) { - return FileInfo.data.link.replace(/>\d+\.\w+' + this.n() + '<'); - } else { - return FileInfo.data.link; - } - }, - L: function() { - return FileInfo.data.link.replace(/>\d+\.\w+' + FileInfo.data.filename + '<'); - }, - n: function() { - var ext; - if ((ext = FileInfo.data.filename.lastIndexOf('.')) > 38) { - return "" + FileInfo.data.filename + "" + (FileInfo.data.filename.substr(0, 32)) + "(...)" + (FileInfo.data.filename.substr(ext)) + ""; - } else { - return FileInfo.data.filename; - } - }, - N: function() { - return FileInfo.data.filename; - }, r: function() { return FileInfo.data.resolution; } @@ -4135,7 +4136,8 @@ td.replyhider {\ float: left;\ pointer-events: none;\ }\ -.filesize a:not(:hover) .fnfull, .filesize a:hover .fntrunc {\ +.filename:hover > .fntrunc,\ +.filename:not(:hover) > .fnfull {\ display: none;\ }\ img[md5], img[md5] + img {\ diff --git a/script.coffee b/script.coffee index 2cf4239a4..70a48ac68 100644 --- a/script.coffee +++ b/script.coffee @@ -1910,7 +1910,8 @@ options = size: 996 unit: 'KB' resolution: '1366x768' - filename: 'Untitled.png' + fullname: '[a.f.k.] Sayonara Zetsubou Sensei - 09.avi_snapshot_03.34_[2011.02.20_06.58.00].jpg' + shortname: '[a.f.k.] Sayonara Zetsubou Sen(...).jpg' type: type FileInfo.setFormats() $.id("#{@name}Preview").innerHTML = FileInfo.funks[type] FileInfo @@ -2405,17 +2406,18 @@ FileInfo = return if root.className is 'inline' or not node = $ '.filesize', root type = if node.childElementCount is 2 then 0 else 1 regexp = [ - /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s/ + /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s([^<]+)/ /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/ ][type] - [_, link, size, unit, resolution, filename] = + [_, link, size, unit, resolution, fullname, shortname] = node.innerHTML.match regexp FileInfo.data = link: link size: size unit: unit resolution: resolution - filename: filename + fullname: fullname + shortname: shortname type: type node.innerHTML = FileInfo.funks[type] FileInfo setFormats: -> @@ -2445,22 +2447,22 @@ FileInfo = size = size.toFixed 2 "#{size} #{unitT}" formatters: + l: -> + if FileInfo.data.type is 0 + FileInfo.data.link.replace />\d+\.\w+#{@n()}<" + else + FileInfo.data.link + L: -> FileInfo.data.link.replace />\d+\.\w+#{FileInfo.data.fullname}<" + n: -> + if FileInfo.data.fullname is FileInfo.data.shortname + FileInfo.data.fullname + else + "#{FileInfo.data.fullname}#{FileInfo.data.shortname}" + N: -> FileInfo.data.fullname + s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}" B: -> FileInfo.convertUnit 'B' K: -> FileInfo.convertUnit 'KB' M: -> FileInfo.convertUnit 'MB' - s: -> "#{FileInfo.data.size} #{FileInfo.data.unit}" - l: -> - if FileInfo.data.type is 0 - FileInfo.data.link.replace />\d+\.\w+' + @n() + '<' - else - FileInfo.data.link - L: -> FileInfo.data.link.replace />\d+\.\w+' + FileInfo.data.filename + '<' - n: -> - if (ext = FileInfo.data.filename.lastIndexOf '.') > 38 - "#{FileInfo.data.filename}#{FileInfo.data.filename.substr 0, 32}(...)#{FileInfo.data.filename.substr ext}" - else - FileInfo.data.filename - N: -> FileInfo.data.filename r: -> FileInfo.data.resolution getTitle = (thread) -> @@ -3428,7 +3430,8 @@ td.replyhider { float: left; pointer-events: none; } -.filesize a:not(:hover) .fnfull, .filesize a:hover .fntrunc { +.filename:hover > .fntrunc, +.filename:not(:hover) > .fnfull { display: none; } img[md5], img[md5] + img { From 379a7d8bf9efd4087fc8014ec10764adb87c72dd Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 1 Mar 2012 00:57:20 +0100 Subject: [PATCH 14/14] Shorter regexps and less arrays. --- 4chan_x.user.js | 8 ++++---- script.coffee | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index e5e2d61e2..ed337dab3 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2181,7 +2181,7 @@
  • :
  • \
  • Link: %l (lowercase L)
  • \
  • Size: %B (Bytes), %K (KB), %M (MB), %s (4chan default)
  • \ -
  • Resolution: %r (Displays PDF on /po/, for PDF\'s)
  • \ +
  • Resolution: %r (Displays PDF on /po/, for PDFs)
  • \ Reply File Info Formatting\
  • :
  • \
  • All thread formatters also work for reply formatting.
  • \ @@ -2941,7 +2941,7 @@ var fullname, link, node, regexp, resolution, shortname, size, type, unit, _, _ref; if (root.className === 'inline' || !(node = $('.filesize', root))) return; type = node.childElementCount === 2 ? 0 : 1; - regexp = [/File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s([^<]+)/, /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/][type]; + regexp = type ? /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF)/ : /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF), ([^<]+)/; _ref = node.innerHTML.match(regexp), _ = _ref[0], link = _ref[1], size = _ref[2], unit = _ref[3], resolution = _ref[4], fullname = _ref[5], shortname = _ref[6]; FileInfo.data = { link: link, @@ -2958,8 +2958,8 @@ var code, format, funks, i, param; funks = []; for (i = 0; i <= 1; i++) { - format = conf[['fileInfoR', 'fileInfoT'][i]]; - param = [/%([BKlLMnNrs])/g, /%([BKlMrs])/g][i]; + format = i ? conf['fileInfoT'] : conf['fileInfoR']; + param = i ? /%([BKlMrs])/g : /%([BKlLMnNrs])/g; code = format.replace(param, function(s, c) { if (c in FileInfo.formatters) { return "' + f.formatters." + c + "() + '"; diff --git a/script.coffee b/script.coffee index 70a48ac68..a3d0a2d6f 100644 --- a/script.coffee +++ b/script.coffee @@ -1778,7 +1778,7 @@ options =
  • :
  • Link: %l (lowercase L)
  • Size: %B (Bytes), %K (KB), %M (MB), %s (4chan default)
  • -
  • Resolution: %r (Displays PDF on /po/, for PDF\'s)
  • +
  • Resolution: %r (Displays PDF on /po/, for PDFs)
  • Reply File Info Formatting
  • :
  • All thread formatters also work for reply formatting.
  • @@ -2405,10 +2405,11 @@ FileInfo = node: (root) -> return if root.className is 'inline' or not node = $ '.filesize', root type = if node.childElementCount is 2 then 0 else 1 - regexp = [ - /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF),\s([^<]+)/ - /File:\s()-\((?:Spoiler Image,\s)?([\d\.]+)\s([BKM]{1,2}),\s(\d+x\d+|PDF)\)/ - ][type] + regexp = + if type + /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF)/ + else + /^File: (<.+>)-\((?:Spoiler Image, )?([\d\.]+) (\w+), (\d+x\d+|PDF), ([^<]+)/ [_, link, size, unit, resolution, fullname, shortname] = node.innerHTML.match regexp FileInfo.data = @@ -2423,8 +2424,8 @@ FileInfo = setFormats: -> funks = [] for i in [0..1] - format = conf[['fileInfoR', 'fileInfoT'][i]] - param = [/%([BKlLMnNrs])/g, /%([BKlMrs])/g][i] + format = if i then conf['fileInfoT'] else conf['fileInfoR'] + param = if i then /%([BKlMrs])/g else /%([BKlLMnNrs])/g code = format.replace param, (s, c) -> if c of FileInfo.formatters "' + f.formatters.#{c}() + '"