User:Lightdarkness/monogooey.js

function inc (file) { mw.loader.load('/w/index.php?title='+file+'&action=raw&ctype=text/javascript&dontcountme=s'); }

function createCookie(name,value,days) {	if (days) {		var date = new Date; date.setTime(date.getTime+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString; }	else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; }

function eraseCookie(name) {	createCookie(name,"",-1); }

function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "=") if (c_start!=-1) {    c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) }  } return null }

function Get_Cookie( name ) { var start = document.cookie.indexOf( name + "=" ); var len = start + name.length + 1; if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { return null; } if ( start == -1 ) return null; var end = document.cookie.indexOf( ";", len ); if ( end == -1 ) end = document.cookie.length; return unescape( document.cookie.substring( len, end ) ); }

function setCookie(c_name,value,expiredays) { var cookie_string = c_name + "=" + escape ( value );

exp_y = '2012'; exp_m = '12'; exp_d = '12';

var expires = new Date ( exp_y, exp_m, exp_d ); cookie_string += "; expires=" + expires.toGMTString;

path = '/'; cookie_string += "; path=" + escape ( path ); document.cookie = cookie_string; }

function Delete_Cookie( name, path, domain ) { if ( Get_Cookie( name ) ) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; }

var software = new Array; var username = getCookie('enwikiUserName'); inc("User:" + username + "/config.js");

if (document.implementation.createDocument) { var gml_xmlparser = new DOMParser; }

function gml_XMLParse(string) { if (document.implementation.createDocument) { return gml_xmlparser.parseFromString(string, "text/xml"); } else if (window.ActiveXObject) { var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM"); gml_xmldoc.async = "false"; ret = gml_xmldoc.loadXML(string); if (!ret) return null; return gml_xmldoc.documentElement; } return null; }

var gml_xmlhttp;

function HTTPClient { var gml_http; if(window.XMLHttpRequest) { gml_http = new XMLHttpRequest; } else if (window.ActiveXObject) { try { gml_http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { gml_http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { gml_http = false; }   }  }  return gml_http; }

var softwarePackageInstall; var softwarePackageConfig;

function UpdateConfig(softwarePackage){

softwarePackageConfig = softwarePackage; var username = document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML; document.getElementById('bodyContent').innerHTML = 'Please wait' + '...'; gml_xmlhttp = HTTPClient; if (!gml_xmlhttp) return; document.getElementById('bodyContent').innerHTML += ' Grabbing Configuration page...'; gml_xmlhttp.open('GET', 'http://en.wikipedia.org/w/index.php?title=User:' + username + '/config.js&action=edit', true); gml_xmlhttp.onreadystatechange = ConfigStep2; gml_xmlhttp.send(null); }

function ConfigStep2 { if (gml_xmlhttp.readyState != 4){ document.getElementById('bodyContent').innerHTML += '.'; return } var form, newform, l;  // Insert the downloaded form in our current page, using // only hidden form inputs. doc = gml_XMLParse(gml_xmlhttp.responseText); form = doc.getElementById('editform'); form.wpTextbox1.value += '\n'; form.wpTextbox1.value += 'software[\'' + softwarePackageConfig + '\'] = true;'; form.wpSummary.value = "Updating Monogooey Configuration file for item " + softwarePackageConfig + ""; newform = document.createElement('form'); l = form.getElementsByTagName('textarea'); for (i = l.length; i--; ) { var t = document.createElement('input'); t.type = 'hidden'; t.name = l[i].name; t.value = l[i].value; newform.appendChild(t); } l = form.getElementsByTagName('input'); for (i = l.length; i--; ) { if (l[i].name == 'wpSummary') { l[i].value = 'Updating Monogooey Configuration file for item ' + softwarePackageConfig + ''; } else if (l[i].name == 'wpMinoredit') { l[i].value = '1'; } else if (l[i].name == 'wpWatchthis') { if (!l[i].checked) continue; l[i].value = "on"; } else if (l[i].name == 'wpPreview') { continue; } else if (l[i].name == 'wpDiff') { continue; }   l[i].type = 'hidden'; newform.appendChild(l[i]); } newform.name = form.name; newform.method = form.method; newform.id = form.id; newform.action = form.action; document.getElementById('bodyContent').innerHTML += ' Submitting form...'; document.getElementById('bodyContent').appendChild(newform); // Submit the form eraseCookie('software'); newform.submit; }

function Install(softwarePackage){ softwarePackageInstall = softwarePackage; var username = document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML; document.getElementById('bodyContent').innerHTML = 'Please wait' + '...'; gml_xmlhttp = HTTPClient; if (!gml_xmlhttp) return; document.getElementById('bodyContent').innerHTML += ' Grabbing Monobook...'; gml_xmlhttp.open('GET', 'http://en.wikipedia.org/w/index.php?title=User:' + username + '/monobook.js&action=edit', true); gml_xmlhttp.onreadystatechange = InstallStep2; gml_xmlhttp.send(null); }

function InstallStep2 { if (gml_xmlhttp.readyState != 4){ document.getElementById('bodyContent').innerHTML += '.'; return } var form, newform, l;  // Insert the downloaded form in our current page, using // only hidden form inputs. doc = gml_XMLParse(gml_xmlhttp.responseText); form = doc.getElementById('editform'); form.wpTextbox1.value += '\n'; form.wpTextbox1.value += 'inc("User:Lightdarkness/monogooey/' + softwarePackageInstall + '.js");'; form.wpSummary.value = "Installing " + softwarePackageInstall + " using Monogooey"; newform = document.createElement('form'); l = form.getElementsByTagName('textarea'); for (i = l.length; i--; ) { var t = document.createElement('input'); t.type = 'hidden'; t.name = l[i].name; t.value = l[i].value; newform.appendChild(t); } l = form.getElementsByTagName('input'); for (i = l.length; i--; ) { if (l[i].name == 'wpSummary') { l[i].value = 'Installing ' + softwarePackageInstall + ' using Monogooey'; } else if (l[i].name == 'wpMinoredit') { l[i].value = '1'; } else if (l[i].name == 'wpWatchthis') { if (!l[i].checked) continue; l[i].value = "on"; } else if (l[i].name == 'wpPreview') { continue; } else if (l[i].name == 'wpDiff') { continue; }   l[i].type = 'hidden'; newform.appendChild(l[i]); } newform.name = form.name; newform.method = form.method; newform.id = form.id; newform.action = form.action + "&returnto=User:Lightdarkness/monobook.js&fakeaction=install"; document.getElementById('bodyContent').innerHTML += ' Submitting form...'; document.getElementById('bodyContent').appendChild(newform); // Submit the form setCookie('software', 'ARV', '42'); newform.submit; }

function MGUI { //check the URL for &fakeaction=install if((location.href.indexOf('&fakeaction=install') != -1) && (location.href.indexOf('&program=') == -1)){ document.getElementsByTagName('h1')[0].innerHTML = "Monogooey 1.0"; document.getElementById('ca-edit').innerHTML = ""; document.getElementById('ca-talk').innerHTML = ""; document.getElementById('ca-history').innerHTML = ""; document.getElementById('ca-move').innerHTML = ""; document.getElementById('ca-watch').innerHTML = ""; document.getElementById('ca-nstab-user').getElementsByTagName('a')[0].innerHTML = "Monogooey"; if(software['ARV'] == true){ ARVimage = "http://upload.wikimedia.org/wikipedia/commons/5/5b/Symbol_support_vote.png"; ARVinstall = "" }   else{ ARVimage = "http://upload.wikimedia.org/wikipedia/en/9/9e/Symbol_comment_vote.png"; ARVinstall = " [Install] "; }   document.getElementById('bodyContent').innerHTML = " ";

document.getElementById('bodyContent').innerHTML += "  Monogooey is licensed under the GNU Free Documentation license.  For more information, visit http://www.gnu.org/copyleft/fdl.html  "; } else if(location.href.indexOf('&program=') != -1){ document.getElementById('bodyContent').innerHTML = ""; packageA = location.href.split('&program=')[1]; Install(packageA); } else { //there isn't a fakeaction install called, but lets see if they are on their userpage if(location.href.indexOf('User:'+username+'/monobook.js') != -1){ document.getElementById('contentSub').innerHTML += " "; document.getElementById('contentSub').innerHTML += "Click here to launch Monogooey "; } } }

function wrapup {

var softwareCookie = getCookie('software'); if(softwareCookie != null){ UpdateConfig(softwareCookie); } }

addOnloadHook(wrapup); addOnloadHook(MGUI);