User:Alien333/common.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

/* global $, mw */
"use strict";
importScript("User:Alien333/poemise.js");
importScript("User:Alien333/tocify.js");
importScript("User:Alien333/nobr.js");
importScript("User:Alien333/clean.js");
mw.loader.using(['mediawiki.util'], () => {

  $(() => { 
  	
    if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) < 0) { // if not editing
        return;
    }
    
    if (mw.config.get('wgCanonicalNamespace') == '' && mw.config.get("wgPageName").search("/") != -1) { // too specific stuff
    	mainspacetricks();
    }

    
  });
}); 


var transclude = "from= to= "; // type of transclusion
function mainspacetricks() { 
	var l = $('#wpTextbox1').val();
	var name = mw.config.get("wgPageName").split("/")[0].replaceAll("(", "").replaceAll(")", "").replaceAll("_", " "); // again, my own naming conventions for indexes
	if (name.slice(0,6) == "Poems ") {
		l = l.replace("[[../]]", "[[../|Poems]]");// I usually do works titled Poems (author name), this keeps me from having to add |Poems for every single subpage
	}
	l = l.replace("| previous   = \n", "| previous   = [[../\n");
	l = l.replace("| next       = \n", "| next       = [[../\n");
	if (l.search("<pages") == -1) {
		l = l + '<pages index="'+name +'.djvu" ' + transclude + '/>';
	}
	$("#wpTextbox1").val(l);
}