跳转到内容

MediaWiki:Gadget-usergroup.js

来自萌娘共享
AnnAngela-dbot留言 | 贡献2025年9月25日 (四) 08:40的版本 (代码变动:caaba1ba - feat: 部分封禁 (#711) by U:SaoMikoto, co-authored-by: U:AnnAngela
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/usergroup/Gadget-usergroup.js|user=[[U:SaoMikoto]]|co-authors=[[U:AnnAngela]]|longId=caaba1baff0493692aacb0415e777523b670ef55|shortId=caaba1ba|summary=feat: 部分封禁 (#711)|body=<nowiki>Co-authored-by: AnnAngela <naganjue📧vip.qq.com></nowiki>}}'; 

/* <pre> */

"use strict";(async()=>{await $.ready;const t=new LocalObjectStorage("usergroup"),e=[["staff","#198754"],["bureaucrat","#6610f2"],["checkuser","#673ab7"],["suppress","#9c27b0"],["sysop","#ec407a"],["interface-admin","#f55b42"],["patroller","#f77f38"],["honoredmaintainer","#febd45"],["techeditor","#3f51b5"],["file-maintainer","#039be5"],["bot","#1e88e5"],["flood","#1e88e5"],["ipblock-exempt","#29b6f6"],["extendedconfirmed","#57c2c3"],["manually-confirmed","#009688"],["goodeditor","#1aa179"],["special-contributor","#595c5f"]].reverse(),o={bureaucrat:{zh:"行"},checkuser:{zh:"查"},suppress:{zh:"监","zh-hant":"監","zh-tw":"監","zh-hk":"監"},sysop:{zh:"管"},patroller:{zh:"维","zh-hant":"維","zh-tw":"維","zh-hk":"維"},bot:{zh:"机","zh-hant":"機","zh-tw":"機","zh-hk":"機"},flood:{zh:"机","zh-hant":"機","zh-tw":"機","zh-hk":"機"},goodeditor:{zh:"优","zh-hant":"優","zh-tw":"優","zh-hk":"優"},honoredmaintainer:{zh:"荣","zh-hant":"榮","zh-tw":"榮","zh-hk":"榮"},"file-maintainer":{zh:"档","zh-hant":"檔","zh-tw":"檔","zh-hk":"檔"},"interface-admin":{zh:"界","zh-hant":"介","zh-tw":"介","zh-hk":"介"},techeditor:{zh:"技"},"ipblock-exempt":{zh:"免"},"manually-confirmed":{zh:"手"},extendedconfirmed:{zh:"延"},staff:{zh:"职","zh-hant":"職","zh-tw":"職","zh-hk":"職"},"special-contributor":{zh:"特"}},n=e.map(([t])=>t),r=Object.entries({anononly:wgULS("仅封禁匿名用户","僅封鎖匿名使用者",null,null,"僅封鎖匿名用戶"),nocreate:wgULS("阻止创建新账号","防止建立新帳號"),autoblock:wgULS("自动封禁该用户最后使用的IP地址,以及其随后试图用于编辑的所有IP地址","自動封鎖最後使用的IP位址,以及在這之後嘗試登入的所有IP位址。"),noemail:wgULS("阻止用户发送电子邮件","阻止使用者發送電子郵件",null,null,"阻止用戶發送電子郵件"),nousertalk:wgULS("阻止用户在封禁期间编辑自己的讨论页","阻止使用者在封鎖期間編輯自己的對話頁",null,null,"阻止用戶在封鎖期間編輯自己的討論頁"),hiddenname:wgULS("隐藏用户名","隱藏使用者名稱",null,null,"隱藏用戶名")}),a={0:"(主)",1:wgULS("讨论","討論"),2:wgULS("用户","使用者"),3:wgULS("用户讨论","使用者討論"),4:"萌娘百科",5:"萌娘百科讨论",6:wgULS("文件","檔案"),7:wgULS("文件讨论","檔案討論"),8:wgULS("界面消息","介面訊息"),9:wgULS("界面消息讨论","介面訊息討論"),10:"模板",11:"模板讨论",12:wgULS("帮助","說明"),13:wgULS("帮助讨论","說明討論"),14:wgULS("分类","分類"),15:wgULS("分类讨论","分類討論"),274:"微件",275:wgULS("微件讨论","微件討論"),710:"TimedText",711:wgULS("TimedText讨论","TimedText討論"),828:wgULS("模组","模組"),829:wgULS("模组讨论","模組討論")},s=mw.config.get("wgUserName");let c;const i=new mw.Api,h=Symbol(),fixZero=(t,e=2)=>`${t}`.padStart(e,"0"),toLocalTimeZoneString=(t=new Date)=>`${t.getFullYear()}/${fixZero(t.getMonth()+1)}/${fixZero(t.getDate())} ${fixZero(t.getHours())}:${fixZero(t.getMinutes())}:${fixZero(t.getSeconds())}.${fixZero(t.getMilliseconds(),3)}`;try{if(c=t.getItem("cache"),!c||"number"!=typeof c.timestamp||c.timestamp<(new Date).getTime()-18e5||!c.groups)throw new Error;for(const t of n)if(!Array.isArray(c.groups[t]))throw new Error}catch{const t=Object.fromEntries(n.map(t=>[t,[]]));let e;for(;e!==h;){const o=await i.post({action:"query",assertuser:s,list:"allusers",augroup:n.join("|"),aulimit:"max",auprop:"groups",aufrom:e});e=o.continue?o.continue.aufrom:h,o.query.allusers.forEach(({name:e,groups:o})=>{o.forEach(o=>{n.includes(o)&&(t[o]||(t[o]=[]),t[o].includes(e)||t[o].push(e))})})}c={timestamp:(new Date).getTime(),groups:t}}t.setItem("cache",c);const l=t.getItem("blockCache",{}),f=Date.now();for(const[t,{timestamp:e,isBlocked:o}]of Object.entries(l))("string"!=typeof t||"number"!=typeof e||"boolean"!=typeof o||f-e>18e5)&&Reflect.deleteProperty(l,t);t.setItem("blockCache",l);const querySelectorAll=t=>[...document.querySelectorAll(t)],markBlocked=(t,e)=>{if(t.classList.add("markBlockInfo"),t.classList.remove("unknownBlockInfo"),e.isBlocked){t.style.textDecoration=e.isPartial?"underline dotted":"underline wavy";const o=document.createElement("sup");o.classList.add("detailedBlockInfo"),o.title=e.info,o.textContent=e.isPartial?"[限+]":"[封+]",t.after(o)}},hook=async()=>{const e=new Set;for(const t of querySelectorAll("a.mw-userlink:not(.markrights), .userlink > a:not(.markrights)")){let o=t.parentElement,r=!1;for(;o;){if(o.classList.contains("navbox")){r=!0;break}o=o.parentElement}if(r)continue;t.classList.add("markrights");const a=new URL(new mw.Uri(t.href));let s;const i=decodeURIComponent(a.pathname),h=a.searchParams.get("title");if(/^\/User:[^/=%]+/.test(i)?s=i.match(/^\/User:([^/=%]+)/)[1].replace(/_/g," "):/^User:[^/=%]+/.test(h)&&(s=h.match(/^User:([^/=%]+)/)[1].replace(/_/g," ")),s){t.dataset.username=s;for(const e of n)if(c.groups[e].includes(s)){const o=document.createElement("sup");o.classList.add(`markrights-${e}`),t.after(o)}if(!t.classList.contains("markBlockInfo")){const o=l[s];o&&o.timestamp?markBlocked(t,o):(t.classList.add("unknownBlockInfo"),e.add(s))}}}if(e.size>0){const o=(await mw.user.getRights()).includes("apihighlimits")?500:50,n=[...e.values()];for(let t=0,e=Math.ceil(n.length/o);t<e;t++){let e;const c=n.slice(t*o,(t+1)*o),f=[],w=Date.now();for(;e!==h;){const t=await i.post({action:"query",assertuser:s,list:"blocks",bkusers:c,bklimit:"max",bkprop:"id|user|by|timestamp|expiry|reason|flags|restrictions",bkcontinue:e});e=t.continue?t.continue.aufrom:h,t.query.blocks.forEach(t=>{f.push(t.user);const e=t.restrictions&&Object.keys(t.restrictions).length>0;let o=`${t.id} - \n    被U:${t.by}${wgULS("封禁","封鎖")}${toLocalTimeZoneString(new Date(t.timestamp))},`;if(moment(t.expiry).isValid()?o+=`${wgULS("持续","持續")}${toLocalTimeZoneString(new Date(t.expiry))}`:o+=wgULS("持续时间为无限期","持續時間為不限期"),o+=`\n    ${wgULS("封禁类型","封鎖類型")}${e?wgULS("部分封禁","部分封鎖"):wgULS("全站封禁","全站封鎖")}`,t.restrictions){const e=[];t.restrictions.pages&&t.restrictions.pages.forEach(t=>{e.push(`${wgULS("页面","頁面")}${t.title}`)}),t.restrictions.namespaces&&t.restrictions.namespaces.forEach(t=>{e.push(`${wgULS("命名空间","命名空間")}${a[t]}`)}),e.length>0&&(o+=`\n    ${wgULS("限制范围","限制範圍")}${e.join(";")}`)}o+=`\n    ${wgULS("额外限制","額外限制")}:`,Reflect.has(t,"allowusertalk")||(t.nousertalk=!0);const n=[];for(const[e,o]of r)Reflect.has(t,e)&&n.push(o);0===n.length&&n.push(wgULS("(无)","(無)")),o+=n.join("、"),o+=`\n    ${wgULS("理由","緣由")}${t.reason}`,l[t.user]={timestamp:w,isBlocked:!0,isPartial:e,info:o}})}for(const t of c.filter(t=>!f.includes(t)))l[t]={timestamp:w,isBlocked:!1}}for(const t of querySelectorAll(".unknownBlockInfo")){const{username:e}=t.dataset,o=l[e];o&&o.timestamp&&markBlocked(t,o)}t.setItem("blockCache",l)}for(const t of n)for(const e of querySelectorAll(`.markrights-${t}`)){let{nextElementSibling:o}=e;for(;o&&[...o.classList].filter(t=>t.startsWith("markrights-")).length>0;){const e=o.nextElementSibling;o.classList.contains(`.markrights-${t}`)&&o.remove(),o=e}}};hook(),mw.hook("wikipage.content").add(hook),mw.hook("anntools.usergroup").add(hook),"complete"!==document.readyState&&$(window).on("load",hook);const w=["sup[class^=markrights-]+sup[class^=markrights-] { margin-left: 2px; }"];for(const[t,o]of e)w.push(`.markrights-${t} { color: ${o}; }`);for(const[t,e]of Object.entries(o)){w.push(`html .markrights-${t}::after { content: "${e.zh}"; }`);for(const[o,n]of Object.entries(e))w.push(`html[lang=${o.toLowerCase()} i] .markrights-${t}::after { content: "${n}"; }`)}mw.loader.addStyleTag(w.join("\n"))})(); 

/* </pre> */