garr3tt

PWM_silencer.js

May 28th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           PWM Silencer
  3. // @namespace      Atęszion^whore^silencer
  4. // @description    Topic ignore feature for PWM. Based on PhpBB enhancer from Alekc (http://userscripts.org/scripts/show/57924)
  5. // @author         Nemo
  6. // @version        1.0.1
  7. // @include        http://pwm.org.pl/*
  8. // @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
  9. // ==/UserScript==
  10.  
  11. var phpbb_prefs;
  12. var debug = false;
  13.  
  14. debugLog("Begin userscript execution");
  15.  
  16. jQuery(document).ready(function() {
  17.    try{
  18.    debugLog("Ready");
  19.     if (jQuery("body#phpbb").length != 1){
  20.       debugLog("This isn't even a phpBB forum.");
  21.         return false;
  22.     }
  23.    
  24.    debugLog("Initializing JQuery");
  25.     var $j = jQuery.noConflict();
  26.     var regex = /t=(\d+)/g;
  27.  
  28.    debugLog("Loading blocked thread list");
  29.     phpbb_prefs = eval(GM_getValue("hb_helper_prefs" + jQuery(document).attr("domain"),{hiddenTopics:{}}));
  30.     GM_log(phpbb_prefs.toSource());
  31.  
  32.    debugLog("Searching for threads");
  33.     $j("li.row").each(function(){
  34.         var topicId = $j(this).find("a.topictitle").attr("href").match(/t=(\d+)/);
  35.         if(topicId == null) {
  36.            topicId = $j(this).find("a.topictitle").attr("href").match(/-t(\d+)\.html/);
  37.       }
  38.         debugLog(topicId);
  39.         if (phpbb_prefs.hiddenTopics[topicId[1]] == true){          
  40.             $j(this).hide();
  41.         } else {
  42.             $j(this).find("dt").css("position","relative").append("<div style='position:absolute;top:0px;right:0px;'><a class='pbe' href='" + topicId[1] + "' title=\"Ignore this thread\">[x]</a></div>");
  43.         }
  44.     });
  45.  
  46.     $j("a.pbe").click(function(e){
  47.         try{
  48.             $j(this).parents("li").hide("slow");
  49.  
  50.             phpbb_prefs.hiddenTopics[$j(this).attr("href")] = true;
  51.             GM_setValue("hb_helper_prefs" + jQuery(document).attr("domain"), phpbb_prefs.toSource());
  52.         } catch (err){GM_log(err.toSource());}
  53.         return false;
  54.     });
  55.    } catch (err){GM_log("Fatal exception inspecting topic:" + err.toSource());}
  56. });
  57.  
  58. function debugLog(msg){
  59.    if (debug){
  60.       GM_log("H-B Helper: " + msg);
  61.    }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment