User:Manishearth/GadgetUS/generate.js

//Tabbed page stuff var prefStarted=false var inter; function startPref(page,title,heading,formID,handler){ if(mw.config.get('wgPageName')==page&&document.getElementById("bodyContent")){ document.getElementById("bodyContent").innerHTML="" document.getElementById("firstHeading").innerHTML=heading document.title=title prefStarted=true; if(handler){ handler }	} } var sections = 0 function addSection(buttonName,sectionText){ if(!prefStarted){ setTimeout("addSection('"+buttonName+"','"+sectionText+"')",1000) return; }	document.getElementById('preftoc').innerHTML+=""+buttonName+"" document.getElementById('preferences').innerHTML+=""+sectionText+" " sections++ openSection(0) } function openSection(section){ if(!prefStarted){return} for(i=0;i<sections;i++){ document.getElementById("prefbutton-"+i).className="" document.getElementById("prefsection-"+i).style.display="none" }	document.getElementById("prefbutton-"+section).className="selected" document.getElementById("prefsection-"+section).style.display="" } startPref("Special:Scripts","Userscripts","Userscripts","USForm",populateUSPage)

//Populate the page function populateUSPage{ if(typeof USGroups=="undefined"){ setTimeout("populateUSPage",100) return; }	for(var i=0;i" //forgetme tells the script not to import it

}

function checkBoxes{ var undefined; if(importsLoaded===undefined){ return; } clearInterval(inter); for(i=0;i<myScripts.length;i++){ document.getElementById("scriptbox-"+myScripts[i]).checked=true; }

}

function saveUS{ var _api = sajax_init_object; _api.open('GET', 'http://en.wikipedia.org/w/index.php?title=User:'+mw.config.get('wgUserName')+'/GadgetUSimports.js&action=render', true); _api.onreadystatechange = function{checkFirst(_api)}; _api.send(null); }

function checkFirst(_api){ if(_api.readyState==4) { if(_api.status==200){ if(_api.responseText.indexOf(importsHeader)==-1){ var pageContent="\/\*"+importsHeader+"\*\/\n\/\/ \nvar myScripts=[]\n\/\/ \n\/\/ \n\/\/ " editPage("User:"+mw.config.get('wgUserName')+"/GadgetUSimports.js",pageContent)

}		condenseFormData } } }

function condenseFormData{ var frmElmt=document.getElementById("USForm").elements for(var i=0;i<frmElmt.length;i++){

} }

var api = sajax_init_object; function editPage(page,text,handler){ if(!handler){ handler=function{} }	api.open('GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=json&action=query&prop=info&indexpageids=1&intoken=edit&titles=Whatever', true); api.onreadystatechange = function{extract_token(page,text,handler)}; api.send(null);

} function extract_token(page,text,handler) { if(api.readyState==4) { if(api.status==200) { var response = eval('(' + api.responseText + ')'); var token = response['query']['pages'][response['query']['pageids'][0]]['edittoken']; edit_page(token,page,text,handler); }		else { alert('The token query returned an error.'); }	} } // edit page (must be done through POST) function edit_page(_token,page,text,handler) { var parameters = 'action=edit&title='+page+'&text='+text+'&token=' + encodeURIComponent(_token); api.open('POST', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php', true); // just reuse the same query object api.onreadystatechange = editOver; api.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); api.setRequestHeader('Connection', 'keep-alive'); api.setRequestHeader('Content-length', parameters.length); api.send(parameters); function editOver{ if(api.readyState==4) { if(api.status==200) { handler }			else { alert('Error saving'); location.reload; }		}

}

}