User:Rahk EX/instaedit.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Rahk EX/instaedit. |
// <source lang="JavaScript">
// Make it load!
addOnloadHook(testy);
// This is what is loaded first
function testy() {
var article = document.getElementById('bodyContent');
// on doubleclick go to the change function
article.addEventListener('dblclick', change, false);
}
// Create the insertAfter function (useful)
function insertAfter(parent, node, referenceNode) {
parent.insertBefore(node, referenceNode.nextSibling);
}
function editpage() {
frame = document.createElement("IFRAME");
frame.setAttribute('src', wgServer + wgScriptPath + '/index.php?title=' + wgPageName + '&action=edit');
frame.setAttribute('height', '1');
frame.setAttribute('width', '1');
document.body.appendChild(frame);
// Below line may be useful, commented for now
// e = frame.contentDocument;
document.all.wpTextbox1.innerHTML = document.getElementById('wpTextbox2').innerHTML;
document.getElementById('wpSummary').value = "Made test edit with script."; // TODO
document.getElementById('wpSave').click();
cancel();
}
function cancel() {
// kill the textarea
document.getElementById('content').removeChild(form);
// kill the cancel button
document.getElementById('content').removeChild(cancelbutton);
// kill the save button
document.getElementById('content').removeChild(editbutton);
// make the article visible
document.getElementById('bodyContent').style.visibility = 'visible';
}
// Create the change function that is called when the article is double-clicked
function change() {
if(document.getElementById('bodyContent').style.visibility != 'hidden') {
document.getElementById('bodyContent').style.visibility = 'hidden';
// document.getElementById('happydiv').innerHTML='';
// document.getElementById('form').type='text';
form = document.createElement('textarea');
// form.setAttribute('input', 'text');
form.setAttribute('id', 'wpTextbox2');
form.setAttribute('rows', '25');
form.setAttribute('cols', '80');
cancelbutton = document.createElement('button');
cancelbutton.setAttribute('id', 'cancelbutton');
cancelbutton.innerHTML = 'Cancel';
cancelbutton.addEventListener('click', cancel, false);
editbutton = document.createElement('button');
editbutton.setAttribute('id', 'editbutton');
editbutton.innerHTML = 'Save';
editbutton.addEventListener('click', editpage, false);
document.getElementById('content').insertBefore(form, document.getElementById('bodyContent'));
insertAfter(document.getElementById('content'), cancelbutton, form);
document.getElementById('content').insertBefore(editbutton, cancelbutton);
a=sajax_init_object();
var request = wgServer + wgScriptPath + '/index.php?title=' + wgPageName + '&action=raw'; // helps debugging
a.open("GET", request, true);
a.onreadystatechange = function()
{
if(a.readyState != 4) return;
document.getElementById('wpTextbox2').innerHTML = a.responseText;
};
a.send(null);
}
}
// </source>