Jump to content

User:TransporterMan/monobook.js

From Wikipedia, the free encyclopedia
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:TheJosh/Scripts/NewPagePatrol.js');

importScript('User:Ais523/watchlistnotifier.js');
importScript('User:Steven Zhang/DRW.js');
importScript("User:Yuvipanda/wizard/wizard.js");

//prevent wikiED from jumping down and turn off duplicate warnings
var wikEdConfig = { 'scrollToEdit': false, 'scrollToPreview': false, 'doCloneWarnings': false };

//Modification by SDG of ("User:PleaseStand/subsearch.js") to search current page and subpages, not just subpages
//   line below was: textbox.value += " prefix:" + nsPrefix + wgTitle + "/";
//   Script will not work, author says, in Vector

/*global window, addOnloadHook, addHandler, SubsearchJsConfig,
wgNamespaceNumber, wgFormattedNamespaces, wgTitle*/

// Global variables
var SubsearchJsCheckbox;

// Event handler called when a search is performed
function SubsearchJsSubmitHandler() {
    // Local variables
    var textbox; var nsPrefix = "";
   
    if(SubsearchJsCheckbox.checked) {
        // Note that the main namespace (0) has no prefix.
        if(mw.config.get('wgNamespaceNumber')) {
            nsPrefix = mw.config.get('wgFormattedNamespaces')[mw.config.get('wgNamespaceNumber')] + ":";
        }
        textbox = window.document.getElementById("searchInput");
        textbox.value += " prefix:" + nsPrefix + mw.config.get('wgTitle');
        SubsearchJsCheckbox.checked = false;
    }
    return true;
}

$(function () {
    // Local variables
    var label; var labelText; var searchform;
   
    try {
    if(typeof SubsearchJsConfig != "object") {
       
        // Default configuration
        SubsearchJsConfig = {
            text: "\u00a0Subpages only",
            tooltip: "Search only the subpages of the current page",
            accesskey: "",
            style: "display: block; font-size: 80%; margin-top: 0.4em;",
            namespaces: // Update the following line from http://en.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=namespaces&format=json
            {"query":{"namespaces":{"-2":{"id":-2,"*":"Media","canonical":"Media"},"-1":{"id":-1,"*":"Special","canonical":"Special"},"0":{"id":0,"*":"","content":""},"1":{"id":1,"*":"Talk","subpages":"","canonical":"Talk"},"2":{"id":2,"*":"User","subpages":"","canonical":"User"},"3":{"id":3,"*":"User talk","subpages":"","canonical":"User talk"},"4":{"id":4,"*":"Wikipedia","subpages":"","canonical":"Project"},"5":{"id":5,"*":"Wikipedia talk","subpages":"","canonical":"Project talk"},"6":{"id":6,"*":"File","canonical":"File"},"7":{"id":7,"*":"File talk","subpages":"","canonical":"File talk"},"8":{"id":8,"*":"MediaWiki","canonical":"MediaWiki"},"9":{"id":9,"*":"MediaWiki talk","subpages":"","canonical":"MediaWiki talk"},"10":{"id":10,"*":"Template","subpages":"","canonical":"Template"},"11":{"id":11,"*":"Template talk","subpages":"","canonical":"Template talk"},"12":{"id":12,"*":"Help","subpages":"","canonical":"Help"},"13":{"id":13,"*":"Help talk","subpages":"","canonical":"Help talk"},"14":{"id":14,"*":"Category","canonical":"Category"},"15":{"id":15,"*":"Category talk","subpages":"","canonical":"Category talk"},"100":{"id":100,"*":"Portal","subpages":"","canonical":"Portal"},"101":{"id":101,"*":"Portal talk","subpages":"","canonical":"Portal talk"},"108":{"id":108,"*":"Book","subpages":"","canonical":"Book"},"109":{"id":109,"*":"Book talk","subpages":"","canonical":"Book talk"}}}}
        };
       
    }
   
    // Make sure the current page's namespace has subpages turned on.
    if(!SubsearchJsConfig.namespaces.query.namespaces[mw.config.get('wgNamespaceNumber')].
    hasOwnProperty("subpages")) {
        return false;
    }
   
    // Add the checkbox if so.
    label = window.document.createElement("label");
    label.setAttribute("title", SubsearchJsConfig.tooltip);
    label.setAttribute("style", SubsearchJsConfig.style);
    SubsearchJsCheckbox = window.document.createElement("input");
    SubsearchJsCheckbox.setAttribute("type", "checkbox");
    SubsearchJsCheckbox.setAttribute("accesskey", SubsearchJsConfig.accesskey);
    label.appendChild(SubsearchJsCheckbox);
    labelText = window.document.createTextNode(SubsearchJsConfig.text);
    label.appendChild(labelText);
    searchform = window.document.getElementById("searchform");
    searchform.appendChild(label);
   
    // Add the submit handler to the search form.
    addHandler(searchform, "submit", SubsearchJsSubmitHandler);
   
    } catch(e) {}
    return false;
});

//Modification by SDG of ("User:PleaseStand/subsearch.js") ends

//Adds subpage link to left bar
$( function () {
  mw.util.addPortletLink("p-tb", mw.config.get('wgServer')+mw.config.get('wgArticlePath').replace("$1", "Special:PrefixIndex/"+mw.config.get('wgPageName')+"/"), "Subpages", "t-subpages", "See all subpages of this page");
});

//Adds multiple history and edit tabs
//Source - [[User:Js/6tabs-vector]]
if (mw.config.get('wgNamespaceNumber') >= 0)
$(function(){
 var pCactions = document.getElementById('p-cactions');
 if (!pCactions) return;
 var caMain = pCactions.getElementsByTagName('li')[0];
 var caTalk = document.getElementById('ca-talk');
 var caEdit = document.getElementById('ca-edit');
 if (!caEdit) caEdit = document.getElementById('ca-viewsource');
 var caHistory = document.getElementById('ca-history');
 if (!caMain || !caTalk || !caEdit || !caHistory) return;
 var el_move, el_create, id2;
 if (mw.config.get('wgNamespaceNumber') % 2) { //talk space
   el_move = caTalk; el_create = caMain; id2 = '';
 } else {
   el_move = caMain; el_create = caTalk; id2 = 'discussion';
 }
 caEdit.firstChild.innerHTML = 'edit';
 caHistory.firstChild.innerHTML = 'hist';
 el_move.parentNode.insertBefore(caHistory, el_move.nextSibling);
 el_move.parentNode.insertBefore(caEdit, el_move.nextSibling);
 var href = el_create.firstChild.getAttribute('href', 2);
 if (el_create.className.indexOf('new') < 0){
   mw.util.addPortletLink('p-cactions', href + '?action=history', 'hist',
     'ca-history-'+id2, id2+' history', '', el_create.nextSibling);
   mw.util.addPortletLink('p-cactions', href + '?action=edit', 'edit',
     'ca-edit-'+id2, 'Edit '+id2, '', el_create.nextSibling);
 } 
  caMain.style.marginRight = '0.3em'; 
  caTalk.style.marginRight = '0.3em'; 
  caTalk.style.marginLeft  = '1.6em'; 
})
//