MediaWiki:Gadget-abusefilter33test.js:修订间差异
外观
AnnAngela-dbot(留言 | 贡献) 代码变动:103d1a56 - feat: rename (#594) by U:AnnAngela, co-authored-by: GH:github-actions[bot] 标签:由机器人或全自动脚本执行的操作 |
AnnAngela-dbot(留言 | 贡献) 代码变动:8ca162b9 - fix(Gadget/abusefilter33test): convert filter to number at extraction poi[...] by U:Copilot, co-authored-by: U:AnnAngela,GH:copilot-swe-agent[bot] 标签:由机器人或全自动脚本执行的操作 |
||
| 第4行: | 第4行: | ||
* ------------------------------------------------------------------------- | * ------------------------------------------------------------------------- | ||
*/ | */ | ||
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/abusefilter33test/Gadget-abusefilter33test.js|user=[[U: | var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/abusefilter33test/Gadget-abusefilter33test.js|user=[[U:Copilot]]|co-authors=[[U:AnnAngela]]、GH:copilot-swe-agent[bot]|longId=8ca162b90492176cd8fad4462d1f02b4e4bf0a6c|shortId=8ca162b9|summary=fix(Gadget/abusefilter33test): convert filter to number at extraction point (#740)|body=<nowiki>Co-authored-by: AnnAngela <9762652+AnnAngela📧users.noreply.github.com>↩Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot📧users.noreply.github.com></nowiki>}}'; | ||
/* <pre> */ | /* <pre> */ | ||
"use strict";$(()=>(async()=>{if(!mw.config.get("wgUserGroups").includes("sysop")&&!mw.config.get("wgUserGroups").includes("staff"))return;if("AbuseLog"!==mw.config.get("wgCanonicalSpecialPageName"))return;const getLogVar=t=>$(`.mw-abuselog-details-${t} .mw-abuselog-var-value .mw-abuselog-var-value`).text(),t=getLogVar("timestamp"),e=getLogVar("user_name"),s=getLogVar("article_prefixedtext"),r=[...document.querySelectorAll('a[href*="/Special:%E6%BB%A5%E7%94%A8%E8%BF%87%E6%BB%A4%E5%99%A8/"]')].filter(({href:t})=>/%E6%BB%A5%E7%94%A8%E8%BF%87%E6%BB%A4%E5%99%A8\/[1-9]\d*$/.test(t))?.[0]?.href?.match?.(/[1-9]\d*$/)?.[0];if(0===t.length||0===e.length||0===s.length|| | "use strict";$(()=>(async()=>{if(!mw.config.get("wgUserGroups").includes("sysop")&&!mw.config.get("wgUserGroups").includes("staff"))return;if("AbuseLog"!==mw.config.get("wgCanonicalSpecialPageName"))return;const getLogVar=t=>$(`.mw-abuselog-details-${t} .mw-abuselog-var-value .mw-abuselog-var-value`).text(),t=getLogVar("timestamp"),e=getLogVar("user_name"),s=getLogVar("article_prefixedtext"),r=+[...document.querySelectorAll('a[href*="/Special:%E6%BB%A5%E7%94%A8%E8%BF%87%E6%BB%A4%E5%99%A8/"]')].filter(({href:t})=>/%E6%BB%A5%E7%94%A8%E8%BF%87%E6%BB%A4%E5%99%A8\/[1-9]\d*$/.test(t))?.[0]?.href?.match?.(/[1-9]\d*$/)?.[0];if(0===t.length||0===e.length||0===s.length||!r)return;const symbolEnter=t=>"string"==typeof t?t.replace(/\n/g,"↵"):t,a=new mw.Api,n=$("<table/>");$("#mw-content-text > fieldset > p:first").after(n.css("width","100%").addClass("wikitable")),n.empty().append('<tbody><tr><td style="text-align: center;">加载中(<span id="abusefiltertest-progress">0</span>/2)……</td></tr></tbody>');const i=$("#abusefiltertest-progress");try{const o=(await a.post({action:"query",assertuser:mw.config.get("wgUserName"),list:"abuselog",afluser:e,afltitle:s,aflprop:"details",aflfilter:r})).query.abuselog;if(0===o.length)throw"无法找到对应用户名和页面标题的滥用过滤器日志";i.text(1);const l=Array.from(new Map(o.filter(({details:{timestamp:e}})=>t===e).map(t=>[t.new_wikitext,t])).values());if(0===l.length)throw console.info(o),"无法找到对应时间戳的滥用过滤器日志";i.text(2);const f=(await a.post({action:"query",assertuser:mw.config.get("wgUserName"),list:"abusefilters",abfstartid:r,abfendid:r,abfprop:"pattern"})).query.abusefilters[0].pattern.replace(/\r/g,""),g=Array.from(f.match(/\/\* string rule start \*\/[\s\S]+?(?=\/\* string rule end \*\/)/g)||[]).map(t=>t.replace(/\/\* regex rule start \*\//g,"").split("\n")).flat().map(t=>t.replace(/^ *"?/,"").replace(/"?,? *$/,"")).filter(t=>""!==t),c=new Set(g),d=Array.from(f.match(/\/\* regex rule start \*\/[\s\S]+?(?=\/\* regex rule end \*\/)/g)||[]).map(t=>t.replace(/\/\* regex rule start \*\//g,"").split("\n")||[]).flat().map(t=>t.replace(/^ *"?/,"").replace(/"?,? *$/,"")).filter(t=>""!==t),u=new Set(d);if(c.size+u.size===0)throw"无法找到符合格式的规则";for(const{details:t}of l){const e=t.added_lines||t.new_wikitext,s=[],a=$("<table/>").css("width","100%").addClass("wikitable abusefiltertest").hide();n.after(a);for(const t of c.values())if(e.includes(t)){const r=e.split(t);r.forEach((e,a)=>{if(a===r.length-1)return;const n=r[a+1],i=Math.max(0,e.length-20),o=Math.min(n.length,20);s.push({isRegexp:!1,rule:t,before:e.substring(i,i+20),string:t,after:n.substring(0,o),start:i})})}for(const t of u.values()){const r=RegExp(`.{0,20}${t}.{0,20}`,"ig"),a=RegExp(t,"ig");if(r.test(e)){const n=e.match(r);let i=0;n.forEach(r=>{const n=r.match(a)[0],o=r.split(n),l=o[0],f=o.slice(1).join(n),g=e.indexOf(n,i);i=g+n.length,s.push({isRegex:!0,rule:t,before:l,string:n,after:f,start:g})})}}if(a.empty(),s.length>0){a.append(`<caption style="font-weight: 700;">命中防滥用过滤器${r}的内容</caption><tr><th style="text-align: right;">规则(请勿泄漏!!!)</th><th style="text-align: left;">命中字符串上下文</th></tr>`),s.sort(({start:t},{start:e})=>t-e);const t=[];s.forEach(e=>{0===t.filter(({isRegex:t,start:s})=>t===e.isRegex&&s===e.start).length&&t.push(e)}),console.info(t),t.forEach(({isRegex:t,rule:e,before:s,string:r,after:n,start:i})=>{const o=$("<tr/>"),l=$("<td/>"),f=$("<code/>");f.text(e),l.addClass("mw-label"),l.text(t?"正则表达式":"字符串"),l.append(symbolEnter(f)).append(":"),o.append(l);const g=$("<td/>");g.addClass("mw-input");const c=$("<span/>");c.text(symbolEnter(s)).css({padding:"0 .25em"});const d=$("<span/>");d.text(symbolEnter(r)).css({"font-weight":"700","text-decoration":"underline",padding:"0 .25em"});const u=$("<span/>");if(u.text(symbolEnter(n)).css({padding:"0 .25em"}),s.length>=20){const t=$("<span/>");t.text(`[${i}] ……`).css({"padding-right":".25em"}),g.append(t)}if(g.append(c).append(d).append(u),n.length>=20){const t=$("<span/>");t.text("……").css({"padding-left":".25em"}),g.append(t)}o.append(g),a.append(o)})}else a.empty().append('<tbody><tr><td style="text-align: center;">现有规则没有匹配项……</td></tr></tbody>')}n.hide(),$(".abusefiltertest").show()}catch(t){console.info("abusefiltertest",t),$(".abusefiltertest").remove(),n.empty(),33===r&&n.append(`<tbody><tr><td style="text-align: ${"string"==typeof t?"center":"left"};">发生错误:${"string"==typeof t?t:`${t} ${t.stack.split("\n")[1].trim()}`}</td></tr></tbody>`)}})()); | ||
/* </pre> */ | /* </pre> */ | ||
2025年11月3日 (一) 11:35的最新版本
/**
* -------------------------------------------------------------------------
* !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
* -------------------------------------------------------------------------
*/
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/abusefilter33test/Gadget-abusefilter33test.js|user=[[U:Copilot]]|co-authors=[[U:AnnAngela]]、GH:copilot-swe-agent[bot]|longId=8ca162b90492176cd8fad4462d1f02b4e4bf0a6c|shortId=8ca162b9|summary=fix(Gadget/abusefilter33test): convert filter to number at extraction point (#740)|body=<nowiki>Co-authored-by: AnnAngela <9762652+AnnAngela📧users.noreply.github.com>↩Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot📧users.noreply.github.com></nowiki>}}';
/* <pre> */
"use strict";$(()=>(async()=>{if(!mw.config.get("wgUserGroups").includes("sysop")&&!mw.config.get("wgUserGroups").includes("staff"))return;if("AbuseLog"!==mw.config.get("wgCanonicalSpecialPageName"))return;const getLogVar=t=>$(`.mw-abuselog-details-${t} .mw-abuselog-var-value .mw-abuselog-var-value`).text(),t=getLogVar("timestamp"),e=getLogVar("user_name"),s=getLogVar("article_prefixedtext"),r=+[...document.querySelectorAll('a[href*="/Special:%E6%BB%A5%E7%94%A8%E8%BF%87%E6%BB%A4%E5%99%A8/"]')].filter(({href:t})=>/%E6%BB%A5%E7%94%A8%E8%BF%87%E6%BB%A4%E5%99%A8\/[1-9]\d*$/.test(t))?.[0]?.href?.match?.(/[1-9]\d*$/)?.[0];if(0===t.length||0===e.length||0===s.length||!r)return;const symbolEnter=t=>"string"==typeof t?t.replace(/\n/g,"↵"):t,a=new mw.Api,n=$("<table/>");$("#mw-content-text > fieldset > p:first").after(n.css("width","100%").addClass("wikitable")),n.empty().append('<tbody><tr><td style="text-align: center;">加载中(<span id="abusefiltertest-progress">0</span>/2)……</td></tr></tbody>');const i=$("#abusefiltertest-progress");try{const o=(await a.post({action:"query",assertuser:mw.config.get("wgUserName"),list:"abuselog",afluser:e,afltitle:s,aflprop:"details",aflfilter:r})).query.abuselog;if(0===o.length)throw"无法找到对应用户名和页面标题的滥用过滤器日志";i.text(1);const l=Array.from(new Map(o.filter(({details:{timestamp:e}})=>t===e).map(t=>[t.new_wikitext,t])).values());if(0===l.length)throw console.info(o),"无法找到对应时间戳的滥用过滤器日志";i.text(2);const f=(await a.post({action:"query",assertuser:mw.config.get("wgUserName"),list:"abusefilters",abfstartid:r,abfendid:r,abfprop:"pattern"})).query.abusefilters[0].pattern.replace(/\r/g,""),g=Array.from(f.match(/\/\* string rule start \*\/[\s\S]+?(?=\/\* string rule end \*\/)/g)||[]).map(t=>t.replace(/\/\* regex rule start \*\//g,"").split("\n")).flat().map(t=>t.replace(/^ *"?/,"").replace(/"?,? *$/,"")).filter(t=>""!==t),c=new Set(g),d=Array.from(f.match(/\/\* regex rule start \*\/[\s\S]+?(?=\/\* regex rule end \*\/)/g)||[]).map(t=>t.replace(/\/\* regex rule start \*\//g,"").split("\n")||[]).flat().map(t=>t.replace(/^ *"?/,"").replace(/"?,? *$/,"")).filter(t=>""!==t),u=new Set(d);if(c.size+u.size===0)throw"无法找到符合格式的规则";for(const{details:t}of l){const e=t.added_lines||t.new_wikitext,s=[],a=$("<table/>").css("width","100%").addClass("wikitable abusefiltertest").hide();n.after(a);for(const t of c.values())if(e.includes(t)){const r=e.split(t);r.forEach((e,a)=>{if(a===r.length-1)return;const n=r[a+1],i=Math.max(0,e.length-20),o=Math.min(n.length,20);s.push({isRegexp:!1,rule:t,before:e.substring(i,i+20),string:t,after:n.substring(0,o),start:i})})}for(const t of u.values()){const r=RegExp(`.{0,20}${t}.{0,20}`,"ig"),a=RegExp(t,"ig");if(r.test(e)){const n=e.match(r);let i=0;n.forEach(r=>{const n=r.match(a)[0],o=r.split(n),l=o[0],f=o.slice(1).join(n),g=e.indexOf(n,i);i=g+n.length,s.push({isRegex:!0,rule:t,before:l,string:n,after:f,start:g})})}}if(a.empty(),s.length>0){a.append(`<caption style="font-weight: 700;">命中防滥用过滤器${r}的内容</caption><tr><th style="text-align: right;">规则(请勿泄漏!!!)</th><th style="text-align: left;">命中字符串上下文</th></tr>`),s.sort(({start:t},{start:e})=>t-e);const t=[];s.forEach(e=>{0===t.filter(({isRegex:t,start:s})=>t===e.isRegex&&s===e.start).length&&t.push(e)}),console.info(t),t.forEach(({isRegex:t,rule:e,before:s,string:r,after:n,start:i})=>{const o=$("<tr/>"),l=$("<td/>"),f=$("<code/>");f.text(e),l.addClass("mw-label"),l.text(t?"正则表达式":"字符串"),l.append(symbolEnter(f)).append(":"),o.append(l);const g=$("<td/>");g.addClass("mw-input");const c=$("<span/>");c.text(symbolEnter(s)).css({padding:"0 .25em"});const d=$("<span/>");d.text(symbolEnter(r)).css({"font-weight":"700","text-decoration":"underline",padding:"0 .25em"});const u=$("<span/>");if(u.text(symbolEnter(n)).css({padding:"0 .25em"}),s.length>=20){const t=$("<span/>");t.text(`[${i}] ……`).css({"padding-right":".25em"}),g.append(t)}if(g.append(c).append(d).append(u),n.length>=20){const t=$("<span/>");t.text("……").css({"padding-left":".25em"}),g.append(t)}o.append(g),a.append(o)})}else a.empty().append('<tbody><tr><td style="text-align: center;">现有规则没有匹配项……</td></tr></tbody>')}n.hide(),$(".abusefiltertest").show()}catch(t){console.info("abusefiltertest",t),$(".abusefiltertest").remove(),n.empty(),33===r&&n.append(`<tbody><tr><td style="text-align: ${"string"==typeof t?"center":"left"};">发生错误:${"string"==typeof t?t:`${t} ${t.stack.split("\n")[1].trim()}`}</td></tr></tbody>`)}})());
/* </pre> */