User:Year2000Prob/Y2P.Wijits.js
Appearance
(Redirected from User:Year2000Prob/Y2P.Widgets.js)
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:Year2000Prob/Y2P.Wijits. |
Y2P.Wijits = new Object();
Y2P.Wijits.StatusChanger = function(StatusNames) {
try {
var li = document.createElement("li");
li.id = "pt-status";
Y2P.Wijits._StatusNames = StatusNames;
for (var i=0; i<StatusNames.length; i++) {
var a = document.createElement("a");
var span = document.createElement("span");
a.onclick = function(e) {
var textbox = document.createElement("input");
textbox.type = "text";
if (e.which == 3) {
a.parentNode.innerHTML = textbox;
textbox.onblur = Y2P.Wijits._SetStatus(i, textbox.value);
} else {
Y2P.Wijits._SetStatus(i, StatusNames[i].defaultText);
};
};
a.appendChild(document.createTextNode(StatusNames[i].defaultText));
span.appendChild(a);
if (i != 0) li.appendChild(document.createTextNode("|"));
li.appendChild(span);
};
document.getElementById("p-personal").appendChild(li);
} catch(e) {
if (Y2P.Debug.Enabled) {
Y2P.Debug.Retry("Y2P Status Changer\nError: " + e, {
onAccept: function() {
Y2P.Wijits.StatusChanger(StatusNames);
}
});
}
};
};
Y2P.Wijits._SetStatus = function(number, text) {
var prelimresp = new XMLHttpRequest();
prelimresp.open("GET", "/index.php?title="+pagename+"&action=submit", false);
var edittime = prelimresp.responseText.match(/\<input type='hidden' value="(\d+)" name="wpEdittime" \/\>/)[1];
var edittoken = prelimresp.responseText.match(/\<input type='hidden' value="([0-9a-f]+\\?)" name="wpEditToken" \/\>/)[1];
var XHR = new XMLHttpRequest();
XHR.open("POST", mw.config.get('wgServer')+mw.config.get('wgScript')+"?title=User:"+wgUserName+"/Status&action=submit", false);
XHR.send("wpEdittime="+edittime+"&wpEditToken="+edittoken+"&wpTextbox1="+escape(Y2P.Wijits._StatusNames[number].templatePre)+escape(text)+escape(Y2P.Wijits._StatusNames[number].templateSuf)+"&wpSummary="+escape(text)+"&wpSection=&wpSave=Save+page");
var headers = {"Content-Type":"application/x-www-form-urlencoded"};
for (header in headers) {
XHR.setRequestHeader(header,headers[header]);
};
};
Y2P.Wijits._CreateStatusType = function() {
var StatusNames = [];
var name = prompt("Enter status name:");
var template = prompt("Enter status template (place \"(statusText)\" in the middle):");
var pre = template.substr(0, "(statusText)");
var suf = template.substr("(statusText)");
StatusNames.push({templatePre:pre,templateSuf:suf,defaultText:name});
if (confirm("Do you want to add another status type?")) {
Y2P.Wijits._createStatusType(StatusNames);
} else {
return StatusNames;
}
};
if (typeof Wijits == "object") {
Wijits.List.push({
name: "Y2P Status Changer",
onEnabled: function() {
Y2P.Wijits.StatusChanger(Y2P.Wijits._CreateStatusType());
},
onDisabled: function() {
if (document.getElementById("pt-status")) document.getElementById("p-personal").removeChild(document.getElementById("pt-status"));
if (Y2P.Wijits._StatusNames) delete Y2P.Wijits._StatusNames;
},
retriveConfigBeforeFullyEnabled: true
});
}