User:Wikidudeman/quicknav.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:Wikidudeman/quicknav. |
// See [[Wikipedia talk:WikiProject User scripts/Scripts/Compact Navigation|Talk page]] for instructions
if (wgNamespaceNumber >= 0) addOnloadHook(function() {
var pCactions = document.getElementById('p-cactions');
var tabs = pCactions.getElementsByTagName('ul')[0];
var caMain = pCactions.getElementsByTagName('li')[0];
var menu2 = pCactions.getElementsByTagName('li')[1];
var caTalk = document.getElementById('ca-talk');
var caEdit = document.getElementById('ca-edit');
if (!caEdit) {
caEdit = document.getElementById('ca-viewsource');
}
var caHistory = document.getElementById('ca-history');
// Insert new menu after first entry
na = document.createElement("a");
na.appendChild(document.createTextNode('pagenav'));
na.href = "#";
var mn = document.createElement("ul");
li = document.createElement("li")
li.appendChild(na);
li.appendChild(mn);
li.className = 'tabmenu';
li.id = 'ca-quicknav';
tabs.insertBefore(li,menu2);
// Hide menus
if (caEdit) caEdit.style.display = 'none';
if (caTalk) caTalk.style.display = 'none';
if (caHistory) caHistory.style.display = 'none';
// Retrieve URLs
var hrefmain = caMain.firstChild.getAttribute('href', 2);
var hreftalk = caTalk.firstChild.getAttribute('href', 2);
// Add menu items
mw.util.addPortletLink('ca-quicknav', hrefmain, 'view');
mw.util.addPortletLink('ca-quicknav', hrefmain + '?action=edit', 'edit');
mw.util.addPortletLink('ca-quicknav', hrefmain + '?action=history', 'history');
mw.util.addPortletLink('ca-quicknav', hreftalk, 'view discussion');
mw.util.addPortletLink('ca-quicknav', hreftalk + '?action=edit', 'edit discussion');
mw.util.addPortletLink('ca-quicknav', hreftalk + '?action=history', 'discussion history');
});