Some archive redirection refactor. Add a missing /.

This commit is contained in:
Nicolas Stepien 2012-02-08 01:19:23 +01:00
parent 504d03b9d2
commit eb4c557d90
2 changed files with 20 additions and 17 deletions

View File

@ -3186,22 +3186,24 @@
redirect = { redirect = {
init: function() { init: function() {
var url; var url;
url = location.hostname === 'images.4chan.org' ? redirect.image(g.BOARD, location.pathname.split('/')[3]) : /^\d+$/.test(g.THREAD_ID) ? redirect.thread() : void 0; url = location.hostname === 'images.4chan.org' ? redirect.image(location.href) : /^\d+$/.test(g.THREAD_ID) ? redirect.thread() : void 0;
if (url) return location.href = url; if (url) return location.href = url;
}, },
image: function(board, filename) { image: function(href) {
href = href.split('/');
if (!conf['404 Redirect']) return; if (!conf['404 Redirect']) return;
switch (board) { switch (href[3]) {
case 'a': case 'a':
case 'jp': case 'jp':
case 'm': case 'm':
case 'tg': case 'tg':
case 'tv': case 'tv':
case 'u': case 'u':
return "http://archive.foolz.us/" + board + "/full_image/" + filename; return "http://archive.foolz.us/" + href[3] + "/full_image/" + href[5];
} }
}, },
thread: function() { thread: function() {
if (!conf['404 Redirect']) return;
switch (g.BOARD) { switch (g.BOARD) {
case 'a': case 'a':
case 'jp': case 'jp':
@ -3241,7 +3243,7 @@
case 'x': case 'x':
return "http://archive.no-ip.org/" + g.BOARD + "/thread/" + g.THREAD_ID; return "http://archive.no-ip.org/" + g.BOARD + "/thread/" + g.THREAD_ID;
default: default:
return "http://boards.4chan.org/" + g.BOARD; return "http://boards.4chan.org/" + g.BOARD + "/";
} }
} }
}; };
@ -3376,13 +3378,12 @@
return $.add(a, img); return $.add(a, img);
}, },
error: function() { error: function() {
var href, src, thumb, timeoutID, url; var href, thumb, timeoutID, url;
href = this.parentNode.href; href = this.parentNode.href;
thumb = this.previousSibling; thumb = this.previousSibling;
src = href.split('/');
imgExpand.contract(thumb); imgExpand.contract(thumb);
$.rm(this); $.rm(this);
if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5])))) { if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = redirect.image(href)))) {
if (g.dead) return; if (g.dead) return;
url = href + '?' + Date.now(); url = href + '?' + Date.now();
} }
@ -3501,7 +3502,7 @@
}, },
ready: function() { ready: function() {
var callback, form, node, nodes, _i, _j, _len, _len2, _ref; var callback, form, node, nodes, _i, _j, _len, _len2, _ref;
if (conf['404 Redirect'] && d.title === '4chan - 404') { if (d.title === '4chan - 404') {
redirect.init(); redirect.init();
return; return;
} }

View File

@ -2495,16 +2495,19 @@ redirect =
init: -> init: ->
url = url =
if location.hostname is 'images.4chan.org' if location.hostname is 'images.4chan.org'
redirect.image g.BOARD, location.pathname.split('/')[3] redirect.image location.href
else if /^\d+$/.test g.THREAD_ID else if /^\d+$/.test g.THREAD_ID
redirect.thread() redirect.thread()
location.href = url if url location.href = url if url
image: (board, filename) -> #board must be given, the image can originate from a cross-quote image: (href) ->
href = href.split '/'
# Do not use g.BOARD, the image url can originate from a cross-quote.
return unless conf['404 Redirect'] return unless conf['404 Redirect']
switch board switch href[3]
when 'a', 'jp', 'm', 'tg', 'tv', 'u' when 'a', 'jp', 'm', 'tg', 'tv', 'u'
"http://archive.foolz.us/#{board}/full_image/#{filename}" "http://archive.foolz.us/#{href[3]}/full_image/#{href[5]}"
thread: -> thread: ->
return unless conf['404 Redirect']
switch g.BOARD switch g.BOARD
when 'a', 'jp', 'm', 'tg', 'tv', 'u' when 'a', 'jp', 'm', 'tg', 'tv', 'u'
"http://archive.foolz.us/#{g.BOARD}/thread/#{g.THREAD_ID}/" "http://archive.foolz.us/#{g.BOARD}/thread/#{g.THREAD_ID}/"
@ -2515,7 +2518,7 @@ redirect =
when '3', 'adv', 'an', 'ck', 'co', 'fa', 'fit', 'int', 'k', 'mu', 'n', 'o', 'p', 'po', 'pol', 'r9k', 'soc', 'sp', 'toy', 'trv', 'v', 'vp', 'x' when '3', 'adv', 'an', 'ck', 'co', 'fa', 'fit', 'int', 'k', 'mu', 'n', 'o', 'p', 'po', 'pol', 'r9k', 'soc', 'sp', 'toy', 'trv', 'v', 'vp', 'x'
"http://archive.no-ip.org/#{g.BOARD}/thread/#{g.THREAD_ID}" "http://archive.no-ip.org/#{g.BOARD}/thread/#{g.THREAD_ID}"
else else
"http://boards.4chan.org/#{g.BOARD}" "http://boards.4chan.org/#{g.BOARD}/"
imgHover = imgHover =
init: -> init: ->
@ -2612,10 +2615,9 @@ imgExpand =
error: -> error: ->
href = @parentNode.href href = @parentNode.href
thumb = @previousSibling thumb = @previousSibling
src = href.split '/'
imgExpand.contract thumb imgExpand.contract thumb
$.rm @ $.rm @
unless @src.split('/')[2] is 'images.4chan.org' and url = redirect.image src[3], src[5] unless @src.split('/')[2] is 'images.4chan.org' and url = redirect.image href
return if g.dead return if g.dead
# CloudFlare may cache banned pages instead of images. # CloudFlare may cache banned pages instead of images.
# This will fool CloudFlare's cache. # This will fool CloudFlare's cache.
@ -2751,7 +2753,7 @@ Main =
$.ready Main.ready $.ready Main.ready
ready: -> ready: ->
if conf['404 Redirect'] and d.title is '4chan - 404' if d.title is '4chan - 404'
redirect.init() redirect.init()
return return
if not $.id 'navtopr' if not $.id 'navtopr'