leftypol/js/show-backlinks.js

63 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2012-03-19 00:33:06 +11:00
/*
2012-03-19 00:48:06 +11:00
* show-backlinks.js
2012-03-31 11:13:11 +11:00
* https://github.com/savetheinternet/Tinyboard/blob/master/js/show-backlinks.js
2012-03-19 00:33:06 +11:00
*
* Released under the MIT license
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
2012-03-19 00:33:06 +11:00
*
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* // $config['additional_javascript'][] = 'js/post-hover.js'; (optional; must come first)
2012-03-19 00:48:06 +11:00
* $config['additional_javascript'][] = 'js/show-backlinks.js';
2012-03-19 00:33:06 +11:00
*
*/
$(document).ready(function() {
let showBackLinks = function() {
2025-02-22 23:33:48 +01:00
let replyId = $(this).attr('id').split('_')[1];
2012-08-27 23:01:08 +10:00
$(this).find('div.body a:not([rel="nofollow"])').each(function() {
let id = $(this).text().match(/^>>(\d+)$/);
if (id) {
2012-03-19 00:33:06 +11:00
id = id[1];
} else {
2012-03-19 00:33:06 +11:00
return;
}
2024-12-29 15:33:10 +01:00
let post = $('#reply_' + id + ', #op_' + id);
if (post.length == 0) {
2024-12-29 15:33:10 +01:00
return;
}
let mentioned = post.find('.head div.mentioned');
if (mentioned.length === 0) {
// The op has two "head"s divs, use the second.
mentioned = $('<div class="mentioned unimportant"></div>').prependTo(post.find('.head').last());
}
if (mentioned.find('a.mentioned-' + replyId).length !== 0) {
return;
}
let link = $('<a class="mentioned-' + replyId + '" onclick="highlightReply(\'' + replyId + '\');" href="#'
+ replyId + '">&gt;&gt;' + replyId + '</a>');
2024-09-02 23:20:56 +02:00
link.appendTo(mentioned);
if (window.init_hover) {
link.each(init_hover);
}
2012-03-19 00:33:06 +11:00
});
};
$('div.post').each(showBackLinks);
$(document).on('new_post', function(e, post) {
if ($(post).hasClass('reply') || $(post).hasClass('op')) {
2013-07-27 00:57:12 -04:00
showBackLinks.call(post);
} else {
$(post).find('div.post').each(showBackLinks);
2013-07-27 00:57:12 -04:00
}
});
2012-03-19 00:33:06 +11:00
});