Jump to content

User:TheFearow/ajax.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TheFearow (talk | contribs) at 23:10, 15 August 2007 (Fixed some errors, added protect and delete). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// TheFearow's similair-to-ajax framework for Wikipedia

function createFrame(href){
 var frame = document.createElement('iframe');
 frame.setAttribute('src', href);
 frame.setAttribute('width', '0');
 frame.setAttribute('height', '0');
 frame.setAttribute('style', 'display:none;');
 frame.setAttribute('id', 'tfajaxframe');
 return frame;
}

function addFrame(frame){
 document.childNodes[1].appendChild(frame);
}

function getFrameDocument(){
 return document.getElementByID('tfajaxframe').contentDocument;
}

function finaliseFrame(){
 document.getElementByID('tfajaxframe') = null;
}

function getPageText(pagename){
 var name = unescape(pagename);
 var frame = createFrame(wgServer + wgScript + "?title=" + name + "&action=edit");
 addFrame(frame);
 var doc = getFrameDocument();
 var content = doc.editform.wpTextbox1.value;
 finaliseFrame();
 return content;
}

function editPage(pagename, newtext, summary, minor, watch){
 var name = unescape(pagename);
 var frame = createFrame(wgServer + wgScript + "?title=" + name + "&action=edit");
 addFrame(frame);
 var doc = getFrameDocument();http://en.wikipedia.org/w/index.php?title=User:TheFearow/ajax.js&action=edit
 doc.editform.wpTextbox1.value = newtext;
 doc.editform.wpSummary.value = summary;
 doc.editform.wpMinoredit.value = minor;
 doc.editform.wpWatchthis.value = watch;
 doc.editform.wpSave.click();
 finaliseFrame();
}

function movePage(pagename, newname, reason, watch){
 var name = unescape(pagename);
 var frame = createFrame(wgServer + wgScript + "?title=Special:Movepage/" + name);
 addFrame(frame);
 var doc = getFrameDocument();
 doc.movepage.wpNewTitle.value = newname;
 doc.movepage.wpReason.value = reason;
 doc.movepage.wpWatch.value = watch;
 doc.movepage.wpMove.click();
 finaliseFrame();
}

function protectPage(pagename, editlevel, movelevel, cascade,  watch){
 var name = unescape(pagename);
 var frame = createFrame(wgServer + wgScript + "?title=" + name + "?action=protect");
 addFrame(frame);
 var doc = getFrameDocument();
 doc.mw-Protect-Form.mwProtect-level-edit.value = editlevel;
 doc.mw-Protect-Form.mwProtect-level-move.value = movelevel;
 doc.mw-Protect-Form.mwProtect-cascade.value = cascade;
 doc.mw-Protect-Form.mwProtectWatch.value = watch;
 doc.mw-Protect-Form.mw-Protect-submit.click();
 finaliseFrame();
}

function deletePage(pagename, reason,  watch){
 var name = unescape(pagename);
 var frame = createFrame(wgServer + wgScript + "?title=" + name + "?action=delete");
 addFrame(frame);
 var doc = getFrameDocument();
 doc.mw-Protect-Form.wpReason.value = reason;
 doc.mw-Protect-Form.wpWatch.value = watch;
 doc.mw-Protect-Form.wpConfirmB.click();
 finaliseFrame();
}