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.
$(document).ready(function(){constmakeNode=html=>{lett=document.createElement("template");t.innerHTML=html;returnt.content.firstElementChild;};constlinkStyle=` font-size: 0.6em; font-family: sans-serif; font-weight: bold; margin-left: 0.75rem; color: red; `;//Talk, Wikipedia, and Wikipedia_talk: namespacesif([1,3,4].includes(mw.config.get("wgNamespaceNumber"))){constpageId=mw.config.get("wgArticleId");// We only need heading2s, but section number is based on all headingsletheadings=document.getElementsByClassName("mw-heading");//Filter to h2s, get section indicesleth2s=Object.values(headings).flatMap((h,i)=>h.className.includes("mw-heading2")?[{index:i+1,heading:h}]:[]);h2s.forEach(h=>{lete=makeNode(`<a style="${linkStyle}">[@]</a>`);e.onclick=e=>{console.log(`Pings tool: Grabbing wikitext for page ${pageId}, section ${h.index}`);newmw.Api().get({action:"query",pageids:pageId,rvsection:h.index,prop:["revisions","info"],rvprop:"content",indexpageids:1,rawcontinue:""}).then(a=>{// Get only paragraphs that end with a timestampletsigParas=a.query.pages[pageId].revisions[0]["*"].split("\n").filter(l=>l.match(/\d{1,2}:\d{2}, \d{1,2} [a-zA-Z]+? \d{4} \(UTC\)/));console.log(`Pings tool: Found ${sigParas.length} paragraphs with signatures`);// Get last User: link in paragraphletusers=sigParas.map(l=>l.match(/User:(.+?)\|/g)?.at(-1)?.replace("|","")).filter((u,i,a)=>!!u&&a.indexOf(u)===i)// dedupe.sort((a,b)=>a.localeCompare(b))// sort alphabetically.map(u=>`@[[${u}|]]`)// map to ping list, using the pipe trick!.join(", ");console.log("Pings tool: Copied pings to clipboard:\n"+users);navigator.clipboard.writeText(users).then(()=>(e.target.style.color="blue"));// write to clipboard});};h.heading.appendChild(e);});}});