User:Microchip08/monobook.js

From Wikibooks

Jump to: navigation, search

Note - After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

importScriptURI('http://meta.wikimedia.org/w/index.php?title=User:Microchip08/global.js&action=raw&ctype=text/javascript');
 
/**
 * A function from [[wikt:en:User:Visviva/pretext.js]] to allow arbitrary
 * text to be inserted into the edit box through the URL.
 *
 * Visit a url of the form ?action=edit&preloadtext=<something>&preloadsummary=
 */
 
function preloadText() { 
    var pretext=""
    var presummary=""
    try {
        parts=window.location.search.split("?")[1].split("&")
    } catch (e) {
        return; //not an edit page
    }
 
    for (p in parts) {
        pair=parts[p].split("=")
        if (pair[0]=="preloadtext") {
            pretext=unescape(pair[1])
        }else if (pair[0]=="preloadsummary") {
            presummary=unescape(pair[1])
        }
    }
    if (pretext != ""){
        if (document.editform.wpTextbox1.value != ""){
            pretext+="\n\n"
        }
        pretext=pretext+document.editform.wpTextbox1.value
        document.editform.wpTextbox1.value=pretext
    }
 
    if (presummary != "") {
        document.editform.wpSummary.value += presummary;
    }
}
 
addOnloadHook( preloadText );