diff --git a/4chan_x.user.js b/4chan_x.user.js index afb728aa7..1eae1a1b8 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -20,7 +20,7 @@ // @icon https://github.com/MayhemYDG/4chan-x/raw/stable/img/icon.gif // ==/UserScript== -/* 4chan X Alpha - Version 3.0.0 - 2012-10-17 +/* 4chan X Alpha - Version 3.0.0 - 2012-10-25 * http://mayhemydg.github.com/4chan-x/ * * Copyright (c) 2009-2011 James Campos @@ -702,7 +702,7 @@ case 'mu': case 'soc': case 'w': - return "//archive.rebeccablacktech.com/" + board + "/full_image/" + filename; + return "//rbt.asia/" + board + "/full_image/" + filename; case 'an': case 'fit': case 'k': @@ -734,12 +734,9 @@ return "//nsfw.foolz.us/_/api/chan/post/?board=" + board + "&num=" + postID; } }, - thread: function(board, threadID, postID) { - var path, url; - if (postID) { - postID = postID.match(/\d+/)[0]; - } - path = threadID ? "" + board + "/thread/" + threadID : "" + board + "/post/" + postID; + to: function(data) { + var board, url; + board = data.board; switch ("" + board) { case 'a': case 'co': @@ -754,41 +751,26 @@ case 'wsg': case 'dev': case 'foolz': - url = "//archive.foolz.us/" + path + "/"; - if (threadID && postID) { - url += "#" + postID; - } + url = Redirect.path('//archive.foolz.us', 'foolfuuka', data); break; case 'u': case 'kuku': - url = "//nsfw.foolz.us/" + path + "/"; - if (threadID && postID) { - url += "#" + postID; - } + url = Redirect.path('//nsfw.foolz.us', 'foolfuuka', data); break; case 'ck': case 'lit': - url = "//fuuka.warosu.org/" + path; - if (threadID && postID) { - url += "#p" + postID; - } + url = Redirect.path('//fuuka.warosu.org', 'fuuka', data); break; case 'diy': - case 'g': case 'sci': - url = "//archive.installgentoo.net/" + path; - if (threadID && postID) { - url += "#p" + postID; - } + url = Redirect.path('//archive.installgentoo.net', 'fuuka', data); break; case 'cgl': + case 'g': case 'mu': case 'soc': case 'w': - url = "//archive.rebeccablacktech.com/" + path; - if (threadID && postID) { - url += "#p" + postID; - } + url = Redirect.path('//rbt.asia', 'fuuka', data); break; case 'an': case 'fit': @@ -797,23 +779,38 @@ case 'r9k': case 'toy': case 'x': - url = "http://archive.heinessen.com/" + path; - if (threadID && postID) { - url += "#p" + postID; - } - break; - case 'e': - url = "https://www.cliché.net/4chan/cgi-board.pl/" + path; - if (threadID && postID) { - url += "#p" + postID; - } + url = Redirect.path('http://archive.heinessen.com', 'fuuka', data); break; default: - if (threadID) { + if (data.threadID) { url = "//boards.4chan.org/" + board + "/"; } } return url || ''; + }, + path: function(base, archiver, data) { + var board, path, postID, threadID, type, value; + if (data.isSearch) { + board = data.board, type = data.type, value = data.value; + type = type === 'name' ? 'username' : type === 'md5' ? 'image' : type; + value = encodeURIComponent(value); + if (archiver === 'foolfuuka') { + return "" + base + "/" + board + "/search/" + type + "/" + value; + } else if (type === 'image') { + return "" + base + "/" + board + "/?task=search2&search_media_hash=" + value; + } else { + return "" + base + "/" + board + "/?task=search2&search_" + type + "=" + value; + } + } + board = data.board, threadID = data.threadID, postID = data.postID; + if (postID) { + postID = postID.match(/\d+/)[0]; + } + path = threadID ? "" + board + "/thread/" + threadID : "" + board + "/post/" + postID; + if (threadID && postID) { + path += archiver === 'foolfuuka' ? "#" + postID : "#p" + postID; + } + return "" + base + "/" + path; } }; @@ -1198,7 +1195,11 @@ if (post = g.posts[quoteID]) { if (post.isDead) { a = $.el('a', { - href: Redirect.thread(board, 0, ID), + href: Redirect.to({ + board: board, + threadID: 0, + postID: ID + }), className: 'quotelink deadlink', textContent: "" + quote + "\u00A0(Dead)", target: '_blank' @@ -1215,7 +1216,11 @@ } } else { a = $.el('a', { - href: Redirect.thread(board, 0, ID), + href: Redirect.to({ + board: board, + threadID: 0, + postID: ID + }), className: 'deadlink', target: '_blank', textContent: "" + quote + "\u00A0(Dead)" @@ -1703,7 +1708,7 @@ }, createFunc: function(format) { var code; - code = format.replace(/%([BKlLMnNprs])/g, function(s, c) { + code = format.replace(/%(.)/g, function(s, c) { if (c in FileInfo.formatters) { return "' + FileInfo.formatters." + c + ".call(post) + '"; } else { @@ -1730,6 +1735,12 @@ }); }, formatters: { + t: function() { + return this.file.URL.match(/\d+\..+$/)[0]; + }, + T: function() { + return "" + (FileInfo.formatters.t.call(this)) + ""; + }, l: function() { return "" + (FileInfo.formatters.n.call(this)) + ""; }, @@ -2776,7 +2787,11 @@ var boardChild, posts, thread, threadChild, threads, _i, _j, _len, _len1, _ref, _ref1; if (d.title === '4chan - 404 Not Found') { if (Conf['404 Redirect'] && g.REPLY) { - location.href = Redirect.thread(g.BOARD, g.THREAD, location.hash); + location.href = Redirect.to({ + board: g.BOARD, + threadID: g.THREAD, + postID: location.hash + }); } return; } diff --git a/changelog b/changelog index d06b1a289..01529fcf5 100644 --- a/changelog +++ b/changelog @@ -8,6 +8,12 @@ alpha master +2.36.1 +- noface + The Menu now has search links for Archivers. +- Mayhem + Added possibility to display unix timestamps with File Info Formatting. + 2.36.0 - Mayhem Added thread creation QR cooldown. diff --git a/latest.js b/latest.js index be75ff81d..a000e475e 100644 --- a/latest.js +++ b/latest.js @@ -1 +1 @@ -postMessage({version:'2.36.0'},'*') \ No newline at end of file +postMessage({version:'2.36.1'},'*') \ No newline at end of file diff --git a/src/features.coffee b/src/features.coffee index c55dcaee8..18c3f4329 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -12,11 +12,9 @@ Redirect = when 'diy', 'sci' "//archive.installgentoo.net/#{board}/full_image/#{filename}" when 'cgl', 'g', 'mu', 'soc', 'w' - "//archive.rebeccablacktech.com/#{board}/full_image/#{filename}" + "//rbt.asia/#{board}/full_image/#{filename}" when 'an', 'fit', 'k', 'mlp', 'r9k', 'toy', 'x' "http://archive.heinessen.com/#{board}/full_image/#{filename}" - # when 'e' - # "https://www.cliché.net/4chan/cgi-board.pl/#{board}/full_image/#{filename}" post: (board, postID) -> switch board when 'a', 'co', 'jp', 'm', 'q', 'sp', 'tg', 'tv', 'v', 'vg', 'wsg', 'dev', 'foolz' @@ -25,47 +23,58 @@ Redirect = "//nsfw.foolz.us/_/api/chan/post/?board=#{board}&num=#{postID}" # for fuuka-based archives: # https://github.com/eksopl/fuuka/issues/27 - thread: (board, threadID, postID) -> - # keep the number only, if the location.hash was sent f.e. + to: (data) -> + {board} = data + switch "#{board}" + when 'a', 'co', 'jp', 'm', 'q', 'sp', 'tg', 'tv', 'v', 'vg', 'wsg', 'dev', 'foolz' + url = Redirect.path '//archive.foolz.us', 'foolfuuka', data + when 'u', 'kuku' + url = Redirect.path '//nsfw.foolz.us', 'foolfuuka', data + when 'ck', 'lit' + url = Redirect.path '//fuuka.warosu.org', 'fuuka', data + when 'diy', 'sci' + url = Redirect.path '//archive.installgentoo.net', 'fuuka', data + when 'cgl', 'g', 'mu', 'soc', 'w' + url = Redirect.path '//rbt.asia', 'fuuka', data + when 'an', 'fit', 'k', 'mlp', 'r9k', 'toy', 'x' + url = Redirect.path 'http://archive.heinessen.com', 'fuuka', data + else + if data.threadID + url = "//boards.4chan.org/#{board}/" + url or '' + path: (base, archiver, data) -> + if data.isSearch + {board, type, value} = data + type = + if type is 'name' + 'username' + else if type is 'md5' + 'image' + else + type + value = encodeURIComponent value + return if archiver is 'foolfuuka' + "#{base}/#{board}/search/#{type}/#{value}" + else if type is 'image' + "#{base}/#{board}/?task=search2&search_media_hash=#{value}" + else + "#{base}/#{board}/?task=search2&search_#{type}=#{value}" + + {board, threadID, postID} = data + # keep the number only if the location.hash was sent f.e. postID = postID.match(/\d+/)[0] if postID - path = + path = if threadID "#{board}/thread/#{threadID}" else "#{board}/post/#{postID}" - switch "#{board}" - when 'a', 'co', 'jp', 'm', 'q', 'sp', 'tg', 'tv', 'v', 'vg', 'wsg', 'dev', 'foolz' - url = "//archive.foolz.us/#{path}/" - if threadID and postID - url += "##{postID}" - when 'u', 'kuku' - url = "//nsfw.foolz.us/#{path}/" - if threadID and postID - url += "##{postID}" - when 'ck', 'lit' - url = "//fuuka.warosu.org/#{path}" - if threadID and postID - url += "#p#{postID}" - when 'diy', 'g', 'sci' - url = "//archive.installgentoo.net/#{path}" - if threadID and postID - url += "#p#{postID}" - when 'cgl', 'mu', 'soc', 'w' - url = "//archive.rebeccablacktech.com/#{path}" - if threadID and postID - url += "#p#{postID}" - when 'an', 'fit', 'k', 'mlp', 'r9k', 'toy', 'x' - url = "http://archive.heinessen.com/#{path}" - if threadID and postID - url += "#p#{postID}" - when 'e' - url = "https://www.cliché.net/4chan/cgi-board.pl/#{path}" - if threadID and postID - url += "#p#{postID}" - else - if threadID - url = "//boards.4chan.org/#{board}/" - url or '' + if threadID and postID + path += + if archiver is 'foolfuuka' + "##{postID}" + else + "#p#{postID}" + "#{base}/#{path}" Build = spoilerRange: {} @@ -553,7 +562,10 @@ Quotify = if post = g.posts[quoteID] if post.isDead a = $.el 'a', - href: Redirect.thread board, 0, ID + href: Redirect.to + board: board + threadID: 0 + postID: ID className: 'quotelink deadlink' textContent: "#{quote}\u00A0(Dead)" target: '_blank' @@ -569,7 +581,10 @@ Quotify = textContent: quote else a = $.el 'a', - href: Redirect.thread board, 0, ID + href: Redirect.to + board: board + threadID: 0 + postID: ID className: 'deadlink' target: '_blank' textContent: "#{quote}\u00A0(Dead)" @@ -934,7 +949,7 @@ FileInfo = return if !@file or @isClone @file.text.innerHTML = FileInfo.funk FileInfo, @ createFunc: (format) -> - code = format.replace /%([BKlLMnNprs])/g, (s, c) -> + code = format.replace /%(.)/g, (s, c) -> if c of FileInfo.formatters "' + FileInfo.formatters.#{c}.call(post) + '" else @@ -955,6 +970,8 @@ FileInfo = name.replace /<|>/g, (c) -> c is '<' and '<' or '>' formatters: + t: -> @file.URL.match(/\d+\..+$/)[0] + T: -> "#{FileInfo.formatters.t.call @}" l: -> "#{FileInfo.formatters.n.call @}" L: -> "#{FileInfo.formatters.N.call @}" n: -> diff --git a/src/main.coffee b/src/main.coffee index 44e01e913..d48bf025c 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -459,7 +459,10 @@ Main = initFeaturesReady: -> if d.title is '4chan - 404 Not Found' if Conf['404 Redirect'] and g.REPLY - location.href = Redirect.thread g.BOARD, g.THREAD, location.hash + location.href = Redirect.to + board: g.BOARD + threadID: g.THREAD + postID: location.hash return return unless $.id 'navtopright'