From 90ceba40838661b567ebe26935873bb64dc56f81 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Mon, 30 Apr 2012 02:31:45 +1000 Subject: [PATCH] js/show-op.js --- js/show-op.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 js/show-op.js diff --git a/js/show-op.js b/js/show-op.js new file mode 100644 index 00000000..df9cf31b --- /dev/null +++ b/js/show-op.js @@ -0,0 +1,49 @@ +/* + * show-op + * https://github.com/savetheinternet/Tinyboard/blob/master/js/show-op.js + * + * Adds "(OP)" to >>X links when the OP is quoted. + * + * Released under the MIT license + * Copyright (c) 2012 Michael Save + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/show-op.js'; + * + */ + +$(document).ready(function(){ + var showOPLinks = function() { + var OP; + + if ($('div.banner').length == 0) { + OP = $(this).parent().find('div.post.op a.post_no:eq(1)').text(); + } else { + OP = $('div.post.op a.post_no:eq(1)').text(); + } + + console.log(OP); + + $(this).find('p.body a:not([rel="nofollow"])').each(function() { + var postID; + + if(postID = $(this).text().match(/^>>(\d+)$/)) + postID = postID[1]; + else + return; + + if (postID == OP) { + $(this).after(' (OP)'); + } + }); + }; + + $('div.post.reply').each(showOPLinks); + + // allow to work with auto-reload.js, etc. + $(document).bind('new_post', function(e, post) { + $(post).each(showOPLinks); + }); +}); +