User:Weeklyd3/scripts/linkRemover.js
Appearance
< User:Weeklyd3 | scripts
(Redirected from User:Weeklyd3/linkRemover.js)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. |
![]() | This user script seems to have a documentation page at User:Weeklyd3/scripts/linkRemover. |
/* Hides some links I do not frequently use. */
(function() {
var idsToHide = ["t-mute",
'n-portal',
'n-help',
'n-introduction',
'n-currentevents',
'n-contents',
'n-aboutsite',
'n-contactpage',
'n-sitesupport'];
if (!globalThis.hiddenLeft) globalThis.hiddenLeft = idsToHide;
for (var i = 0; i < globalThis.hiddenLeft.length; i++) {
var link = document.querySelector('li#' + globalThis.hiddenLeft[i]);
if (!link) continue;
link.style.display = 'none';
}
})();
if (mw.config.get("wgFormattedNamespaces")[mw.config.get("wgNamespaceNumber")] === "Special"
&& mw.config.get("wgTitle") === "HideLinks") {
document.querySelector('title').textContent = 'Hide links - Wikipedia';
document.querySelector('h1').textContent = 'Links to hide';
document.querySelector('#mw-content-text').innerHTML = `
<p>Here are some of the IDs of links on the left. Note that other userscripts may add other links.</p>
<p>To choose the links to hide, set <code>globalThis.hiddenLeft</code> to an array with the ids to hide <em>before loading the link remover script</em>.</p>
<p>(Note: This list is generated automatically on page load.)</p>
<table class="wikitable sortable">
<thead><tr style="">
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Link text
</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">ID
</th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Currently hidden?
</th></tr></thead><tbody id="links">
</tbody><tfoot></tfoot></table>
`;
var links = document.querySelectorAll('#mw-panel > nav');
for (var i = 0; i < links.length; i++) {
var menu = links[i];
var title = menu.children[0];
if (title.textContent != "") {
var titleField = document.createElement('tr');
var titleText = document.createElement('td');
titleText.style.textAlign = 'center';
titleText.textContent = title.textContent;
titleText.setAttribute('colspan', '3');
titleField.appendChild(titleText);
document.querySelector('#links').appendChild(titleField);
}
var menuChildren = menu.children[1].children[0];
if (menuChildren.tagName !== 'UL') continue;
var menuChildrenItems = menuChildren.children;
for (var j = 0; j < menuChildrenItems.length; j++) {
var menuItem = menuChildrenItems[j];
var data = document.createElement('tr');
var linkText = document.createElement('td');
linkText.textContent = menuItem.textContent;
data.appendChild(linkText);
var idText = document.createElement('td');
idText.textContent = menuItem.getAttribute('id');
data.appendChild(idText);
var hidden = document.createElement('td');
hidden.innerHTML = (menuItem.style.display == 'none') ? '<strong>Yes</strong>' : "No";
data.appendChild(hidden);
document.querySelector('#links').appendChild(data);
}
}
}