Jump to content

User:Gregbard/vector.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gregbard (talk | contribs) at 19:24, 16 June 2010 (unwatch). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
importScript('User:Quarl/util.js');
importScript('User:Quarl/wikipage.js');

importScript('Wikipedia:WikiProject User scripts/Scripts/Add LI menu');
importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css');
importScript('User:AzaToth/twinkle.js');
importScript('Wikipedia:WikiProject Deletion sorting/delsort.js');

importScript('User:Lupin/popups.js'); // see Wikipedia:Tools/Navigation popups

importScript('User:Anomie/util.js');
importScript('User:Anomie/linkclassifier.js'); // Linkback: [[User:Anomie/linkclassifier.js]]


/* This script adds an "unwatch" link to each entry in your watchlist, using the new
 * ajax watchlist thing.
 */

var wlUnwatch = {
    supported:true,
    onLoad:function(){
        if(!document.forms[0] || !document.forms[0].namespace) return;
        var links=document.getElementById('content').getElementsByTagName('a');
        var j;
        for(var i=links.length-1; i>=0; i--){
            if(/[?&]action=history([&#]|$)/.test(links[i].href)){
                j=i;
            } else if(/\/Special:Log\//.test(links[i].href)){
                j=i+4;
            } else {
                continue;
            }
            var m=links[j].href.match(/title=([^&]*)/);
            if(!m) continue;
            var a=document.createElement('A');
            a.href=wgServer+wgScript+'?action=unwatch&title='+m[1];
            a.title=wgAjaxWatch.unwatchMsg+' '+links[j].title;
            a.unwatchInProgress=false;
            a.onclick=wlUnwatch.onClick;
            a.appendChild(document.createTextNode('unw'));
            links[i].parentNode.insertBefore(a, links[i].nextSibling);

            // insert a delimiter between the two links
            var d=document.createTextNode('\xa0| ');
            links[i].parentNode.insertBefore(d, a);
        }
    },

    onClick:function(){
        if(!wlUnwatch.supported) return true;
        var obj=this;
        if(obj.unwatchInProgress) return false;
        if(!wfSupportsAjax()){
            wlUnwatch.supported=false;
            return true;
        }
        obj.unwatchInProgress=true;
        obj.style.color='red';
        var timeout=setTimeout(function(){
            timeout=null;
            obj.unwatchInProgress=false;
            obj.style.color='';
        }, 10000);
        sajax_do_call('wfAjaxWatch',
            [decodeURIComponent(obj.href.match(/&title=(.+)/)[1]), 'u'],
            function(req){
                if(timeout) clearTimeout(timeout);
                timeout=null;
                obj.unwatchInProgress=false;
                obj.style.color='';
                if(!/^<u#>/.test(req.responseText)) return;
                var li;
                for(li=obj; li && li.nodeName!='LI'; li=li.parentNode);
                if(li) li.parentNode.removeChild(li);
            });
        return false;
    }
};

if(wgCanonicalSpecialPageName && wgCanonicalSpecialPageName=="Watchlist" && wgAction=='view'){
    if(doneOnloadHook) wlUnwatch.onLoad(); //if imported dynamically
    else addOnloadHook(wlUnwatch.onLoad)
}