View difference between Paste ID: dXTTCMVK and R4bBA9f9
SHOW: | | - or go back to the newest paste.
1
// ==UserScript==
2
// @name        opchan backlinks
3
// @namespace   http://*operatorchan.org/*/res/*
4
// @description opchan backlinks
5
// @require      http://code.jquery.com/jquery-2.1.1.min.js
6
// @version     1
7
// @include http://*operatorchan.org/*
8
// @grant       none
9
// ==/UserScript==
10
11
//partly based on the "4chan pretty thread" userscript
12
13
//root-post
14
var firsPostId = $('.reflink:first').text().replace(/[^0-9]+/g, '');
15
$('<div class="repliesDiv" id="replies-'+firsPostId+'" ><span class="RplyMsg"> Replies to this post: </span></div>').insertAfter('.reflink:first');
16
$('#replies-'+firsPostId).css('display','none');
17
18
// wrap replies
19
$(".reply").each
20
(
21
	function()
22
	{
23
		var id = $(this).attr("id").replace("reply","");
24
		var reply = $(this).parents().get(2);
25
		$(reply).wrap('<div id="parent-'+id+'"></div>');
26
		$("a[name='"+id+"']").prependTo("#parent-"+id);
27
		$('<div class="repliesDiv" id="replies-'+id+'" ><span class="RplyMsg"> Replies to this post: </span></div>').insertAfter($(this).find('.reflink'));
28
		$('#replies-'+id).css('display','none');
29
	}
30
);
31
32
//add param: the ID from the post that quoted 
33
$('.reply').each
34
(
35
	function ()
36
	{
37
		var currentPost = $(this);
38
		var id = currentPost.attr('id').replace('reply', '');
39
		//  alert(id);
40
		currentPost.find('a').each
41
		(
42
			function ()
43
			{
44
				if ($(this).attr('class') != null)
45
					if ($(this).attr('class').match(/^ref.+/))
46
					{
47
						var ctemp = $(this).attr('class');
48
						$(this).attr('class', ctemp+'|'+id);
49
					}
50
			}
51
		);
52
	}
53
);
54
55
//add quotelinks
56
$("a").each
57
(
58
	function()
59
	{
60
		if ( $(this).attr('class') != null )
61
			if ( $(this).attr('class').match(/^ref.+/) )
62
			{
63
				var myarr =  $(this).attr('class').split("|");
64
				var parentid = myarr[3];
65
				$('<a class="ref|'+ myarr[1]+'|'+ myarr[2]+'|'+ myarr[4] +'" href="#'+myarr[4]+'">>>'+myarr[4]+'&nbsp</a>;').appendTo("#replies-"+parentid);
66
				$('#replies-'+parentid).css('display','inline');
67
			}
68
	}
69
);
70
71
$("<style type='text/css'> .repliesDiv{; margin: 3px 5px 0px 3px;} .RplyMsg{font-style: italic;}</style>").appendTo("head");