Add Sauce. Change sauce parameters. Fix Quote Inlining/Previewing.

This commit is contained in:
Nicolas Stepien 2012-09-10 22:40:29 +02:00
parent a73777ca8d
commit 3bb93e73c7
2 changed files with 174 additions and 61 deletions

View File

@ -74,7 +74,7 @@
*/ */
(function() { (function() {
var $, $$, Board, Build, Clone, Conf, Config, FileInfo, Get, Main, Post, QuoteBacklink, QuoteInline, QuotePreview, Quotify, Redirect, Thread, Time, UI, d, g, var $, $$, Board, Build, Clone, Conf, Config, FileInfo, Get, Main, Post, QuoteBacklink, QuoteInline, QuotePreview, Quotify, Redirect, Sauce, Thread, Time, UI, d, g,
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
@ -159,7 +159,7 @@
filesize: [''].join('\n'), filesize: [''].join('\n'),
md5: [''].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;text:Upload to imgur', '#http://omploader.org/upload?url1=$2;text:Upload to omploader', '# "View Same" in archives:', '#http://archive.foolz.us/search/image/$3/;text:View same on foolz', '#http://archive.foolz.us/$4/search/image/$3/;text:View same on foolz /$4/', '#https://archive.installgentoo.net/$4/image/$3;text:View same on installgentoo /$4/'].join('\n'), sauces: ['http://iqdb.org/?url=$turl', 'http://www.google.com/searchbyimage?image_url=$turl', '#http://tineye.com/search?url=$turl', '#http://saucenao.com/search.php?db=999&url=$turl', '#http://3d.iqdb.org/?url=$turl', '#http://regex.info/exif.cgi?imgurl=$url', '# uploaders:', '#http://imgur.com/upload?url=$url;text:Upload to imgur', '#http://omploader.org/upload?url1=$url;text:Upload to omploader', '# "View Same" in archives:', '#http://archive.foolz.us/search/image/$md5/;text:View same on foolz', '#http://archive.foolz.us/$board/search/image/$md5/;text:View same on foolz /$board/', '#https://archive.installgentoo.net/$board/image/$md5;text:View same on installgentoo /$board/'].join('\n'),
time: '%m/%d/%y(%a)%H:%M', time: '%m/%d/%y(%a)%H:%M',
backlink: '>>%id', backlink: '>>%id',
fileInfo: '%l (%p%s, %r)', fileInfo: '%l (%p%s, %r)',
@ -978,6 +978,13 @@
$.log(err, 'File Info Formatting'); $.log(err, 'File Info Formatting');
} }
} }
if (Conf['Sauce']) {
try {
Sauce.init();
} catch (err) {
$.log(err, 'Sauce');
}
}
return $.ready(Main.initFeaturesReady); return $.ready(Main.initFeaturesReady);
}, },
initFeaturesReady: function() { initFeaturesReady: function() {
@ -1347,11 +1354,9 @@
}; };
}, },
postClone: function(board, threadID, postID, root) { postClone: function(board, threadID, postID, root) {
var clone, origin, url; var post, url;
if (origin = g.posts["" + board + "." + postID]) { if (post = g.posts["" + board + "." + postID]) {
clone = origin.addClone(); Get.insert(post, root);
Main.callbackNodes(Post, [clone]);
$.add(root, Get.cleanRoot(clone));
return; return;
} }
root.textContent = "Loading post No." + postID + "..."; root.textContent = "Loading post No." + postID + "...";
@ -1365,20 +1370,21 @@
}); });
} }
}, },
cleanRoot: function(clone) { insert: function(post, root) {
var child, post, root, _i, _len, _ref, _ref1; var clone, nodes;
_ref = clone.nodes, root = _ref.root, post = _ref.post; if (!root.parentNode) {
_ref1 = Array.prototype.slice.call(root.childNodes); return;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
child = _ref1[_i];
if (child !== post) {
$.rm(child);
}
} }
return root; clone = post.addClone();
Main.callbackNodes(Post, [clone]);
nodes = clone.nodes;
nodes.root.innerHTML = null;
$.add(nodes.root, nodes.post);
root.innerHTML = null;
return $.add(root, nodes.root);
}, },
fetchedPost: function(req, board, threadID, postID, root) { fetchedPost: function(req, board, threadID, postID, root) {
var doc, href, inBoard, inThread, link, pc, post, quote, status, url, _i, _len, _ref; var doc, href, link, pc, post, quote, status, thread, url, _i, _len, _ref;
if (post = g.posts["" + board + "." + postID]) { if (post = g.posts["" + board + "." + postID]) {
Get.insert(post, root); Get.insert(post, root);
return; return;
@ -1421,9 +1427,9 @@
link = $('a[title="Highlight this post"]', pc); link = $('a[title="Highlight this post"]', pc);
link.href = "/" + board + "/res/" + threadID + "#p" + postID; link.href = "/" + board + "/res/" + threadID + "#p" + postID;
link.nextSibling.href = "/" + board + "/res/" + threadID + "#q" + postID; link.nextSibling.href = "/" + board + "/res/" + threadID + "#q" + postID;
inBoard = g.boards[board] || new Board(board); board = g.boards[board] || new Board(board);
inThread = g.threads["" + board + "." + threadID] || new Thread(threadID, inBoard); thread = g.threads["" + board + "." + threadID] || new Thread(threadID, inBoard);
post = new Post(postContainer, thread, board); post = new Post(pc, thread, board);
Main.callbackNodes(Post, [post]); Main.callbackNodes(Post, [post]);
return Get.insert(post, root); return Get.insert(post, root);
}, },
@ -1505,15 +1511,6 @@
}); });
Main.callbackNodes(Post, [post]); Main.callbackNodes(Post, [post]);
return Get.insert(post, root); return Get.insert(post, root);
},
insert: function(post, root) {
var clone;
if (!root.parentNode) {
return;
}
clone = post.addClone();
Main.callbackNodes(Post, [clone]);
return $.replace(root.firstChild, Get.cleanRoot(clone));
} }
}; };
@ -1716,8 +1713,8 @@
className: 'reply dialog' className: 'reply dialog'
}); });
UI.hover(e); UI.hover(e);
Get.postClone(board, threadID, postID, qp);
$.add(d.body, qp); $.add(d.body, qp);
Get.postClone(board, threadID, postID, qp);
$.on(this, 'mousemove', UI.hover); $.on(this, 'mousemove', UI.hover);
$.on(this, 'mouseout click', QuotePreview.mouseout); $.on(this, 'mouseout click', QuotePreview.mouseout);
if (!(origin = g.posts["" + board + "." + postID])) { if (!(origin = g.posts["" + board + "." + postID])) {
@ -2026,6 +2023,72 @@
} }
}; };
Sauce = {
init: function() {
var link, links, _i, _len, _ref;
links = [];
_ref = Conf['sauces'].split('\n');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
link = _ref[_i];
if (link[0] === '#') {
continue;
}
links.push(this.createSauceLink(link.trim()));
}
if (!links.length) {
return;
}
this.links = links;
return Post.prototype.callbacks.push({
name: 'Sauce',
cb: this.node
});
},
createSauceLink: function(link) {
var el, href, m, text;
link = link.replace(/\$(turl|url|md5|board)/g, function(parameter) {
switch (parameter) {
case '$turl':
return "' + post.file.thumbURL + '";
case '$url':
return "' + post.file.URL + '";
case '$md5':
return "' + encodeURIComponent(post.file.MD5) + '";
case '$board':
return "' + post.board + '";
default:
return parameter;
}
});
text = (m = link.match(/;text:(.+)$/)) ? m[1] : link.match(/(\w+)\.\w+\//)[1];
link = link.replace(/;text:.+$/, '');
href = Function('post', "return '" + link + "'");
el = $.el('a', {
target: '_blank',
textContent: text
});
return function(post) {
var a;
a = el.cloneNode(true);
a.href = href(post);
return a;
};
},
node: function() {
var link, nodes, _i, _len, _ref;
if (this.isClone || !this.file) {
return;
}
nodes = [];
_ref = Sauce.links;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
link = _ref[_i];
nodes.push($.tn('\u00A0'), link(this));
}
return $.add(this.file.info, nodes);
}
};
Main.init(); Main.init();
}).call(this); }).call(this);

View File

@ -105,19 +105,19 @@ Config =
'' ''
].join '\n' ].join '\n'
sauces: [ sauces: [
'http://iqdb.org/?url=$1' 'http://iqdb.org/?url=$turl'
'http://www.google.com/searchbyimage?image_url=$1' 'http://www.google.com/searchbyimage?image_url=$turl'
'#http://tineye.com/search?url=$1' '#http://tineye.com/search?url=$turl'
'#http://saucenao.com/search.php?db=999&url=$1' '#http://saucenao.com/search.php?db=999&url=$turl'
'#http://3d.iqdb.org/?url=$1' '#http://3d.iqdb.org/?url=$turl'
'#http://regex.info/exif.cgi?imgurl=$2' '#http://regex.info/exif.cgi?imgurl=$url'
'# uploaders:' '# uploaders:'
'#http://imgur.com/upload?url=$2;text:Upload to imgur' '#http://imgur.com/upload?url=$url;text:Upload to imgur'
'#http://omploader.org/upload?url1=$2;text:Upload to omploader' '#http://omploader.org/upload?url1=$url;text:Upload to omploader'
'# "View Same" in archives:' '# "View Same" in archives:'
'#http://archive.foolz.us/search/image/$3/;text:View same on foolz' '#http://archive.foolz.us/search/image/$md5/;text:View same on foolz'
'#http://archive.foolz.us/$4/search/image/$3/;text:View same on foolz /$4/' '#http://archive.foolz.us/$board/search/image/$md5/;text:View same on foolz /$board/'
'#https://archive.installgentoo.net/$4/image/$3;text:View same on installgentoo /$4/' '#https://archive.installgentoo.net/$board/image/$md5;text:View same on installgentoo /$board/'
].join '\n' ].join '\n'
time: '%m/%d/%y(%a)%H:%M' time: '%m/%d/%y(%a)%H:%M'
backlink: '>>%id' backlink: '>>%id'
@ -783,6 +783,13 @@ Main =
# XXX handle error # XXX handle error
$.log err, 'File Info Formatting' $.log err, 'File Info Formatting'
if Conf['Sauce']
try
Sauce.init()
catch err
# XXX handle error
$.log err, 'Sauce'
$.ready Main.initFeaturesReady $.ready Main.initFeaturesReady
initFeaturesReady: -> initFeaturesReady: ->
if d.title is '4chan - 404 Not Found' if d.title is '4chan - 404 Not Found'
@ -1157,10 +1164,8 @@ Get =
postID: postID postID: postID
} }
postClone: (board, threadID, postID, root) -> postClone: (board, threadID, postID, root) ->
if origin = g.posts["#{board}.#{postID}"] if post = g.posts["#{board}.#{postID}"]
clone = origin.addClone() Get.insert post, root
Main.callbackNodes Post, [clone]
$.add root, Get.cleanRoot clone
return return
root.textContent = "Loading post No.#{postID}..." root.textContent = "Loading post No.#{postID}..."
@ -1170,11 +1175,19 @@ Get =
else if url = Redirect.post board, postID else if url = Redirect.post board, postID
$.cache url, -> $.cache url, ->
Get.archivedPost @, board, postID, root Get.archivedPost @, board, postID, root
cleanRoot: (clone) -> insert: (post, root) ->
{root, post} = clone.nodes # Stop here if the container has been removed while loading.
for child in Array::slice.call root.childNodes return unless root.parentNode
$.rm child unless child is post clone = post.addClone()
root Main.callbackNodes Post, [clone]
# Get rid of the side arrows.
{nodes} = clone
nodes.root.innerHTML = null
$.add nodes.root, nodes.post
root.innerHTML = null
$.add root, nodes.root
fetchedPost: (req, board, threadID, postID, root) -> fetchedPost: (req, board, threadID, postID, root) ->
# In case of multiple callbacks for the same request, # In case of multiple callbacks for the same request,
# don't parse the same original post more than once. # don't parse the same original post more than once.
@ -1218,11 +1231,11 @@ Get =
link.href = "/#{board}/res/#{threadID}#p#{postID}" link.href = "/#{board}/res/#{threadID}#p#{postID}"
link.nextSibling.href = "/#{board}/res/#{threadID}#q#{postID}" link.nextSibling.href = "/#{board}/res/#{threadID}#q#{postID}"
inBoard = g.boards[board] or board = g.boards[board] or
new Board board new Board board
inThread = g.threads["#{board}.#{threadID}"] or thread = g.threads["#{board}.#{threadID}"] or
new Thread threadID, inBoard new Thread threadID, inBoard
post = new Post postContainer, thread, board post = new Post pc, thread, board
Main.callbackNodes Post, [post] Main.callbackNodes Post, [post]
Get.insert post, root Get.insert post, root
archivedPost: (req, board, postID, root) -> archivedPost: (req, board, postID, root) ->
@ -1315,12 +1328,6 @@ Get =
isArchived: true isArchived: true
Main.callbackNodes Post, [post] Main.callbackNodes Post, [post]
Get.insert post, root Get.insert post, root
insert: (post, root) ->
# Stop here if the container has been removed while loading.
return unless root.parentNode
clone = post.addClone()
Main.callbackNodes Post, [clone]
$.replace root.firstChild, Get.cleanRoot clone
Quotify = Quotify =
init: -> init: ->
@ -1523,8 +1530,8 @@ QuotePreview =
id: 'qp' id: 'qp'
className: 'reply dialog' className: 'reply dialog'
UI.hover e UI.hover e
Get.postClone board, threadID, postID, qp
$.add d.body, qp $.add d.body, qp
Get.postClone board, threadID, postID, qp
$.on @, 'mousemove', UI.hover $.on @, 'mousemove', UI.hover
$.on @, 'mouseout click', QuotePreview.mouseout $.on @, 'mouseout click', QuotePreview.mouseout
@ -1726,6 +1733,49 @@ FileInfo =
M: -> FileInfo.convertUnit @file.size, 'MB' M: -> FileInfo.convertUnit @file.size, 'MB'
r: -> if @file.isImage then @file.dimensions else 'PDF' r: -> if @file.isImage then @file.dimensions else 'PDF'
Sauce =
init: ->
links = []
for link in Conf['sauces'].split '\n'
continue if link[0] is '#'
# XXX .trim() is there to fix Opera reading two different line breaks.
links.push @createSauceLink link.trim()
return unless links.length
@links = links
Post::callbacks.push
name: 'Sauce'
cb: @node
createSauceLink: (link) ->
link = link.replace /\$(turl|url|md5|board)/g, (parameter) ->
switch parameter
when '$turl'
"' + post.file.thumbURL + '"
when '$url'
"' + post.file.URL + '"
when '$md5'
"' + encodeURIComponent(post.file.MD5) + '"
when '$board'
"' + post.board + '"
else
parameter
text = if m = link.match(/;text:(.+)$/) then m[1] else link.match(/(\w+)\.\w+\//)[1]
link = link.replace /;text:.+$/, ''
href = Function 'post', "return '#{link}'"
el = $.el 'a',
target: '_blank'
textContent: text
(post) ->
a = el.cloneNode true
a.href = href post
a
node: ->
return if @isClone or !@file
nodes = []
for link in Sauce.links
# \u00A0 is nbsp
nodes.push $.tn('\u00A0'), link @
$.add @file.info, nodes
Main.init() Main.init()