User:Blue-Haired Lawyer/test.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:Blue-Haired Lawyer/test. |
// To make this script work you need to add the following to you style sheet (vector.css):
// +--------------------------------------------------------------------+
// | #mw-panel { visibility: hidden !important; } |
// | #mw-head-base { margin-left: 0 !important; } |
// | #content { margin-left: 0 !important; } |
// | #left-navigation { margin-left: 1em !important; } |
// | #footer { margin-left: 0 !important; } |
// +--------------------------------------------------------------------+
// set viewport for mobile devices
myView = document.createElement("meta");
myView.setAttribute("name", "viewport");
myView.setAttribute("content", "width=device-width, initial-scale=1.0, minimal-scale=1.0, maximal-scale=1.0");
document.getElementsByTagName("head")[0].appendChild(myView);
// Insert head banner
myDiv = document.createElement("DIV");
myLink = document.createElement("A");
myDiv.appendChild(myLink);
myDiv.id = 'myNewBanner';
myDiv.setAttribute("style", "position: absolute; top: 5px; left: 15px; font: 31pt Times; font-variant: small-caps; z-index: 999999;");
myDiv.className = 'noprint';
myLink.href = mw.config.get( 'wgArticlePath' ).replace('$1', '');
myLink.setAttribute("style", "color: black; text-decoration: none;");
let siteName = mw.config.get( 'wgSiteName' );
if(siteName == 'Wikipedia') { siteName = 'WikipediA'; }
myLink.innerHTML = siteName;
document.getElementById("mw-head").appendChild(myDiv);
function transferChildren(from, to) {
if(typeof from == 'string') {
from = document.querySelectorAll(from);
}
if(typeof to == 'string') {
to = document.querySelector(to);
}
if(!from || !to) return;
for(let i = 0; i < from.length ; i++) {
let li = document.createElement("LI");
li.className = 'noprint mw-list-item';
li.appendChild(from[i]);
to.appendChild(li);
}
}
$(document).ready(function() {
// place certain (less used) links in the footer
transferChildren("#t-permalink A, #t-cite A, #p-wikibase-otherprojects A", "#footer-places");
// language links
let langChildren = document.querySelectorAll("#p-lang UL A");
if(langChildren !== null && langChildren.length > 0) {
let addLinks = document.querySelector('.wbc-editpage > a');
if(addLinks !== null) {
addLinks.innerHTML = 'Add language links';
}
//list
let langList = document.createElement("UL");
langList.id = 'langList';
langList.style.fontSize = "0.8em";
// interwiki list
transferChildren(langChildren, langList);
// language banner
let lbanner = document.createElement("DIV");
lbanner.id = "lbanner";
lbanner.className = "catlinks noprint";
lbanner.appendChild(langList);
document.getElementById("content").appendChild(lbanner);
}
let menuTable = document.createElement("table");
// Create a wiki menu for navigation and interaction links
// node.cloneNode(true) doesn't copy css stuff properly
let vectorMenu = document.getElementById('p-cactions');
let newMenu = document.createElement("NAV");
newMenu.id = 'faviconMenu';
newMenu.innerHTML = vectorMenu.innerHTML.replace(/ id="[^"]+"/g, '');
newMenu.className = vectorMenu.className;
newMenu.style.setProperty("display", "block", "important");
// Change ids and clear content
newMenu.querySelector('span').innerHTML = '<img src="https://upload.wikimedia.org/wikipedia/commons/b/b2/Hamburger_icon.svg" width="19">';
newMenu.querySelector('.vector-menu-content').innerHTML = '<table><tr><td style="vertical-align: top;"><h6>Wikipedia</h6><ul id="mainList" style="border-right: 1px solid black;"></ul></td>' +
'<td style="vertical-align: top;"><h6>Contribute</h6><ul id="contribList" style="border-right: 1px solid black;"></ul></td>' +
'<td style="vertical-align: top;"><h6>Tools</h6><ul id="toolsList" style="column-count: 2;"></ul></td></tr></table>';
// Insert newMenu
let ln = document.getElementById('left-navigation');
ln.insertBefore(newMenu, ln.firstChild);
transferChildren("#p-navigation A", "#mainList");
transferChildren("#p-interaction A", "#contribList");
transferChildren("#p-tb A, #p-coll-print_export A", "#toolsList");
// set some css for good and featured articles
let style = document.createElement('style');
let head = document.getElementsByTagName('head')[0];
let css = document.createTextNode( "#lbanner .GA:before { content: url('//upload.wikimedia.org/wikipedia/commons/4/42/Monobook-bullet-ga.png') ' '; } " );
css.appendData( "#lbanner .FA:before { content: url('//upload.wikimedia.org/wikipedia/en/d/d4/Monobook-bullet-star.png') ' '; }" );
style.appendChild(css);
head.appendChild(style);
});