User:Polygnotus/Scripts/NamespaceFilter.js: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
 
(3 intermediate revisions by the same user not shown)
Line 1:
// Very janky and not intended for real world use, does not make API calls just filters whatever is there on the page (so use limit=5000).
// <nowiki>
// I have requested something better:
// ==UserScript==
// https://meta.wikimedia.org/wiki/Community_Wishlist/Wishes/Add_Namespace_filter_to_all_Special:_pages_(where_applicable)
// @name Wikipedia Namespace Filter
// @namespace http://tampermonkey.net/
// @version 0.6
// @description Filter special page results by namespace, including mainspace, with All/None options, localStorage, and improved article names only option
// @match https://*.wikipedia.org/w/index.php?title=Special:LinkSearch*
// @grant none
// ==/UserScript==
 
(function() {
Line 34 ⟶ 28:
margin-right: 10px;
}
.article-name-only .external, {
.article-name-only .mw-speclink {
display: none;
}
.article-name-only li a:nth-child(2) {
pointer-events: none;
text-decoration: none;
color: inherit;
}
`;
Line 149 ⟶ 137:
document.querySelector('ol.special').classList.toggle('article-name-only', isChecked);
localStorage.setItem(ARTICLE_NAMES_ONLY_KEY, isChecked);
 
// Remove "is linked from" text when article names only is checked
document.querySelectorAll('ol.special li').forEach(li => {
const linkElement = li.querySelector('a:nth-child(2)');
if (isChecked) {
li.textContent = '';
li.appendChild(linkElement);
} else {
// Restore original content
const originalHtml = li.getAttribute('data-original-html');
if (originalHtml) {
li.innerHTML = originalHtml;
}
}
});
}
 
Line 181 ⟶ 154:
addStyles();
createFilterUI(namespaces);
 
// Save original HTML content for each list item
document.querySelectorAll('ol.special li').forEach(li => {
li.setAttribute('data-original-html', li.innerHTML);
});
 
filterResults(); // Apply filters on initial load
}