User:Tyrok1/monobook.js: Difference between revisions

Content added Content deleted
(Testing a new script)
(Fixing long lines and escaping problem)
Line 1: Line 1:
/*========================================
/*========================================
This comparison script was written by
This comparison script was written by
Tyrok1, and has been tested on Fx 3.6.6
Tyrok1, and has been tested on Fx 3.6.6,
Cr 5.0.375.99, Epiphany 2.30.2,
Midori 0.2.2
========================================*/
========================================*/


var gadgetsAvailable = [
var gadgetsAvailable = [
{
{ id: "LanguageComparison", name: "Language comparison", url: "http://rosettacode.org/mw/index.php?title=Rosetta_Code:Language_comparison_script&action=raw&ctype=text/javascript", prefix: "Compare" },
id: "LanguageComparison",
{ id: "UtilityButtonBar", name: "Utility button bar", url: "http://rosettacode.org/mw/index.php?title=Rosetta_Code:Per-Code_Example_Buttonbar&action=raw&ctype=text/javascript", prefix: "ButtonBar" }
name: "Language comparison",
url: "http://rosettacode.org/mw/index.php" +
"?title=Rosetta_Code:Language_comparison_script" +
"&action=raw&ctype=text/javascript",
prefix: "Compare"
},
{
id: "UtilityButtonBar",
name: "Utility button bar",
url: "http://rosettacode.org/mw/index.php" +
"?title=Rosetta_Code:Per-Code_Example_Buttonbar" +
"&action=raw&ctype=text/javascript",
prefix: "ButtonBar"
}
];
];


Line 65: Line 81:
else
else
{
{
//pop up a warning to the user to let them know the plugin will be disabled when they reload
//pop up a warning to the user to let them know
//the plugin will be disabled when they reload
alert("This script will be disabled on next page load");
alert("This script will be disabled on next page load");
}
}
Line 111: Line 128:
for(var c = 0; checkboxEl = document.getElementById("pt-jsgadgets-gadget" + c); ++c)
for(var c = 0; checkboxEl = document.getElementById("pt-jsgadgets-gadget" + c); ++c)
{
{
checkedBoxes += (checkboxEl.checked ? (checkedBoxes != "" ? "," : "") + gadgetsAvailable[c].id : "");
if(checkboxEl.checked)
{
if(checkedBoxes != "")
{
checkedBoxes += ",";
}
checkedBoxes += gadgetsAvailable[c].id;
}
}
}
Line 119: Line 143:
//store the cookie
//store the cookie
document.cookie = "jsGadgets=" + escape(checkedBoxes) + "; expires=" + expireDate.toUTCString();
document.cookie = "jsGadgets=" + escape(checkedBoxes) +
"; expires=" + expireDate.toUTCString();
}
}


Line 135: Line 160:
//split the gadget IDs by comma
//split the gadget IDs by comma
var checkIDs = fullCookie.substring(gadgetsPos + ("jsGadgets=").length, (endPos > 0 ? endPos : fullCookie.length)).split(",");
var jsGadgets = fullCookie.substring(gadgetsPos + ("jsGadgets=").length,
(endPos > 0 ? endPos : fullCookie.length));
var checkIDs = unescape(jsGadgets).split(",");
//translate the list of IDs to a list of array indices, in keeping with the way the rest of this module works
//translate the list of IDs to a list of array indices,
//in keeping with the way the rest of this module works
var checkIndices = new Array();
var checkIndices = new Array();
for(var g = 0; g < gadgetsAvailable.length; ++g)
for(var g = 0; g < gadgetsAvailable.length; ++g)
Line 157: Line 185:
//find the user preferences button and add a new list item to the right of it
//find the user preferences button and add a new list item to the right of it
var prefsEl = document.getElementById("pt-preferences");
var prefsEl = document.getElementById("pt-preferences");
if(!prefsEl)
var jsMenuEl = prefsEl.parentNode.insertBefore(document.createElement("li"), prefsEl.nextSibling);
{
var personalEl = document.getElementById("p-personal");
if(!personalEl)
{
return;
}
var liEls = personalEl.getElementsByTagName("li");
if(!liEls || liEls.length < 2)
{
return;
}
prefsEl = liEls[liEls.length - 2];
}
var jsMenuEl = prefsEl.parentNode.insertBefore(
document.createElement("li"), prefsEl.nextSibling);
jsMenuEl.setAttribute("id", "pt-jsgadgets");
jsMenuEl.setAttribute("id", "pt-jsgadgets");
//add a new link named "My scripts" in the new list item
//add a new link named "My scripts" in the new list item
//from a semantics point of view, this is not great, but this way the styling kicks in to keep it consistent with its siblings
//from a semantics point of view, this is not great,
//but this way the styling kicks in to keep it consistent with its siblings
var jsLinkEl = jsMenuEl.appendChild(document.createElement("a"));
var jsLinkEl = jsMenuEl.appendChild(document.createElement("a"));
jsLinkEl.appendChild(document.createTextNode("My scripts"));
jsLinkEl.appendChild(document.createTextNode("My scripts"));
Line 185: Line 229:
modulesListEl.style.display = "none";
modulesListEl.style.display = "none";
//raise the zIndex of the new button (as well as a few parents) so the menu overlaps the page
//raise the zIndex of the new button (as well as
//a few parents) so the menu overlaps the page
var zEl = modulesListEl;
var zEl = modulesListEl;
for(var z = 0; z < 6 && zEl && zEl.style; ++z, zEl = zEl.parentNode)
for(var z = 0; z < 6 && zEl && zEl.style; ++z, zEl = zEl.parentNode)
Line 226: Line 271:
for(var c = 0; c < checks.length; ++c)
for(var c = 0; c < checks.length; ++c)
{
{
//for each one that should be checked on page load, check the box, load, and activate it
//for each one that should be checked on page load,
//check the box, load, and activate it
document.getElementById("pt-jsgadgets-gadget" + checks[c]).checked = true;
document.getElementById("pt-jsgadgets-gadget" + checks[c]).checked = true;
GadgetsScriptLoad(checks[c]);
GadgetsScriptLoad(checks[c]);