User:Justin Folvarcik/common.js

From Zelda Wiki, the Zelda encyclopedia
Revision as of 01:37, 6 January 2015 by Justin Folvarcik (talk | contribs) (Ready to test)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// --------------------------------------------------------
// Perma-link to disambiguation links page
// --------------------------------------------------------
addOnloadHook(function () {
    {addPortletLink('p-Community', '/Special:Disambiguations',
                  "Disambiguation Links", 't-test', 'This page shows links to disambiguation pages. These need to be tackled.');}
});
// --------------------------------------------------------
// UTC Clock
// Adds a live UTC clock to the personal links.
// --------------------------------------------------------

function liveClock(){
    liveClock.node = addPortletLink( 'p-personal', wgServer + '/index.php?title=' + encodeURIComponent(wgPageName) + '&action=view', '', 'utcdate' );
    liveClock.node.style.fontSize = 'larger';
    liveClock.node.style.fontWeight = 'bolder';

    showTime();
}
addOnloadHook(liveClock);

function showTime(){
    var dateNode = liveClock.node;
    if( !dateNode ) {
        return;
    }

    var now = new Date();
    var hh = now.getUTCHours();
    var mm = now.getUTCMinutes();
    var ss = now.getUTCSeconds();
    var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss );
    dateNode.firstChild.replaceChild( document.createTextNode( time ), dateNode.firstChild.firstChild );

    window.setTimeout(showTime, 1000);
}

//

// --------------------------------------------------------
// Check tab. Allows me to cross reference the Zeldapedia
// version of an article to detect copypasta.
// --------------------------------------------------------
addOnloadHook(function () {
{addPortletLink('p-cactions', "http://zelda.wikia.com/wiki/" + wgPageName,
"Check", 'ca-cr', "Check the Zeldapedia version of this article to detect copy-paste jobs.", '2');}
});
//
// --------------------------------------------------------
// Recent Changes w/ unpatrolled edits only
// Takes me straight to the patrol backlog. Weee!
// --------------------------------------------------------
addOnloadHook(function () {
    {addPortletLink('p-Navigation', '/index.php?title=Special:RecentChanges&hidepatrolled=1&limit=50000&days=500',
                  "Patrol Backlog", 't-backlog', 'Jump straight into the patrol backlog and start patrolling edits.');}
});

// --------------------------------------------------------
// Files to be deleted.
// For maintenance and shiz
// --------------------------------------------------------
addOnloadHook(function () {
    {addPortletLink('p-Navigation', '/Category:Images_for_deletion',
                  "Images for Deletion", 't-imgs', 'Files marked with imdel.');}
});

/**
 * Remove duplicate links with a button
 */
if (wgAction == "edit"){

mw.toolbar.addButton( {
                imageFile: 'http://zeldawiki.org/images/2/20/Button_cite_template.png',
                speedTip: 'Remove duplicate links',
                callback: removeDuplicateLinks(),
        } );
function removeDuplicateLinks(){
    
    var box =$('[id^=wpTextbox]');
    var text = box.val();
    var start=text.split('[[');
    var i;
    for (i = 0;typeof(start[i]) !== 'undefined' ;i++){
        start[i] = start[i].split(']]')[0];

        start.split('|');
        typeof(start[i][1]) !== 'undefined' ? 
            start[i] = start[i][1]:
            start[i] = start[i][0];
        text = text.replace('[[' + start[i] + ']]', start[i]);
    }
    box.val(text);
}
}

/**
*  Force removal of "leave redirect" box for file moves.
*/
if (wgPageName.toLowerCase().indexOf("move") >= 0 && wgPageName.toLowerCase().indexOf("file") >= 0){
    var input = $("#wpLeaveRedirect");
    input.removeAttr("checked");
    input.value("0");
    input.parent().hide();
}