Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
console.log("%cload%c :: loaded using global.js", "color: red;", "color: #999;");
/* quick go-to-wiki field. for people who don't type text into the browser's url field like apes like me */
(function() {
var toolbar = document.querySelector("body > .WikiaSiteWrapper > #WikiaBar .toolbar .tools"),
nodes = {};
// initiate nodes
nodes.li = document.createElement("li");
nodes.nav = document.createElement("nav");
nodes.button = document.createElement("div");
nodes.link = document.createElement("a");
nodes.input = document.createElement("input");
nodes.nav.id = "goto-wiki";
// attributes
nodes.link.setAttribute("target", "_blank");
nodes.input.type = "text";
nodes.input.placeholder = "Go to wiki";
// hierarchy
nodes.link.appendChild(nodes.input);
nodes.nav.appendChild(nodes.button);
nodes.nav.appendChild(nodes.link);
nodes.li.appendChild(nodes.nav);
// events
nodes.button.addEventListener("click", function() {
nodes.input.select();
});
nodes.input.addEventListener("keydown", function(e) {
var a = this.value;
if (e.which == 13 && /[a-z0-9]+(?:\.[a-z0-9]+)?/i.test(a)) {
nodes.link.setAttribute("href", "/wiki/w:c:" + a);
}
});
// insert
toolbar.appendChild(nodes.li);
// css
mw.util.addCSS(`nav#goto-wiki {
position: relative;
margin-top: -2px;
}
nav#goto-wiki div {
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 18px;
cursor: pointer;
}
nav#goto-wiki input {
width: 196px;
height: 14px;
margin: 0;
padding: 1px;
line-height: 18px;
border: 1px solid #ccc;
font-size: 12px;
}`);
}());
console.log("@@ potato @@")