From dfc703fdfced1bb5d49d7981b6b534074932cb01 Mon Sep 17 00:00:00 2001 From: noface Date: Sat, 20 Oct 2012 00:59:54 +0200 Subject: [PATCH 1/2] Add Archivers submenu. --- 4chan_x.user.js | 123 ++++++++++++++++++++++++++++++++++++------------ changelog | 2 + script.coffee | 111 ++++++++++++++++++++++++++++++++----------- 3 files changed, 177 insertions(+), 59 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 21452abc4..c7b688270 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -4499,25 +4499,65 @@ }; ArchiveLink = { - init: function() { - var a; - a = $.el('a', { - className: 'archive_link', - target: '_blank', - textContent: 'Archived post' + init: function(post) { + var div, entry, type, _i, _len, _ref; + div = $.el('div', { + textContent: 'Archive' }); - return Menu.addEntry({ - el: a, + entry = { + el: div, open: function(post) { - var href, path; + var path; path = $('a[title="Highlight this post"]', post.el).pathname.split('/'); - if ((href = Redirect.thread(path[1], path[3], post.ID)) === ("//boards.4chan.org/" + path[1] + "/")) { + if ((Redirect.thread(path[1], path[3], post.ID)) === ("//boards.4chan.org/" + path[1] + "/")) { return false; } - a.href = href; return true; - } + }, + children: [] + }; + _ref = [['Post', 'apost'], ['Name', 'name'], ['Tripcode', 'tripcode'], ['E-mail', 'email'], ['Subject', 'subject'], ['Filename', 'filename'], ['Image MD5', 'md5']]; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + type = _ref[_i]; + entry.children.push(this.createSubEntry(type[0], type[1])); + } + return Menu.addEntry(entry); + }, + createSubEntry: function(text, type) { + var el, open; + el = $.el('a', { + textContent: text, + target: '_blank' }); + open = function(post) { + var path, value; + path = $('a[title="Highlight this post"]', post.el).pathname.split('/'); + if (type !== 'apost') { + value = Filter[type](post); + } + if (value === false) { + return false; + } + switch (type) { + case 'name': + if (value === 'Anonymous' || value.length === 0) { + return false; + } + break; + case 'email': + if (value === 'sage' || value.length === 0) { + return false; + } + break; + case 'apost': + return el.href = Redirect.thread(path[1], path[3], post.ID); + } + return el.href = Redirect.thread(path[1], value, type, true); + }; + return { + el: el, + open: open + }; } }; @@ -4737,12 +4777,33 @@ 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; + thread: function(board, threadID, postID, AL) { + var ar, path, url; + ar = function(a) { + var path; + if (AL) { + if (postID === 'name') { + postID = 'username'; + } + if (postID === 'md5') { + postID = 'image'; + } + if (a === 'fuuka') { + return "" + board + "/search/" + postID + "/" + (encodeURIComponent(threadID)); + } else if (a === 'gentoo') { + if (postID === 'image') { + return "" + board + "/image/" + (encodeURIComponent(threadID)); + } else { + return "" + board + "/?task=search2&search_" + postID + "=" + (encodeURIComponent(threadID)); + } + } + } else { + if (postID) { + postID = postID.match(/\d+/)[0]; + } + return path = threadID ? "" + board + "/thread/" + threadID : "" + board + "/post/" + postID; + } + }; switch (board) { case 'a': case 'co': @@ -4757,30 +4818,34 @@ case 'wsg': case 'dev': case 'foolz': + path = ar('fuuka'); url = "//archive.foolz.us/" + path + "/"; - if (threadID && postID) { + if (threadID && postID && !AL) { url += "#" + postID; } break; case 'u': case 'kuku': + path = ar('fuuka'); url = "//nsfw.foolz.us/" + path + "/"; - if (threadID && postID) { + if (threadID && postID && !AL) { url += "#" + postID; } break; case 'ck': case 'lit': + path = ar('fuuka'); url = "//fuuka.warosu.org/" + path; - if (threadID && postID) { - url += "#p" + postID; + if (threadID && postID && !AL) { + url += "#" + postID; } break; case 'diy': case 'g': case 'sci': + path = ar('gentoo'); url = "//archive.installgentoo.net/" + path; - if (threadID && postID) { + if (threadID && postID && !AL) { url += "#p" + postID; } break; @@ -4788,8 +4853,9 @@ case 'mu': case 'soc': case 'w': + path = ar('gentoo'); url = "//archive.rebeccablacktech.com/" + path; - if (threadID && postID) { + if (threadID && postID && !AL) { url += "#p" + postID; } break; @@ -4800,14 +4866,9 @@ case 'r9k': case 'toy': case 'x': + path = ar('gentoo'); 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) { + if (threadID && postID && !AL) { url += "#p" + postID; } break; diff --git a/changelog b/changelog index 161d71413..bad127f66 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ master +- noface + Archives now populate a submenu just like the quicklinks for the Filter. 2.36.0 - Mayhem diff --git a/script.coffee b/script.coffee index 7b8445352..2e1424dad 100644 --- a/script.coffee +++ b/script.coffee @@ -3695,19 +3695,56 @@ DownloadLink = true ArchiveLink = - init: -> - a = $.el 'a', - className: 'archive_link' - target: '_blank' - textContent: 'Archived post' - Menu.addEntry - el: a - open: (post) -> + init: (post) -> + div = $.el 'div', + textContent: 'Archive' + + entry = + el: div + open: (post) -> path = $('a[title="Highlight this post"]', post.el).pathname.split '/' - if (href = Redirect.thread path[1], path[3], post.ID) is "//boards.4chan.org/#{path[1]}/" + if (Redirect.thread path[1], path[3], post.ID) is "//boards.4chan.org/#{path[1]}/" return false - a.href = href true + children: [] + + for type in [ + ['Post', 'apost'] + ['Name', 'name'] + ['Tripcode', 'tripcode'] + ['E-mail', 'email'] + ['Subject', 'subject'] + ['Filename', 'filename'] + ['Image MD5', 'md5'] + ] + # Add a sub entry for each filter type. + entry.children.push @createSubEntry type[0], type[1] + + Menu.addEntry entry + + createSubEntry: (text, type) -> + el = $.el 'a', + textContent: text + target: '_blank' + + open = (post) -> + path = $('a[title="Highlight this post"]', post.el).pathname.split '/' + unless type is 'apost' + value = Filter[type] post + # We want to parse the exact same stuff as Filter does already + maybe a few extras. + return false if value is false + switch type + when 'name' + if value is 'Anonymous' or value.length is 0 + return false + when 'email' + if value is 'sage' or value.length is 0 + return false + when 'apost' + return el.href = Redirect.thread path[1], path[3], post.ID + el.href = Redirect.thread path[1], value, type, true + + return el: el, open: open ThreadStats = init: -> @@ -3873,43 +3910,61 @@ Redirect = "//archive.foolz.us/_/api/chan/post/?board=#{board}&num=#{postID}" when 'u', 'kuku' "//nsfw.foolz.us/_/api/chan/post/?board=#{board}&num=#{postID}" - thread: (board, threadID, postID) -> - # keep the number only if the location.hash was sent f.e. - postID = postID.match(/\d+/)[0] if postID - path = - if threadID - "#{board}/thread/#{threadID}" + thread: (board, threadID, postID, AL) -> + ar = (a) -> + if AL + postID = 'username' if postID is 'name' + postID = 'image' if postID is 'md5' + if a is 'fuuka' + return "#{board}/search/#{postID}/#{encodeURIComponent threadID}" + else if a is 'gentoo' + if postID is 'image' + "#{board}/image/#{encodeURIComponent threadID}" + else + "#{board}/?task=search2&search_#{postID}=#{encodeURIComponent threadID}" else - "#{board}/post/#{postID}" + # keep the number only if the location.hash was sent f.e. + postID = postID.match(/\d+/)[0] if postID + 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' + path = ar 'fuuka' url = "//archive.foolz.us/#{path}/" - if threadID and postID + if threadID and postID and !AL url += "##{postID}" when 'u', 'kuku' + path = ar 'fuuka' url = "//nsfw.foolz.us/#{path}/" - if threadID and postID + if threadID and postID and !AL url += "##{postID}" when 'ck', 'lit' + path = ar 'fuuka' url = "//fuuka.warosu.org/#{path}" - if threadID and postID - url += "#p#{postID}" + if threadID and postID and !AL + url += "##{postID}" when 'diy', 'g', 'sci' + path = ar 'gentoo' url = "//archive.installgentoo.net/#{path}" - if threadID and postID + if threadID and postID and !AL url += "#p#{postID}" when 'cgl', 'mu', 'soc', 'w' + path = ar 'gentoo' url = "//archive.rebeccablacktech.com/#{path}" - if threadID and postID + if threadID and postID and !AL url += "#p#{postID}" when 'an', 'fit', 'k', 'mlp', 'r9k', 'toy', 'x' + path = ar 'gentoo' 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 + if threadID and postID and !AL 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}/" From 5f87b2d84995e88560e1c97df4d306ff924f1146 Mon Sep 17 00:00:00 2001 From: noface Date: Sat, 20 Oct 2012 16:08:11 +0200 Subject: [PATCH 2/2] Corrections. --- 4chan_x.user.js | 150 ++++++++++++++++++++++-------------------------- changelog | 2 +- script.coffee | 149 ++++++++++++++++++++++++----------------------- 3 files changed, 147 insertions(+), 154 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index c7b688270..fe6e1ae37 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -4295,7 +4295,11 @@ a.href = "#p" + id; a.className = 'quotelink'; } else { - a.href = Redirect.thread(board, 0, id); + a.href = Redirect.to({ + board: board, + threadID: 0, + postID: id + }); a.className = 'deadlink'; a.target = '_blank'; if (Redirect.post(board, id)) { @@ -4499,7 +4503,7 @@ }; ArchiveLink = { - init: function(post) { + init: function() { var div, entry, type, _i, _len, _ref; div = $.el('div', { textContent: 'Archive' @@ -4509,9 +4513,14 @@ open: function(post) { var path; path = $('a[title="Highlight this post"]', post.el).pathname.split('/'); - if ((Redirect.thread(path[1], path[3], post.ID)) === ("//boards.4chan.org/" + path[1] + "/")) { + if ((Redirect.to({ + board: path[1], + threadID: path[3], + postID: post.ID + })) === ("//boards.4chan.org/" + path[1] + "/")) { return false; } + post.info = [path[1], path[3]]; return true; }, children: [] @@ -4530,29 +4539,25 @@ target: '_blank' }); open = function(post) { - var path, value; - path = $('a[title="Highlight this post"]', post.el).pathname.split('/'); - if (type !== 'apost') { - value = Filter[type](post); + var value; + if (type === 'apost') { + el.href = Redirect.to({ + board: post.info[0], + threadID: post.info[1], + postID: post.ID + }); + return true; } - if (value === false) { + value = Filter[type](post); + if (!value) { return false; } - switch (type) { - case 'name': - if (value === 'Anonymous' || value.length === 0) { - return false; - } - break; - case 'email': - if (value === 'sage' || value.length === 0) { - return false; - } - break; - case 'apost': - return el.href = Redirect.thread(path[1], path[3], post.ID); - } - return el.href = Redirect.thread(path[1], value, type, true); + return el.href = Redirect.to({ + board: post.info[0], + type: type, + value: value, + isSearch: true + }); }; return { el: el, @@ -4777,33 +4782,12 @@ return "//nsfw.foolz.us/_/api/chan/post/?board=" + board + "&num=" + postID; } }, - thread: function(board, threadID, postID, AL) { - var ar, path, url; - ar = function(a) { - var path; - if (AL) { - if (postID === 'name') { - postID = 'username'; - } - if (postID === 'md5') { - postID = 'image'; - } - if (a === 'fuuka') { - return "" + board + "/search/" + postID + "/" + (encodeURIComponent(threadID)); - } else if (a === 'gentoo') { - if (postID === 'image') { - return "" + board + "/image/" + (encodeURIComponent(threadID)); - } else { - return "" + board + "/?task=search2&search_" + postID + "=" + (encodeURIComponent(threadID)); - } - } - } else { - if (postID) { - postID = postID.match(/\d+/)[0]; - } - return path = threadID ? "" + board + "/thread/" + threadID : "" + board + "/post/" + postID; - } - }; + to: function(data) { + var board, threadID, url; + if (!data.isSearch) { + threadID = data.threadID; + } + board = data.board; switch (board) { case 'a': case 'co': @@ -4818,46 +4802,26 @@ case 'wsg': case 'dev': case 'foolz': - path = ar('fuuka'); - url = "//archive.foolz.us/" + path + "/"; - if (threadID && postID && !AL) { - url += "#" + postID; - } + url = Redirect.path('//archive.foolz.us', 'foolfuuka', data); break; case 'u': case 'kuku': - path = ar('fuuka'); - url = "//nsfw.foolz.us/" + path + "/"; - if (threadID && postID && !AL) { - url += "#" + postID; - } + url = Redirect.path("//nsfw.foolz.us", 'foolfuuka', data); break; case 'ck': case 'lit': - path = ar('fuuka'); - url = "//fuuka.warosu.org/" + path; - if (threadID && postID && !AL) { - url += "#" + postID; - } + url = Redirect.path("//fuuka.warosu.org", 'fuuka', data); break; case 'diy': case 'g': case 'sci': - path = ar('gentoo'); - url = "//archive.installgentoo.net/" + path; - if (threadID && postID && !AL) { - url += "#p" + postID; - } + url = Redirect.path("//archive.installgentoo.net", 'fuuka', data); break; case 'cgl': case 'mu': case 'soc': case 'w': - path = ar('gentoo'); - url = "//archive.rebeccablacktech.com/" + path; - if (threadID && postID && !AL) { - url += "#p" + postID; - } + url = Redirect.path("//archive.rebeccablacktech.com", 'fuuka', data); break; case 'an': case 'fit': @@ -4866,11 +4830,7 @@ case 'r9k': case 'toy': case 'x': - path = ar('gentoo'); - url = "http://archive.heinessen.com/" + path; - if (threadID && postID && !AL) { - url += "#p" + postID; - } + url = Redirect.path("http://archive.heinessen.com", 'fuuka', data); break; default: if (threadID) { @@ -4878,6 +4838,30 @@ } } return url || null; + }, + 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; } }; @@ -5323,7 +5307,11 @@ var MutationObserver, a, board, nav, node, nodes, observer, _i, _j, _len, _len1, _ref, _ref1; if (/^4chan - 404/.test(d.title)) { if (Conf['404 Redirect'] && /^\d+$/.test(g.THREAD_ID)) { - location.href = Redirect.thread(g.BOARD, g.THREAD_ID, location.hash); + location.href = Redirect.to({ + board: g.BOARD, + threadID: g.THREAD_ID, + postID: location.hash + }); } return; } diff --git a/changelog b/changelog index bad127f66..8b9339f1e 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,6 @@ master - noface - Archives now populate a submenu just like the quicklinks for the Filter. + The Menu now has search links for Archivers. 2.36.0 - Mayhem diff --git a/script.coffee b/script.coffee index 2e1424dad..b1c917e91 100644 --- a/script.coffee +++ b/script.coffee @@ -3522,7 +3522,11 @@ Quotify = a.href = "#p#{id}" a.className = 'quotelink' else - a.href = Redirect.thread board, 0, id + a.href = + Redirect.to + board: board + threadID: 0 + postID: id a.className = 'deadlink' a.target = '_blank' if Redirect.post board, id @@ -3695,21 +3699,22 @@ DownloadLink = true ArchiveLink = - init: (post) -> + init: -> div = $.el 'div', textContent: 'Archive' entry = el: div - open: (post) -> + open: (post) -> path = $('a[title="Highlight this post"]', post.el).pathname.split '/' - if (Redirect.thread path[1], path[3], post.ID) is "//boards.4chan.org/#{path[1]}/" + if (Redirect.to {board: path[1], threadID: path[3], postID: post.ID}) is "//boards.4chan.org/#{path[1]}/" return false + post.info = [path[1], path[3]] true children: [] for type in [ - ['Post', 'apost'] + ['Post', 'apost'] ['Name', 'name'] ['Tripcode', 'tripcode'] ['E-mail', 'email'] @@ -3717,32 +3722,34 @@ ArchiveLink = ['Filename', 'filename'] ['Image MD5', 'md5'] ] - # Add a sub entry for each filter type. + # Add a sub entry for each type. entry.children.push @createSubEntry type[0], type[1] Menu.addEntry entry createSubEntry: (text, type) -> + el = $.el 'a', textContent: text target: '_blank' open = (post) -> - path = $('a[title="Highlight this post"]', post.el).pathname.split '/' - unless type is 'apost' - value = Filter[type] post - # We want to parse the exact same stuff as Filter does already + maybe a few extras. - return false if value is false - switch type - when 'name' - if value is 'Anonymous' or value.length is 0 - return false - when 'email' - if value is 'sage' or value.length is 0 - return false - when 'apost' - return el.href = Redirect.thread path[1], path[3], post.ID - el.href = Redirect.thread path[1], value, type, true + if type is 'apost' + el.href = + Redirect.to + board: post.info[0] + threadID: post.info[1] + postID: post.ID + return true + value = Filter[type] post + # We want to parse the exact same stuff as Filter does already. + return false unless value + el.href = + Redirect.to + board: post.info[0] + type: type + value: value + isSearch: true return el: el, open: open @@ -3902,74 +3909,68 @@ Redirect = "//archive.rebeccablacktech.com/#{board}/full_image/#{filename}" when 'an', 'k', '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' "//archive.foolz.us/_/api/chan/post/?board=#{board}&num=#{postID}" when 'u', 'kuku' "//nsfw.foolz.us/_/api/chan/post/?board=#{board}&num=#{postID}" - thread: (board, threadID, postID, AL) -> - ar = (a) -> - if AL - postID = 'username' if postID is 'name' - postID = 'image' if postID is 'md5' - if a is 'fuuka' - return "#{board}/search/#{postID}/#{encodeURIComponent threadID}" - else if a is 'gentoo' - if postID is 'image' - "#{board}/image/#{encodeURIComponent threadID}" - else - "#{board}/?task=search2&search_#{postID}=#{encodeURIComponent threadID}" - else - # keep the number only if the location.hash was sent f.e. - postID = postID.match(/\d+/)[0] if postID - path = - if threadID - "#{board}/thread/#{threadID}" - else - "#{board}/post/#{postID}" + to: (data) -> + unless data.isSearch + {threadID} = data + {board} = data switch board when 'a', 'co', 'jp', 'm', 'q', 'sp', 'tg', 'tv', 'v', 'vg', 'wsg', 'dev', 'foolz' - path = ar 'fuuka' - url = "//archive.foolz.us/#{path}/" - if threadID and postID and !AL - url += "##{postID}" + url = Redirect.path '//archive.foolz.us', 'foolfuuka', data when 'u', 'kuku' - path = ar 'fuuka' - url = "//nsfw.foolz.us/#{path}/" - if threadID and postID and !AL - url += "##{postID}" + url = Redirect.path "//nsfw.foolz.us", 'foolfuuka', data when 'ck', 'lit' - path = ar 'fuuka' - url = "//fuuka.warosu.org/#{path}" - if threadID and postID and !AL - url += "##{postID}" + url = Redirect.path "//fuuka.warosu.org", 'fuuka', data when 'diy', 'g', 'sci' - path = ar 'gentoo' - url = "//archive.installgentoo.net/#{path}" - if threadID and postID and !AL - url += "#p#{postID}" + url = Redirect.path "//archive.installgentoo.net", 'fuuka', data when 'cgl', 'mu', 'soc', 'w' - path = ar 'gentoo' - url = "//archive.rebeccablacktech.com/#{path}" - if threadID and postID and !AL - url += "#p#{postID}" + url = Redirect.path "//archive.rebeccablacktech.com", 'fuuka', data when 'an', 'fit', 'k', 'mlp', 'r9k', 'toy', 'x' - path = ar 'gentoo' - url = "http://archive.heinessen.com/#{path}" - if threadID and postID and !AL - url += "#p#{postID}" - #when 'e' - # url = "https://www.cliché.net/4chan/cgi-board.pl/#{path}" - # if threadID and postID - # url += "#p#{postID}" + url = Redirect.path "http://archive.heinessen.com", 'fuuka', data else if threadID url = "//boards.4chan.org/#{board}/" url or null + 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 = + if threadID + "#{board}/thread/#{threadID}" + else + "#{board}/post/#{postID}" + if threadID and postID + path += + if archiver is 'foolfuuka' + "##{postID}" + else + "#p#{postID}" + "#{base}/#{path}" + ImageHover = init: -> Main.callbacks.push @node @@ -4300,7 +4301,11 @@ Main = ready: -> if /^4chan - 404/.test d.title if Conf['404 Redirect'] and /^\d+$/.test g.THREAD_ID - location.href = Redirect.thread g.BOARD, g.THREAD_ID, location.hash + location.href = + Redirect.to + board: g.BOARD + threadID: g.THREAD_ID + postID: location.hash return unless $.id 'navtopright' return