deviantART - Quick +devWATCH

By DavidJCobb Last update Jul 30, 2009 — Installed 1,196 times. Daily Installs: 2, 2, 6, 3, 4, 4, 5, 4, 2, 3, 2, 4, 2, 4, 4, 2, 3, 2, 7, 5, 4, 4, 4, 5, 2, 3, 4, 4, 4, 3, 3, 3

There are 5 previous versions of this script.

// ==UserScript==
// @name           deviantART Quick +devWATCH
// @description    Alters the +devWATCH link on profiles so you can +devWATCH without even leaving the page.
// @namespace      http://davidjcobb.deviantart.com
// @include        http://*.deviantart.com
// @include        http://*.deviantart.com/
// @include        http://*.deviantart.com/gallery
// @include        http://*.deviantart.com/gallery/
// @include        http://*.deviantart.com/gallery/*
// @exclude        http://www.deviantart.com
// @exclude        http://www.deviantart.com/
// @exclude        http://about.deviantart.com*
// @exclude        http://browse.deviantart.com*
// @exclude        http://chat.deviantart.com*
// @exclude        http://forum.deviantart.com*
// @exclude        http://help.deviantart.com*
// @exclude        http://my.deviantart.com*
// @exclude        http://news.deviantart.com*
// @exclude        http://services.deviantart.com*
// @exclude        http://shop.deviantart.com*
// @exclude        http://store.deviantart.com*
// @exclude        http://today.deviantart.com*
// ==/UserScript==

window.link=null;
window.user="";

document.addEventListener("click",function(e){if(e.target.id!="djc-devwatch")return;window.nW()},!0);

window.error=function(s,d) {
   alert("Unable to +deviantWATCH "+window.user+".\n\nPlease try again.");
   window.link.node.innerHTML=window.link.node.innerHTML.replace(/Adding\.\.\./i,"+devWATCH");
};

window.verify=function(s,d) { // verify success using another request.
   GM_xmlhttpRequest(
      {
         method:"GET",
         url:"http://"+window.user+".deviantart.com/journal/1/",
         onload:
            function(r) {
               if(r.responseText.indexOf('<a href="http://my.deviantart.com/deviants/" class="gmbutton2 disabledbutton" title="You are already watching ')>0) return window.success();
               window.error();
            },
         onerror:window.error
      }
   );
};

window.success=function() {
   var l=window.link.node,t=window.link.text;
   l.innerHTML=l.innerHTML.replace(/Adding\.\.\./i,(t=="+deviantWATCH")?"+deviantWATCH":["Watch this deviant","Watching this deviant"][Number(success)]);
   if(l.className.indexOf("gmbutton2")>=0)l.className+=" disabledbutton";
   l.href="http://my.deviantart.com/deviants";
};

window.nW=function(u) { // code for actually adding to watchlist

   var l=window.link.node,u=u||window.user;

   GM_xmlhttpRequest(
      {
         method:"POST",
         url:"http://my.deviantart.com/deviants/add",
         headers:
            {
               "Content-Type":"application/x-www-form-urlencoded"
            },
         data:"username="+window.user,
         onload:
            function(r) {
               window[r.status==200?"verify":"error"]();
            },
         onerror:window.error
      }
   );

   l.innerHTML=l.innerHTML.replace(/\+deviantWATCH|Watch this deviant/,"Adding...");

   return !1;
};

var Setup = function() {
   var link,i=0,user,toArray=function(a){var A=[],i=0;for(;i<a.length;i++){A.push(a[i])}return A},
       $SS=function(a,b){var S=(b||a).match(/^([^#\.]*)(#[^.]*)?(\.[^#]*)?(#[^.]*)?$/),T=(S[1]||"").toUpperCase(),I=(S[2]||S[4]||"").substring(1),C=(S[3]||"").substring(1).replace(/\./g," ").replace(/^\s+|\s+$/g,"");if(!C&&I)return [(b?a:document).getElementById(I)];if(!C&&T)return toArray((b?a:document).getElementsByTagName(T));return Array.filter((b?a:document).getElementsByClassName(C),function(e){if(I&&e.id!=I)return !1;if(T&&e.nodeName!=T)return !1;return 1})},
       $SSm=function(n,s){var S=s.match(/^([^#\.]*)(#[^.]*)?(\.[^#]*)?(#[^.]*)?$/),T=(S[1]||"").toUpperCase(),C=((S[3]||"")+".").replace(/\./g," ").replace(/^\s+|\s+$/g," ");I=(S[2]||S[4]||"").substring(1);if(I&&n.id!=I||T&&n.tagName!=T)return 0;if(!C.replace(/\s/g,""))return 1;return Array.filter(C,function(e){return (" "+n.className+" ").indexOf(C)!=-1}).length==C.length},
       $SST=function(a,b){if(!b){b=" "+a;a=[document]}var S=b.split(/\s*([\s>\+])\s*/g),i=0,E=[],curNodes=a,nextNodes=[],s;S.splice(0,1);switch(S[0]){case " ":for(;i<curNodes.length;i++){nextNodes=nextNodes.concat($SS(curNodes[i],S[1]))}break;case ">":for(;i<curNodes.length;i++){nextNodes=nextNodes.concat(Array.filter($SS(curNodes[i],S[1]),function(e){return e.parentNode==curNodes[i]}))}break;case "+":for(;i<curNodes.length;i++){for(j=curNodes[i].nextSibling;!j.tagName;j=j.nextSibling){}if(j&&$SSm(j,S[1]))nextNodes.push(j)}break}if(!nextNodes.length||S.length==2)return nextNodes;s=[].concat(S);s.splice(0,2);E=E.concat($SST(nextNodes,s.join("")));return E};

   try{if(window.WLR)return -3}catch(e){}

   user=window.user=(window.location.hostname.match(/^(www\.|)([a-zA-Z\d-]*?)\.deviantart\.com/)||[0,0,null])[2];
   if(!user)return GM_log("Unable to figure out whose userpage we're on!");

   // confirm on userpage
   if($SST("#deviant h1>a.u")[0].innerHTML.indexOf(user)==-1)return GM_log("Not a userpage.");
   if($SST("#logindock a.u")[0].href=="http://"+user+".deviantart.com/")return GM_log("Own userpage.");

   link=$SST("#watch-form+a.gmbutton2")[0];
   if(!link){alert($SST("#watch-form+a.gmbutton2"))}
   if(link.getAttribute("href")==""&&link.getAttribute("onclick").indexOf("watch-form")>0){
      link.id="djc-devwatch";
      link.href="javascript:void(0);";
      link.removeAttribute("onclick","");

      window.link=
         {
            text:link.textContent,
            get node(){return document.getElementById("djc-devwatch")}
         };

      GM_log("Quick +devWATCH: Found and altered the link.");

      return (window.WLR=!0)
   } else if (link.innerHTML.indexOf("atching")>0||link.className.indexOf("disabledbutton")>=0) {
      return -3
   }
};

Setup();

//GM_registerMenuCommand("Debug Quick +devWATCH",function(){unsafeWindow.QDW=window});