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.
/** * Scrapes all WikiProjects from the Category:Active WikiProjects page * and copies them to clipboard in a bulleted list format */functionscrapeWikiProjects(){// Check if we're on the right pageif(!window.___location.href.includes('Category:Active_WikiProjects')){console.error('Please run this script on the Category:Active WikiProjects page');return;}// Get all links in the category listconstlinks=document.querySelectorAll('#mw-pages .mw-category a');if(links.length===0){console.error('No WikiProject links found. Make sure you\'re on the correct page');return;}// Format each link as plain textconstprojectList=Array.from(links).map(link=>{// Format: Wikipedia:WikiProject Namereturn`${link.innerText}`;}).join('\n');// Copy to clipboardnavigator.clipboard.writeText(projectList).then(()=>{console.log('Successfully copied to clipboard:');console.log(projectList);// Visual feedbackconstfeedbackElement=document.createElement('div');feedbackElement.innerHTML=` <div style="position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background-color: #393; color: white; padding: 15px; border-radius: 5px; z-index: 9999; box-shadow: 0 2px 10px rgba(0,0,0,0.2);"> Copied ${links.length} WikiProjects to clipboard! </div> `;document.body.appendChild(feedbackElement);// Remove feedback after 3 secondssetTimeout(()=>{document.body.removeChild(feedbackElement);},3000);}).catch(err=>{console.error('Failed to copy: ',err);alert('Failed to copy to clipboard. Check console for details.');});}// Handle case where the category spans multiple pagesfunctionscrapeAllWikiProjectPages(){constbaseUrl='https://en.wikipedia.org/wiki/Category:Active_WikiProjects';letcurrentPage=baseUrl;letallWikiProjects=[];functionprocessPage(url){returnfetch(url).then(response=>response.text()).then(html=>{constparser=newDOMParser();constdoc=parser.parseFromString(html,'text/html');// Get all WikiProject links on this pageconstlinks=doc.querySelectorAll('#mw-pages .mw-category a');// Add to our collectionallWikiProjects=allWikiProjects.concat(Array.from(links).map(link=>`${link.innerText}`));// Check if there's a "next page" linkconstnextPageLink=Array.from(doc.querySelectorAll('#mw-pages a')).find(a=>a.innerText.includes('next page'));if(nextPageLink){constnextUrl=newURL(nextPageLink.href,baseUrl).href;returnprocessPage(nextUrl);// Process the next page}else{// No more pages, copy everything to clipboardconstprojectList=allWikiProjects.join('\n');navigator.clipboard.writeText(projectList).then(()=>{console.log(`Successfully copied ${allWikiProjects.length} WikiProjects to clipboard`);alert(`Copied ${allWikiProjects.length} WikiProjects to clipboard!`);}).catch(err=>{console.error('Failed to copy: ',err);alert('Failed to copy to clipboard. Check console for details.');});}});}// Start the processprocessPage(currentPage);}// Run the single-page or multi-page script based on preference// For a single page: scrapeWikiProjects();// For all pages (recommended): scrapeAllWikiProjectPages();scrapeAllWikiProjectPages();