program666 / HideThreads

// ==UserScript==
// @name        HideThreads
// @namespace   sa
// @include     http://forums.somethingawful.com/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @version     1
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
function hiddenThreadPop(hidThreadList){
  var me = this;
  this.jq = $("<div>", {style:"background:yellowgreen;position:absolute;top:0px;left:0px;min-width:200px"});
  var listTable = $("<table>");
  this.jq.append(listTable);
  var tbody = $("<tbody>");
  listTable.append(tbody);
  var closeBtn = $("<input>", {type:"button", value:"Close"});
  this.jq.append(closeBtn);
  var exportBtn = $("<input>", {type:"button", value:"Export"});
  this.jq.append(exportBtn);
  var importBtn = $("<input>", {type:"button", value:"Import"});
  this.jq.append(importBtn);
  
  function listReload(){
    tbody.empty();
    for(var idx in hidThreadList){
      addElem(hidThreadList[idx].threadId, hidThreadList[idx].threadTitle);
    }
  }
  this.listReload = listReload;

  function addElem(threadId, threadName){
    var newLine = $("<tr>");
    newLine.append($("<th>").append(threadName));
    var removeBtn = $("<input>", {type:"button", value:"x"});
    newLine.append($("<th>").append(removeBtn));
    removeBtn.click(getRemoveHand(threadId));
    
    function getRemoveHand(threadId){
      return function(){
        for(var idx in hidThreadList){
          if(hidThreadList[idx].threadId == threadId){
            hidThreadList.splice(idx, 1);
            GM_setValue("threadList", JSON.stringify(hidThreadList));
            listReload();
            break;
          }
        }
      }
    }
    
    tbody.append(newLine);
  }
  exportBtn.click(function(){
	  prompt("List of threads in json format",JSON.stringify(hidThreadList));
  });
    
  importBtn.click(function(){
	  var jsonList = prompt("Enter json list of threads", "[]");
      GM_setValue("threadList", jsonList);
  });
    
  this.setCloseBtnFnc = function(f){
    closeBtn.click(f);
  }
}

if(window.location.href.indexOf("forumdisplay.php?forumid=") != -1){
  var hiddenThreads = $("<a>", {text:"Hidden threads", style:"cursor:pointer;"});
  $("#navigation").append($("<li>").append("- ").append(hiddenThreads))
  var threadListStr = GM_getValue("threadList");
  var threadList;
  if(threadListStr)
    try{
   threadList = JSON.parse(threadListStr);
    }catch(e){
      alert("Error importing");
      threadList = new Array();
    }
  if(threadList === undefined)
    threadList = new Array();
 
  for(var idx in threadList)
    $("#thread" + threadList[idx].threadId).css("display", "none");

  hiddenThreads.click(function(){
    var htp = new hiddenThreadPop(threadList);
    htp.listReload();
    htp.setCloseBtnFnc(function(){
      htp.jq.detach();
      htp = null;
    });
    $("body").append(htp.jq);
  });
  
  $(".threadlist").children("tbody").children().each(function(i){
    var hideBtn = $("<input>", {type:"button", style:"width:15px;height:23px;",value:"x"});
    var thTitle = $(this).children(".title").find(".thread_title").text();
    var thId = $(this).attr("id").substr(6);
    hideBtn.click(function(){
      threadList.push({threadTitle:thTitle, threadId:thId});
      $("#thread" + thId).children().css("background", "red");
      GM_setValue("threadList", JSON.stringify(threadList));
    });
    $(this).children(".lastpost").append(hideBtn);
  });
}