User:Dbeef/cplus.js: Difference between revisions

Content deleted Content added
[BOT] dbeef: add commit name as dbeef (https://github.com/fee1-dead/cplus/compare/a4ad9c5718b4...bb081cb76a25)
[BOT] dbeef: bail if page is not "get actions" (https://github.com/fee1-dead/cplus/compare/bb081cb76a25...08e7ef10f3e5)
Line 1:
// {{Wikipedia:USync |repo=https://github.com/fee1-dead/cplus |ref=refs/heads/production |path=main.js}}
// A helper for Special:CheckUser.
function F(LN){if(document.readyState==="complete")setTimeout(LN,1);else document.addEventListener("DOMContentLoaded",LN)}F(()=>{if(mw.config.get("wgPageName")!=="Special:CheckUser")return;let LN=document.getElementById("checkuserresults");if(!LN){console.error("cplus: can't get cu results!");return}let S=N.previousElementSibling;if(!S||!S.classList.contains("mw-pager-navigation-bar")){console.info("cplus: not a 'get actions' page, bailing");return}mw.util.addCSS(`
.cplus-injected-header {
padding: 5px 0 5px 0;
Line 15:
margin-right: 4px;
}
`);let Z$=document.querySelectorAll(".mw-checkuser-helper-table tbody tr td a.mw-userlink"),$g=document.querySelectorAll(".mw-checkuser-user-link a.mw-userlink"),P=new Map,gD=0,XY=(B)=>{let q=B.querySelector("bdi")?.innerText;if(q===void 0)return;if(mw.util.isIPAddress(q))return;let H=P.get(q);if(!H)H=`cplus-checkbox-${gD++}`,P.set(q,H);let I=document.createElement("input");I.type="checkbox",I.value=B.firstElementChild?.innerHTML??"",I.classList.add("cplus-injected","cplus-checkbox",H),B.before(I)};Z$.forEach(XY),$g.forEach(XY);let J=document.createElement("div");J.classList.add("cplus-injected","cplus-injected-top");let SX=document.createElement("div");SX.innerText="C+",J.append(SX),SX.classList.add("cplus-injected","cplus-injected-header");let K=document.createElement("textarea"),YZ=()=>{let B=K.value.trim();if(B==="")return new Set;if(B.startsWith("{{sock list|")&&B.endsWith("}}")){let q=B.substring(12,B.length-2);return document.getElementById("cplus-warning")?.remove(),new Set(q.split("|").map((H)=>H.trim()).filter((H)=>H!==""))}else if(!document.getElementById("cplus-warning")){let q=document.createElement("span");q.innerText="C+ Warning: could not parse input sock list",q.id="cplus-warning",J.appendChild(q)}return new Set};J.append(K),J.classList.add("oo-ui-panelLayout-padded","oo-ui-panelLayout-framed"),K.classList.add("cplus-injected","cplus-textarea"),K.oninput=()=>{let B=YZ();P.forEach((q,H)=>{let I=B.has(H);document.querySelectorAll("."+q).forEach((NL)=>{NL.checked=I})})},P.forEach((B,q)=>{document.querySelectorAll("."+B).forEach((H)=>{H.addEventListener("change",()=>{let I=H.checked,NL=YZ();if(I&&!NL.has(q))NL.add(q);if(!I)NL.delete(q);K.value=`{{sock list|${[...NL].join("|")}}}`,document.querySelectorAll("."+B).forEach((E)=>{E.checked=I})})})});let D=L.previousElementSibling??L,Q=document.createElement("button");Q.classList.add("cplus-injected","cplus-copybtn"),Q.innerText="Copy socklist",Q.addEventListener("click",()=>{K.select(),window.navigator.clipboard.writeText(K.value)}),J.append(Q),DS.before(J)});