User:TheFearow/ajax.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
// 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(); 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, expires, watch){ var name = unescape(pagename); var frame = createFrame(wgServer + wgScript + "?title=" + name + "?action=protect"); addFrame(frame); var doc = getFrameDocument(); doc.getElementById('mwProtect-level-edit').value = editlevel; doc.getElementById('mwProtect-level-move').value = movelevel; doc.getElementById('mwProtect-cascade').value = cascade; doc.getElementById('expires').value = expires; doc.getElementById('mwProtectWatch').value = watch; doc.getElementById('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.getElementById('wpReason').value = reason; doc.getElementById('wpWatch').value = watch; doc.getElementById('wpConfirmB').click(); finaliseFrame(); }