User:LikeLakers2/addtool.js
Appearance
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:LikeLakers2/addtool. |
addOnloadHook(function addtool(location2,link2,name2,id2,comment2){
// First, lets check the location.
// Does it equal "p-tb", "toolbox", or "tb"?
if(location2=="p-tb" || location2=="toolbox" || location2=="tb" || location2=='p-tb' || location2=='toolbox' || location2=='tb') {
// If so, define the parameter as "p-tb" and then go to step two.
step2("p-tb",link2,name2,id2,comment2);
}
// Ok, so it does not equal any of those.
// Next, does it equal "p-cactions", "toolbar", or "cactions"?
else if(location2=="p-cactions" || location2=="toolbar" || location2=="cactions" || location2=='p-cactions' || location2=='toolbar' || location2=='cactions') {
// If so, define the parameter as "p-cactions" and then go to step two.
step2("p-cactions",link2,name2,id2,comment2);
}
// So it doesn't equal those?
// Since it doesn't, let us check if it equals "both".
else if(location2=='both' || location2=="both") {
// If so, define the parameter as "both" and then go to step two.
step2("both",link2,name2,id2,comment2);
}
// Still nothing? Don't continue.
});
// Next is the check to see if both the "link2" and "name2" parameters are defined.
function step2(location2,link2,name2,id2,comment2) {
// Are both parameters even defined?
if(link2 && name2) {
// If so, continue to step three.
step3(location2,link2,name2,id2,comment2);
}
// If they are not defined, don't continue.
};
// Next, the check to see if "id2" is defined.
function step3(location2,link2,name2,id2,comment2) {
// Is the "id2" parameter defined?
if(id2) {
// If so, does it equal "noid"?
if(id2=="noid" || id2=='noid') {
// If so, define as such and continue to step four.
step4(location2,link2,name2,"noid",comment2);
}
// It doesnt? Continue to step four with the parameter specified.
else {
step4(location2,link2,name2,id2,comment2);
}
}
// Not defined? Set to "noid" and send to step4().
else {
step4(location2,link2,name2,"noid",comment2);
}
};
// This checks if the "comment2" parameter exists.
function step4(location2,link2,name2,id2,comment2) {
// Is it defined?
if(comment2) {
// If so, send to finalcheck() for final parsing.
finalcheck(location2,link2,name2,id2,comment2);
}
// If it is not defined, set to "name2" and send to finalcheck().
else {
finalcheck(location2,link2,name2,id2,name2);
}
};
// This is the final processing, after all steps are done.
function finalcheck(location2,link2,name2,id2,comment2) {
// What is "location2"?
if(location2=="p-tb") {
// What is "id2"?
if(id2=="noid") {
// Add it to the toolbox, with id2 being "ca-" plus "name2" plus "-tb".
mw.util.addPortletLink("p-tb", link2, name2, "ca-" + name2 + "-tb", comment2, "");
}
else {
mw.util.addPortletLink("p-tb", link2, name2, id2, comment2, "");
}
}
if(location2=="p-cactions") {
// What is "id2"?
if(id2=="noid") {
// Add it to the cactions bar, with id2 being "ca-" plus "name2".
mw.util.addPortletLink("p-cactions", link2, name2, "ca-" + name2, comment2, "");
}
else {
mw.util.addPortletLink("p-cactions", link2, name2, id2, comment2, "");
}
}
if(location2=="both") {
// What is "id2"?
if(id2=="noid") {
// Add it to both sections.
mw.util.addPortletLink("p-tb", link2, name2, "ca-" + name2 + "-tb", comment2, "");
mw.util.addPortletLink("p-cactions", link2, name2, "ca-" + name2, comment2, "");
}
else {
mw.util.addPortletLink("p-tb", link2, name2, id2, comment2, "");
mw.util.addPortletLink("p-cactions", link2, name2, id2, comment2, "");
}
}
};