User:Archanamiya/checkexternal.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

var f=function(){
    addPortletLink('p-tb', 'javascript:json_external_links(wgPageName)', 'Check external links', 't-jsonchecklinks');
}
if (doneOnloadHook) f(); /* if imported dynamically */
else addOnloadHook(f);
 
function json_external_links(arg)
{
    document.getElementById('contentSub').innerHTML += '<br /><strong>Grabbing external links information for ' + wgTitle + '. <br />Please wait...</strong>';
    var pageurl = 'http://tools.wikimedia.de/~dispenser/cgi-bin/jsonchecklinks.py?page=' + arg;
    var scriptElem = document.createElement( 'script' );
    scriptElem.setAttribute( 'src' , pageurl );
    scriptElem.setAttribute( 'type' , 'text/javascript' );
    document.getElementsByTagName( 'head' )[0].appendChild( scriptElem ); 
}
 
function checklinksDone()
{
    /* Get number of external links */
    if(checklinks.links.length -1 >= 1)
    {
        for (i = 0;i<checklinks.links.length - 1;i++)
        {
            /* If link is fine */
            if (checklinks.links[i].status === 200)
            {
                textcolour = '#000000';
                colour = '#00FF00';
                reason = '';
            } else
            {
                textcolour = '#FFFFFF';
                colour = '#FF0000';
                reason = '<br />Reason : ' + checklinks.links[i].reason;
            }
            document.getElementById('contentSub').innerHTML += '<br /><strong><span style="color:' + textcolour + '; background:' + colour + ';">Link: <a href="' + checklinks.links[i].url + '" style="color:' + textcolour + ';">' + checklinks.links[i].url + '</a> : ' + checklinks.links[i].status + reason + '</strong></span>';
        }
    } else
    {
    document.getElementById('contentSub').innerHTML += '<br /><strong><span style="color:#FF0000">No links!</span></strong>';
    }
}