Advertisement
Guest User

Untitled

a guest
Dec 17th, 2008
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          PunBB Ignore
  3. // @namespace     http://kasparovchess.crestbook.com/
  4. // @description   Kasparovchess censor
  5. // @include       http://kasparovchess.crestbook.com/*
  6. // ==/UserScript==
  7.  
  8.  
  9. /* this is the list of userids to ignore */
  10. var ignore_list = [12];
  11. function match_end( str, end) {
  12.     var sl = str.length;
  13.     var el = end.length;
  14.     if(-1 == (sl - el))
  15.       return false;
  16.     return (str.indexOf(end) == (sl - el));
  17. }
  18. function div_matches( div , profileid ) {
  19.   var a = div.getElementsByTagName("A");
  20.   var i = 0;
  21.   var m = "profile.php?id="+profileid;
  22.   for ( i = 0 ; i < a.length ; i++ ) {
  23.     if (match_end(a[i].href, m)) {
  24.       return true;
  25.     }
  26.   }
  27.   return false;
  28. }
  29. function getposterid(div) {
  30.   var a = div.getElementsByTagName("A");
  31.   var offset;
  32.   var value = 0;
  33.   var str;
  34.   for ( i = 0 ; i < a.length ; i++ ) {
  35.     str = a[i].href;
  36.     offset = str.indexOf("profile.php?id=");
  37.     if(-1 == offset) {
  38.       continue;
  39.    
  40.     }
  41.     // is this even needed?
  42.     if((str.length-offset) < 1) {
  43.       continue;
  44.     }
  45.     value = str;
  46.     value = 1 * str.slice(offset+15).valueOf();
  47.     if(value == -1 || isNaN(value)) {
  48.       continue;
  49.     }
  50.     //alert(value);
  51.     return value;
  52.   }
  53.   return -1;
  54. }
  55. function unignorepost(event) {
  56.   var buttonpressed = event.currentTarget;
  57.  
  58.   buttonpressed.parentNode.style.display = "none";
  59.   buttonpressed.parentNode.nextSibling.style.display = null;
  60.  
  61.   /////////////////////////
  62.   getposterid(buttonpressed.parentNode.parentNode);
  63.  
  64.   event.preventDefault();
  65. }
  66. function ignorepost(event) {
  67.   var buttonpressed = event.currentTarget;
  68.  
  69.   var common = buttonpressed.parentNode.parentNode.parentNode.parentNode.parentNode;
  70.   common.previousSibling.style.display = null;
  71.   common.style.display = "none";
  72.  
  73.   event.preventDefault();
  74. }
  75. function isposterignored(div) {
  76.   var value = getposterid(div);
  77.   for (j = 0 ; j < ignore_list.length ; j++) {
  78.     if(value == ignore_list[j]) {
  79.       return true;
  80.     }
  81.   }
  82. }
  83. function removeignoreid(div) {
  84.   var value = getposterid(div);
  85.   for (j = 0 ; j < ignore_list.length ; j++) {
  86.     if(value == ignore_list[j]) {
  87.       ignore_list.splice(j,1);
  88.     }
  89.   }
  90. }
  91. function toggleignore(event) {
  92.   var buttonpressed = event.currentTarget;
  93.  
  94.   var postdiv = buttonpressed.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  95.   var test = isposterignored(postdiv);
  96.   var r;
  97.   var changed = false;
  98.   if(test > 0) {
  99.     r = confirm("Are you sure you want to REMOVE this poster from your ignore list?");
  100.     if(true == r) {
  101.       removeignoreid(postdiv);
  102.       buttonpressed.textContent = "Ignore";
  103.       changed = true;
  104.     }
  105.   }
  106.   else {
  107.     r = confirm("Are you sure you want to ADD this poster from your ignore list?");
  108.     if(true == r) {
  109.       ignore_list.push(getposterid(postdiv));
  110.       buttonpressed.textContent = "***IGNORED***";
  111.       changed = true;
  112.     }
  113.   }
  114.   // Update the persistent cookie data
  115.   if(changed) {
  116.     GM_setValue("sassignorelist",ignore_list.join(','));
  117.   }
  118.  
  119.   event.preventDefault();
  120. }
  121. function setupignores() {
  122.   var divs = document.getElementsByTagName("DIV");
  123.   var d;
  124.   var i = 0, j = 0;
  125.   for (i = 0 ; i < divs.length ; i++ ) {
  126.     if (divs[i].className.match(/blockpost/)) {
  127.       //for (j = 0 ; j < ignore_list.length ; j++) {
  128.         //if (div_matches(divs[i],ignore_list[j])) {
  129.        
  130.           var isignored = isposterignored(divs[i]);
  131.          
  132.           var ignoredstatusstring = "Ignore";
  133.           if(isignored) {
  134.             ignoredstatusstring = "***IGNORED***";
  135.           }
  136.          
  137.           /////
  138.          
  139.           var bigdiv = divs[i];
  140.           var hiding = bigdiv.getElementsByTagName("div")[0];
  141.          
  142.           /////
  143.           var clearer = document.createElement("div");
  144.           clearer.class = "clearer";
  145.          
  146.           var optionslocation = bigdiv.getElementsByTagName("dl")[0];
  147.           var ddarea = document.createElement("dd");
  148.           var hidebutton = document.createElement("a");
  149.           var toggleignorebutton = document.createElement("a");
  150.          
  151.           hidebutton.title = bigdiv.id//will be needed later i think
  152.           hidebutton.href = "#";
  153.           hidebutton.addEventListener("click",ignorepost,true);
  154.           //
  155.           toggleignorebutton.title = bigdiv.id//will be needed later i think
  156.           toggleignorebutton.href = "#";
  157.           toggleignorebutton.addEventListener("click",toggleignore,true);
  158.           hidebutton.textContent = "Hide post";
  159.           toggleignorebutton.textContent = ignoredstatusstring;
  160.           ddarea.appendChild(hidebutton);
  161.           ddarea.appendChild(clearer);
  162.           ddarea.appendChild(toggleignorebutton);
  163.           optionslocation.appendChild(ddarea);
  164.          
  165.           /////
  166.  
  167.           var showbuttonarea = document.createElement("div");
  168.           var showbutton = document.createElement("a");
  169.           showbutton.title = bigdiv.id//will be needed later i think
  170.           showbutton.href = "#";
  171.           showbutton.addEventListener("click",unignorepost,true);
  172.          
  173.           showbutton.textContent = "Show post";
  174.           showbuttonarea.appendChild(showbutton);
  175.          
  176.           bigdiv.insertBefore(showbuttonarea,hiding);
  177.          
  178.           /////
  179.          
  180.           // Toggle these... (when one is on, turn the other off).
  181.           if(isignored) {
  182.             hiding.style.display = "none";
  183.             //showbutton.parentNode.style.display = "none";
  184.           }
  185.           else {
  186.             //hiding.style.display = "none";
  187.             showbutton.parentNode.style.display = "none";
  188.           }
  189.          
  190.         //}
  191.       //}
  192.     }
  193.   }
  194. }
  195. function loadignorelist() {
  196.   var savedlist = GM_getValue("sassignorelist","");
  197.  
  198.   ignore_list = savedlist.split(',');
  199. }
  200. loadignorelist();
  201. setupignores();
  202.  
  203.  
  204.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement