Jump to content

User:Wikidudeman/quicknav.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// 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');


});