Advertisement
Guest User

opchan backlinks

a guest
Aug 5th, 2014
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. // @grant       none
  8. // ==/UserScript==
  9.  
  10. //partly based on the "4chan pretty thread" userscript
  11.  
  12. //root-post
  13. var firsPostId = $('.reflink:first').text().replace(/[^0-9]+/g, '');
  14. $('<div class="repliesDiv" id="replies-'+firsPostId+'" ><span class="RplyMsg"> Replies to this post: </span></div>').insertAfter('.reflink:first');
  15. $('#replies-'+firsPostId).css('display','none');
  16.  
  17. // wrap replies
  18. $(".reply").each
  19. (
  20.     function()
  21.     {
  22.         var id = $(this).attr("id").replace("reply","");
  23.         var reply = $(this).parents().get(2);
  24.         $(reply).wrap('<div id="parent-'+id+'"></div>');
  25.         $("a[name='"+id+"']").prependTo("#parent-"+id);
  26.         $('<div class="repliesDiv" id="replies-'+id+'" ><span class="RplyMsg"> Replies to this post: </span></div>').insertAfter($(this).find('.reflink'));
  27.         $('#replies-'+id).css('display','none');
  28.     }
  29. );
  30.  
  31. //add param: the ID from the post that quoted
  32. $('.reply').each
  33. (
  34.     function ()
  35.     {
  36.         var currentPost = $(this);
  37.         var id = currentPost.attr('id').replace('reply', '');
  38.         //  alert(id);
  39.         currentPost.find('a').each
  40.         (
  41.             function ()
  42.             {
  43.                 if ($(this).attr('class') != null)
  44.                     if ($(this).attr('class').match(/^ref.+/))
  45.                     {
  46.                         var ctemp = $(this).attr('class');
  47.                         $(this).attr('class', ctemp+'|'+id);
  48.                     }
  49.             }
  50.         );
  51.     }
  52. );
  53.  
  54. //add quotelinks
  55. $("a").each
  56. (
  57.     function()
  58.     {
  59.         if ( $(this).attr('class') != null )
  60.             if ( $(this).attr('class').match(/^ref.+/) )
  61.             {
  62.                 var myarr =  $(this).attr('class').split("|");
  63.                 var parentid = myarr[3];
  64.                 $('<a class="ref|'+ myarr[1]+'|'+ myarr[2]+'|'+ myarr[4] +'" href="#'+myarr[4]+'">>>'+myarr[4]+'&nbsp</a>;').appendTo("#replies-"+parentid);
  65.                 $('#replies-'+parentid).css('display','inline');
  66.             }
  67.     }
  68. );
  69.  
  70. $("<style type='text/css'> .repliesDiv{; margin: 3px 5px 0px 3px;} .RplyMsg{font-style: italic;}</style>").appendTo("head");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement