deviantART - Unhide "Flagged as Spam" Comments

By DavidJCobb Last update Aug 24, 2009 — Installed 869 times. Daily Installs: 0, 1, 2, 6, 0, 6, 1, 1, 0, 6, 2, 4, 3, 15, 17, 3, 0, 1, 4, 4, 0, 0, 4, 3, 6, 2, 1, 2, 4, 3, 0, 2

There are 2 previous versions of this script.

// ==UserScript==
// @name           deviantART - Unhide "Flagged as Spam" Comments
// @namespace      http://davidjcobb.deviantart.com/
// @description    Allows you to unhide comments that have been flagged as spam and hidden.
// @include        http://*.deviantart.com/*
// ==/UserScript==

function $CSSget(a,b) {
   b=b||a;
   a=b!=a?a:document
   var I,T,C,E,M=[],l,p=b.match(/^([^#\.]*)?(#[^\.]*)?(\.[^#]*)?(#[^\.]*)?/);
   T=(p[1]||"*").toUpperCase();
   I=(p[2]||p[4]||"#").substring(1);
   l=(C=(p[3]||".").substring(1).split(".")).length;
   if(I)E=[a.getElementById(I)];
   else E=a.getElementsByTagName(T);
   Array.forEach(E,
      function(e,i,a) {
         var b=0,CN=" "+e.className.split(".").join(" ")+" ";
         if(T!="*"&&e.tagName!=T)return;
         if(l)
            for(;b<l;b++)
               if(CN.indexOf(" "+C[b]+" ")<0)
                  return;
         M.push(e)
      }
   );
   return M
}

function $cNr(n,c) { // className remove
   n.className=n.className.replace(new RegExp("(\\s|^)"+c+"(\\s|$)","gi"),"$1$2");
}

window.ToggleComment=
function(c) {
   var node,type=c.substring(0,c.indexOf(":")+1),cid=Number(c.substring(c.indexOf(":")+1)); // comment node, dAversion, comment index
   if(type=="v5:") {
      node=window.CO[cid];
      if(node.className.indexOf("collapsed-thought")!=-1) { // hidden comments -- show
         $cNr(node,"collapsed-thought");
         $CSSget(node,"a.DJC_GM_hidelink")[0].innerHTML="[rehide]";
      } else { // shown comments -- rehide
         node.className+=" collapsed-thought"
      }
   } else if (type=="v6:") {
      node=window.CN[cid];
      if(node.className.indexOf("ccomment-hidden")!=-1) { // hidden comments -- show
         $cNr(node,"ccomment-hidden");
      } else { // shown comments -- rehide
         node.className+=" ccomment-hidden"
      }
   }
};

window.Click=
function(e) {
   var node=e.target;
   if(node.className=="DJC_GM_hidelink")
      window.ToggleComment(node.getAttribute("data"));
};

(function(){
   document.body.appendChild(document.createElement("style")).innerHTML="\
a.DJC_GM_hidelink{display:inline!important;visibility:visible!important;cursor:pointer}\n\
div.creason>a.DJC_GM_hidelink{color:#88958D!important}\
";

   var COld=$CSSget("div.collapsed-thought"); // array of nodes (old comments)
   var CNew=$CSSget("div.ccomment-hidden"); // array of nodes (new comments)
   window.CO=[]; // arrays of nodes (old/new hidden comments, respectively)
   window.CN=[];
   var a,b,bl,i=0,cl=COld.length,IDX;

   for(;i<cl;i++) {
      bl=(b=$CSSget(COld[i],"span.time")).length;
      for(a=0;a<bl;a++) {
         if(b[a].innerHTML.match(/flagged as spam/i)) {
            IDX=window.CO.push(COld[i])-1; // comment's index in window.CO
            b[a].innerHTML+="&nbsp;&nbsp;&nbsp;<a class=\"DJC_GM_hidelink\" data=\"v5:"+IDX+"\">[unhide]</a>";
         }
      }
   }

   cl=CNew.length;
   for(i=0;i<cl;i++) {
      bl=(b=$CSSget(CNew[i],"div.creason")).length;
      for(a=0;a<bl;a++) {
         if(b[a].innerHTML.match(/flagged as spam/i)) {
            IDX=window.CN.push(CNew[i])-1; // Comment's index in window.CN
            b[a].innerHTML+="&nbsp;&nbsp;&nbsp;<a class=\"DJC_GM_hidelink\" data=\"v6:"+IDX+"\">[unhide]</a>";
         }
      }
      $CSSget(CNew[i],"span.cc-time")[0].innerHTML+="&nbsp;&nbsp;&nbsp;(Spam - <a class=\"DJC_GM_hidelink\" data=\"v6:"+IDX+"\">[rehide]</a>)"; // seen when box is unhidden
   }
   
   document.addEventListener("click",window.Click,true);
})()