User:Megadardery/common.js

From the Super Mario Wiki, the Mario encyclopedia
Jump to navigationJump 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.
function AddSidebarItem(heading, title, link, tooltip) {
    try {
        switch (heading) {
          case "languages":
            var target = "p-lang";
            break;
          case "toolbox":
            var target = "p-tb";
            break;
          case "navigation":
            var target = "p-navigation";
            break;
          default:
            var target = "p-" + section;
            break;
        }
            var node = document.getElementById(target)
                               .getElementsByTagName('div')[0]
                               .getElementsByTagName('ul')[0];
 
            var aNode = document.createElement('a');
            var liNode = document.createElement('li');
 
            aNode.appendChild(document.createTextNode(title));
            aNode.setAttribute('href', link);
            aNode.setAttribute('title', tooltip);
            liNode.appendChild(aNode);
            liNode.className='plainlinks';
            node.appendChild(liNode);

 
    } catch(e) {
      return;
    }
}
function AddTab(action, after, tooltip, shortcutbutton) {

	mw.util.addPortletLink(
		'p-cactions', 
		wgScript + "?title=" + wgPageName + "&action=" + action,
		action,
		'ca-' + action,
		tooltip,
		shortcutbutton,
		document.getElementById('ca-' + after).nextSibling
	);
    
	document.getElementById('ca-' + action).parentNode.insertBefore(document.createTextNode("\n"), document.getElementById('ca-' + action));

	if (wgAction == action) {
		document.getElementById('ca-' + action).className += "selected";
	}
}
 
function Summary(entervalue) {
    document.editform.wpSummary.value = entervalue;
}

if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload' && !document.getElementById('wpForReUpload') && !document.getElementsByClassName('warning')[0] && !document.getElementsByClassName('error')[0])
{
  function loadAutoAboutfileTemplate()
  {
   uploadDescription = document.getElementById('wpUploadDescription');

   uploadDescription.value = '{' + '{' + 'aboutfile\n|1=[[<SUBJECT>]] in the game \'\'[[<GAME>]]\'\'.\n|2=Taken from an emulator\n}}[[Category:<GAME> Images]]';
  }

  addOnloadHook(loadAutoAboutfileTemplate);
}

function SidebarItems() {
        AddSidebarItem("toolbox", "Preview Subpages", wgServer+wgArticlePath.replace("$1", "Special:PrefixIndex/"+wgPageName+"/"), "Preview all subpages of this page.");
        AddSidebarItem("toolbox", "Purge the Cache", wgServer+wgArticlePath.replace("$1", "index.php?title="+wgPageName+"&action=purge"), "Purge this page to clear the cache and force the most current revision to appear.");
}
function Tabs() {
        AddTab("info", "history", "Show helpful info for the current page.", "i");
        AddTab("purge", "move", "Purge this page to clear the cache and force the most current revision to appear.", "u");
}

var customizeToolbar = function() {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'advanced',
        group: 'format',
        tools: {
                "comment": {
                        label: 'Comment',
                        type: 'button',
                        icon: '//upload.wikimedia.org/wikipedia/commons/3/37/Btn_toolbar_commentaire.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "<!-- ",
                                        peri: "Comment",
                                        post: " -->"
                                }
                        }
                }
        }
} );

};

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.using( 'user.options', function () {
                if ( mw.user.options.get('usebetatoolbar') ) {
                        mw.loader.using( 'ext.wikiEditor.toolbar', function () {
                                $(document).ready( customizeToolbar );
                        } );
                }
        } );
}
// Add the customizations to LiquidThreads' edit toolbar, if available
mw.hook( 'ext.lqt.textareaCreated' ).add( customizeToolbar );


//Enable or disable the above codes
addOnloadHook(Tabs);
addOnloadHook(SidebarItems);
//addOnloadHook(Summary('CodeHere'));