User:AmiDaniel/monobook.js

From Wikipedia

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror:: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences.

/* <pre> */

/**
 * This is a simple little helper function for JVP2, needed to append text and submit forms.
 * You will need this added to your monobook.js in order for JVP2 to work!
 *
 * Author: Daniel Cannon (alias [[User:AmiDaniel|AmiDaniel]])
 *
 */

addOnloadHook( function() {
	if (location.href.indexOf("&action=edit") == -1 || location.href.indexOf("&dosave=") == -1) return;

	/* Safeguard against primitive browser hijacking. */
	var now = new Date();
	var curTime = "" + now.getTime();
        
        var token = location.href.split("&dosave=")[1].split("&")[0];

	if (!(token.length > 4) || curTime.indexOf(token) == -1) {
            document.getElementById('content').innerHTML = "<H1>DoSave failed. Invalid token: " 
                 + token + " " + curTime + document.getElementById('content').innerHTML + "</H1>";
            return;
        }

	document.getElementById('content').innerHTML = "<H1>The page is being saved. Please wait." 
		+ document.getElementById('content').innerHTML + "</H1>";

	/* Set the edit summary. */
	var sum = location.href.split("&sum=")[1].split("&")[0];
	document.getElementById('wpSummary').value = sum.replace("%20", " ");

	/* Append the text. */
	if (location.href.indexOf("&append=") != -1) {
		var append = location.href.split("&append=")[1].split("&")[0];
		document.getElementById('wpTextbox1').value += "\n\n" + append.replace("%20", " ");
	}

	/* Mark as minor. */
	document.getElementById('wpMinoredit').checked = 'checked';

	/* Submit the form. */
	document.getElementById('editform').submit();
});

/* </pre>*/
Navigation