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.
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.
// 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).// I have requested something better:// https://meta.wikimedia.org/wiki/Community_Wishlist/Wishes/Add_Namespace_filter_to_all_Special:_pages_(where_applicable)(function(){'use strict';constSTORAGE_KEY='wikipediaNamespaceFilter';constARTICLE_NAMES_ONLY_KEY='wikipediaArticleNamesOnly';functionaddStyles(){conststyle=document.createElement('style');style.textContent=` #namespace-filter { margin: 10px 0; padding: 10px; border: 1px solid #a2a9b1; background-color: #f8f9fa; } #namespace-filter label { margin-right: 10px; display: inline-block; } #all-none-options, #display-options { margin-bottom: 10px; } #all-none-options button { margin-right: 10px; } .article-name-only .external { display: none; } `;document.head.appendChild(style);}functiongetNamespaces(){constnamespaces=newSet(['Main']);document.querySelectorAll('ol.special li a:nth-child(2)').forEach(link=>{consttext=link.textContent;constcolonIndex=text.indexOf(':');if(colonIndex===-1){namespaces.add('Main');}else{constnamespace=text.substring(0,colonIndex);if(namespace){namespaces.add(namespace);}}});returnArray.from(namespaces).sort((a,b)=>a==='Main'?-1:b==='Main'?1:a.localeCompare(b));}functioncreateFilterUI(namespaces){constfilterDiv=document.createElement('div');filterDiv.id='namespace-filter';filterDiv.innerHTML='<h4>Filter by namespace:</h4>';// Add All/None optionsconstallNoneDiv=document.createElement('div');allNoneDiv.id='all-none-options';constallButton=document.createElement('button');allButton.textContent='Select All';allButton.addEventListener('click',()=>setAllCheckboxes(true));constnoneButton=document.createElement('button');noneButton.textContent='Select None';noneButton.addEventListener('click',()=>setAllCheckboxes(false));allNoneDiv.appendChild(allButton);allNoneDiv.appendChild(noneButton);filterDiv.appendChild(allNoneDiv);// Add Article Names Only optionconstdisplayOptionsDiv=document.createElement('div');displayOptionsDiv.id='display-options';constarticleNamesOnlyLabel=document.createElement('label');constarticleNamesOnlyCheckbox=document.createElement('input');articleNamesOnlyCheckbox.type='checkbox';articleNamesOnlyCheckbox.id='article-names-only';articleNamesOnlyCheckbox.checked=localStorage.getItem(ARTICLE_NAMES_ONLY_KEY)==='true';articleNamesOnlyCheckbox.addEventListener('change',toggleArticleNamesOnly);articleNamesOnlyLabel.appendChild(articleNamesOnlyCheckbox);articleNamesOnlyLabel.appendChild(document.createTextNode('Show Article Names Only'));displayOptionsDiv.appendChild(articleNamesOnlyLabel);filterDiv.appendChild(displayOptionsDiv);constsavedFilters=getSavedFilters();namespaces.forEach(namespace=>{constlabel=document.createElement('label');constcheckbox=document.createElement('input');checkbox.type='checkbox';checkbox.value=namespace;checkbox.checked=savedFilters?savedFilters.includes(namespace):true;checkbox.addEventListener('change',()=>{filterResults();saveFilters();});label.appendChild(checkbox);label.appendChild(document.createTextNode(namespace));filterDiv.appendChild(label);});constol=document.querySelector('ol.special');ol.parentNode.insertBefore(filterDiv,ol);// Apply initial article names only settingtoggleArticleNamesOnly();}functionsetAllCheckboxes(checked){document.querySelectorAll('#namespace-filter input[type="checkbox"]').forEach(cb=>{if(cb.id!=='article-names-only'){cb.checked=checked;}});filterResults();saveFilters();}functionfilterResults(){constcheckedNamespaces=Array.from(document.querySelectorAll('#namespace-filter input:checked:not(#article-names-only)')).map(cb=>cb.value);document.querySelectorAll('ol.special li').forEach(li=>{constlink=li.querySelector('a:nth-child(2)');consttext=link.textContent;constcolonIndex=text.indexOf(':');constnamespace=colonIndex===-1?'Main':text.substring(0,colonIndex);if(checkedNamespaces.includes(namespace)){li.style.display='';}else{li.style.display='none';}});}functiontoggleArticleNamesOnly(){constisChecked=document.getElementById('article-names-only').checked;document.querySelector('ol.special').classList.toggle('article-name-only',isChecked);localStorage.setItem(ARTICLE_NAMES_ONLY_KEY,isChecked);}functionsaveFilters(){constcheckedNamespaces=Array.from(document.querySelectorAll('#namespace-filter input:checked:not(#article-names-only)')).map(cb=>cb.value);localStorage.setItem(STORAGE_KEY,JSON.stringify(checkedNamespaces));}functiongetSavedFilters(){constsavedFilters=localStorage.getItem(STORAGE_KEY);returnsavedFilters?JSON.parse(savedFilters):null;}functioninit(){constnamespaces=getNamespaces();if(namespaces.length>0){addStyles();createFilterUI(namespaces);filterResults();// Apply filters on initial load}}// Run the script when the page is loadedif(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',init);}else{init();}})();// </nowiki>