跳转到内容

User:SuperGrey/gadgets/ReviewTool/main.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// [[User:SuperGrey/gadgets/ReviewTool]]
// Repository: https://github.com/QZGao/ReviewTool
// Release: 1.0.1
// Timestamp: 2026-02-09T00:19:58.148Z
// <nowiki>
(()=>{var Qt=Object.defineProperty,Kt=Object.defineProperties;var Jt=Object.getOwnPropertyDescriptors;var Xe=Object.getOwnPropertySymbols;var Yt=Object.prototype.hasOwnProperty,Zt=Object.prototype.propertyIsEnumerable;var Qe=(e,t,n)=>t in e?Qt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oe=(e,t)=>{for(var n in t||(t={}))Yt.call(t,n)&&Qe(e,n,t[n]);if(Xe)for(var n of Xe(t))Zt.call(t,n)&&Qe(e,n,t[n]);return e},Re=(e,t)=>Kt(e,Jt(t));var _e=class{constructor(){this.convByVar=function(t){return t&&t.hant?t.hant:"繁簡轉換未初始化,且 langDict 無效!"};this.articleTitle="";this.inTalkPage=!1;this.assessmentType="";this.userName=mw.config.get("wgUserName")||"Example";this._api=null;this.pendingReviewHeading=null;this.annotationModeState={}}initHanAssist(){return mw.loader.using("ext.gadget.HanAssist").then(t=>{let{convByVar:n}=t("ext.gadget.HanAssist");typeof n=="function"&&(this.convByVar=n)})}getApi(){return this._api||(this._api=new mw.Api({ajax:{headers:{"Api-User-Agent":"ReviewTool/1.0"}}})),this._api}isAnnotationModeActive(t){return!!this.annotationModeState[t]}toggleAnnotationModeState(t){let n=this.isAnnotationModeActive(t);this.annotationModeState[t]=!n}},en=new _e,a=en;var Ke=`.review-tool-dialog .review-tool-suggested-criteria-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:0;margin-top:5px}.review-tool-dialog .review-tool-form-section:not(:first-child){margin-top:10px}.review-tool-dialog.review-tool-check-writing-dialog{max-width:900px;width:90vw}.review-tool-dialog .chapter-block{border:1px solid rgba(0,0,0,.08);background:#00000005;padding:12px;margin-bottom:12px;border-radius:6px}.review-tool-dialog .chapter-suggestions{margin-top:8px}.review-tool-dialog .suggestion-row{display:flex;gap:8px;align-items:flex-start;padding:6px 0}.review-tool-dialog .suggestion-row:last-child{border-bottom:none;margin-bottom:0}.review-tool-dialog .suggestion-bullet{display:list-item;color:#666;list-style-position:inside;padding-left:5px}.review-tool-dialog .suggestion-columns{display:flex;gap:8px;flex:1 1 auto;align-items:flex-start}.review-tool-dialog .quote-col{flex:0 0 35%}.review-tool-dialog .suggestion-col{flex:1 1 auto}.review-tool-dialog textarea{min-height:32px;max-height:160px;resize:vertical}.review-tool-dialog .review-tool-edit-step textarea{font-family:SFMono-Regular,Consolas,Liberation Mono,Courier New,monospace;min-height:180px;max-height:calc(100vh - 220px)}.review-tool-dialog .quote-area textarea{color:#008560}.review-tool-dialog .suggestion-controls{display:flex;gap:8px;justify-content:flex-end;margin-top:3px}.review-tool-dialog .row-controls{display:flex;gap:8px;align-items:center;justify-content:space-between;margin-top:8px}.review-tool-dialog .suggestion-add{margin-top:0;display:flex;justify-content:flex-start}.review-tool-dialog .chapter-controls{display:flex;gap:8px;justify-content:flex-end;margin-top:0}.review-tool-dialog .cdx-button--icon-only{padding:4px;display:inline-flex;align-items:center;justify-content:center}.review-tool-dialog .cdx-button__icon{width:16px;height:16px}.review-tool-annotation-ui .sentence{background:transparent}.review-tool-annotation-ui .sentence:hover{background:#ffeb3b1f}.review-tool-annotation-ui .annotation-badge{display:inline-block;background:#fc0;color:#000;border-radius:10px;padding:0 6px;font-size:11px;margin-left:6px}.review-tool-annotation-ui .floating-button{background:#1976d2;color:#fff;border:none;padding:6px 8px;border-radius:4px;box-shadow:0 2px 6px #0003;cursor:pointer}.review-tool-annotation-ui.floating-button,.floating-button.review-tool-annotation-ui{background:#1976d2;color:#fff;border:none;padding:6px 8px;border-radius:4px;box-shadow:0 2px 6px #0003;cursor:pointer;font-size:13px;line-height:1.2;white-space:nowrap}.review-tool-annotation-ui.floating-button:hover{background:#1e88e5}.review-tool-annotation-badge{display:inline-block;background:#fc0;color:#000;border-radius:10px;padding:0 6px;font-size:11px;margin-left:4px;vertical-align:baseline;text-decoration:none}.review-tool-annotation-badge:hover{filter:brightness(1.1)}.review-tool-annotation-badge--section{margin-left:6px}.review-tool-inline-annotation{display:inline-flex;align-items:center;margin-left:4px;vertical-align:baseline;gap:2px}.review-tool-inline-annotation__icon{background:#fff7d1;border:1px solid #f5c400;border-radius:999px;color:#202122;cursor:pointer;font-size:11px;line-height:1.3;padding:0 6px;text-decoration:none;display:inline-flex;align-items:center;justify-content:center;min-height:16px}.review-tool-inline-annotation__icon:hover{background:#ffe58f}html:not(.review-tool-annotation-mode) .review-tool-inline-annotation{display:none}.review-tool-annotation-editor__label{font-size:12px;font-weight:600;color:#54595d;margin-bottom:4px}.review-tool-annotation-editor__section{font-size:13px;color:#202122}.review-tool-annotation-editor__quote{background:#f8f9fa;border:1px solid #eaecf0;border-radius:4px;padding:8px;white-space:pre-wrap;max-height:160px;overflow-y:auto}.review-tool-annotation-editor__error{color:#d73333;font-size:12px;margin-top:4px}.review-tool-annotation-editor__footer{display:flex;justify-content:space-between;align-items:center;gap:12px;padding-top:12px}.review-tool-annotation-editor__actions{display:flex;gap:8px}.review-tool-annotation-viewer__empty{text-align:center;color:#54595d;padding:32px 0}.review-tool-annotation-viewer__footer{display:flex;justify-content:space-between;align-items:center;gap:12px;padding-top:12px;flex-wrap:wrap}.review-tool-annotation-viewer__footer-left{display:flex;align-items:center;gap:8px;flex:1 1 240px}.review-tool-annotation-viewer__sort-select{min-width:200px;flex:0 0 220px}.review-tool-annotation-viewer__footer-actions{display:flex;gap:8px;justify-content:flex-end;flex:1 1 auto;flex-wrap:wrap}.review-tool-annotation-viewer__section{margin-bottom:16px}.review-tool-annotation-viewer__section-title{font-size:13px;font-weight:600;margin:0 0 6px}.review-tool-annotation-viewer__items{list-style:none;padding:0;margin:0}.review-tool-annotation-viewer__item{border:1px solid #eaecf0;border-radius:6px;padding:8px;margin-bottom:8px;background:#fff}.review-tool-annotation-viewer__quote{font-style:italic;color:#54595d}.review-tool-annotation-viewer__opinion{margin-top:4px}.review-tool-annotation-viewer__meta{font-size:12px;color:#72777d;margin-top:4px}.review-tool-annotation-viewer__actions{display:flex;gap:8px;margin-top:6px}.review-tool-annotation-ui.sentence{background:transparent;transition:background .12s ease-in}.review-tool-annotation-ui.sentence:hover,.review-tool-annotation-ui .sentence:hover{background:#ffeb3b33}.review-tool-annotation-ui.sentence{cursor:pointer}html.rt-selecting .review-tool-annotation-ui.sentence{cursor:text}.review-tool-annotation-ui.floating-button,.floating-button.review-tool-annotation-ui{cursor:pointer}.review-tool-annotation-ui.sentence:hover,.review-tool-annotation-ui .sentence:hover{background:#ffeb3b38!important}.review-tool-annotation-mode .ipe__in-article-link,.review-tool-annotation-mode .ipe-quick-edit,.review-tool-annotation-mode .ipe-quick-edit--create-only,.review-tool-annotation-mode .qeec-ref-tag-copy-btn{user-select:text!important;pointer-events:auto!important}.review-tool-multistep-dialog header{padding:16px 24px}.review-tool-multistep-dialog header h2{margin:0;padding:0;font-size:20px}.review-tool-multistep-dialog__header-top{display:flex;align-items:center;justify-content:space-between}.review-tool-multistep-dialog__stepper{display:flex;align-items:center;gap:12px;padding:8px 24px 0}.review-tool-multistep-dialog__stepper__label{color:#6b7280;font-size:13px}.review-tool-multistep-dialog__stepper__steps{display:flex;gap:8px}.review-tool-multistep-dialog__stepper__step{background-color:#c8ccd1;display:block;width:12px;height:12px;border-radius:999px}.review-tool-multistep-dialog__stepper__step--active{background-color:#0b5fff}.review-tool-multistep-dialog__image{background-color:#f1f5f9;display:flex;justify-content:center;padding:12px 0}.review-tool-multistep-dialog__image img{display:block;max-width:100%}.review-tool-multistep-dialog__text{padding:16px 24px}.review-tool-multistep-dialog__text p{margin:8px 0 0;font-size:13px}.review-tool-multistep-dialog__text ul{margin:0;padding-left:24px}.review-tool-multistep-dialog__text li{font-size:13px}.review-tool-multistep-dialog footer{display:flex;align-items:center;justify-content:space-between;border-top:1px solid rgba(0,0,0,.06);padding:12px 24px}.review-tool-multistep-dialog__footer-left{display:flex;align-items:center;gap:8px}.review-tool-multistep-dialog__actions{display:flex;gap:12px}.review-tool-preview-pre--html{border:1px solid rgba(0,0,0,.1);border-radius:6px;background:#fafafa;padding:12px}
`;function be(){return{bplus:{label:a.convByVar({hant:"乙上級",hans:"乙上级"}),section_regex:/乙上?[級级]?(?:|[條条]目)[評评][審审選选級级]/,suggested_criteria:[a.convByVar({hant:"來源",hans:"来源"})+" (B1)",a.convByVar({hant:"覆蓋面",hans:"覆盖面"})+" (B2)",a.convByVar({hant:"結構",hans:"结构"})+" (B3)",a.convByVar({hant:"文筆",hans:"文笔"})+" (B4)",a.convByVar({hant:"配圖",hans:"配图"})+" (B5)",a.convByVar({hant:"易讀",hans:"易读"})+" (B6)",a.convByVar({hant:"乙上級以外的建議",hans:"乙上级以外的建议"})]},good:{label:a.convByVar({hant:"優良級",hans:"优良级"}),section_regex:/[優优]良[級级]?(?:|[條条]目)[評评][審审選选級级]/,page_prefix:"Wikipedia:優良條目評選",suggested_criteria:[a.convByVar({hant:"文筆",hans:"文笔"})+" (GA1)",a.convByVar({hant:"來源",hans:"来源"})+" (GA2)",a.convByVar({hant:"覆蓋面",hans:"覆盖面"})+" (GA3)",a.convByVar({hant:"中立",hans:"中立"})+" (GA4) & "+a.convByVar({hant:"穩定",hans:"稳定"})+" (GA5)",a.convByVar({hant:"配圖",hans:"配图"})+" (GA6)",a.convByVar({hant:"結構",hans:"结构"})+" (B3)",a.convByVar({hant:"易讀",hans:"易读"})+" (B6)",a.convByVar({hant:"優良級以外的建議",hans:"优良级以外的建议"})]},a:{label:a.convByVar({hant:"甲級",hans:"甲级"}),section_regex:/甲[級级](?:|[條条]目)[評评][審审選选級级]/,suggested_criteria:[a.convByVar({hant:"來源",hans:"来源"})+" (A1)",a.convByVar({hant:"覆蓋面",hans:"覆盖面"})+" (A2)",a.convByVar({hant:"結構",hans:"结构"})+" (A3)",a.convByVar({hant:"文筆",hans:"文笔"})+" (A4)",a.convByVar({hant:"配圖",hans:"配图"})+" (A5)",a.convByVar({hant:"易讀",hans:"易读"})+" (A6)",a.convByVar({hant:"甲級以外的建議",hans:"甲级以外的建议"})]},featured:{label:a.convByVar({hant:"典範級",hans:"典范级"}),section_regex:/典[範范][級级]?(?:|[條条]目)[評评][審审選选級级]/,page_prefix:"Wikipedia:典范条目评选",suggested_criteria:[a.convByVar({hant:"文筆",hans:"文笔"})+" (FA1a)",a.convByVar({hant:"覆蓋面",hans:"覆盖面"})+" (FA1b)",a.convByVar({hant:"來源",hans:"来源"})+" (FA1c)",a.convByVar({hant:"中立",hans:"中立"})+" (FA1d) & "+a.convByVar({hant:"穩定",hans:"稳定"})+" (FA1e)",a.convByVar({hant:"格式",hans:"格式"})+" (FA2)",a.convByVar({hant:"結構",hans:"结构"})+" (FA2b)",a.convByVar({hant:"配圖",hans:"配图"})+" (FA3)",a.convByVar({hant:"長度",hans:"长度"})+" (FA4)",a.convByVar({hant:"易讀",hans:"易读"})+" (A6)",a.convByVar({hant:"典範級以外的建議",hans:"典范级以外的建议"})]},featured_list:{label:a.convByVar({hant:"特色列表級",hans:"特色列表级"}),section_regex:/特色列表[級级]?(?:|[條条]目)[評评][審审選选級级]/,page_prefix:"Wikipedia:特色列表評选",suggested_criteria:[a.convByVar({hant:"文筆",hans:"文笔"})+" (FL1)",a.convByVar({hant:"序言",hans:"序言"})+" (FL2)",a.convByVar({hant:"覆蓋面",hans:"覆盖面"})+" (FL3a)",a.convByVar({hant:"長度",hans:"长度"})+" (FL3b)",a.convByVar({hant:"結構",hans:"结构"})+" (FL4)",a.convByVar({hant:"格式",hans:"格式"})+" (FL5a)",a.convByVar({hant:"配圖",hans:"配图"})+" (FL5b)",a.convByVar({hant:"穩定",hans:"稳定"})+" (FL6)",a.convByVar({hant:"特色列表級以外的建議",hans:"特色列表级以外的建议"})]}}}var Je=[/建[議议]/,/重新?[評评][級级]?/];function Be(){let e={};for(let[t,n]of Object.entries(be()))e[t]=n.section_regex;return e}function Ye(){let e={};for(let[t,n]of Object.entries(be()))e[t]=n.label;return e}var Le=null,De=null,xe=!1,pe=!1,$=null,ge=0;function Pe(e){return!e||!(e instanceof HTMLElement)?!1:e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?!e.disabled&&!e.readOnly:e.isContentEditable}function Ze(){$!==null&&(window.clearTimeout($),$=null),pe=!0,ge=Date.now()}function et(){ge=Date.now(),$!==null&&window.clearTimeout($),$=window.setTimeout(()=>{pe=!1,$=null},80)}function Te(e){let t=typeof e.inputType=="string"?e.inputType:"";(e.isComposing||t.indexOf("insertComposition")===0)&&(ge=Date.now(),pe=!0)}function tt(){return pe?!0:Date.now()-ge<=500}function Ae(e){if(e.key!=="Escape")return;let t=e.isComposing||e.keyCode===229,n=Pe(e.target)||Pe(document.activeElement);(t||n&&tt())&&(e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation())}function nt(e){let t=e.target;!t||t.tagName!=="DIALOG"||tt()&&Pe(document.activeElement)&&(e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation())}function nn(){xe||(window.addEventListener("compositionstart",Ze,!0),window.addEventListener("compositionend",et,!0),window.addEventListener("beforeinput",Te,!0),window.addEventListener("input",Te,!0),window.addEventListener("keydown",Ae,!0),window.addEventListener("keyup",Ae,!0),window.addEventListener("cancel",nt,!0),xe=!0)}function on(){xe&&(window.removeEventListener("compositionstart",Ze,!0),window.removeEventListener("compositionend",et,!0),window.removeEventListener("beforeinput",Te,!0),window.removeEventListener("input",Te,!0),window.removeEventListener("keydown",Ae,!0),window.removeEventListener("keyup",Ae,!0),window.removeEventListener("cancel",nt,!0),$!==null&&(window.clearTimeout($),$=null),xe=!1,pe=!1,ge=0)}function j(){return mw.loader.using("@wikimedia/codex").then(e=>{let t=e("vue"),n=e("@wikimedia/codex");return typeof window!="undefined"&&!window.Vue&&(window.Vue=t),{Vue:t,Codex:n}})}function rn(){if(!document.getElementById("review-tool-dialog-mount")){let e=document.createElement("div");e.id="review-tool-dialog-mount",document.body.appendChild(e)}return document.getElementById("review-tool-dialog-mount")}function z(e){return rn(),nn(),Le=e,De=e.mount("#review-tool-dialog-mount"),De}function q(){return Le}function B(){let e=document.getElementById("review-tool-dialog-mount");e&&e.remove(),on(),Le=null,De=null}function X(e,t){if(!(!e||!e.component||!t))try{e.component("cdx-dialog",t.CdxDialog).component("cdx-text-input",t.CdxTextInput).component("cdx-text-area",t.CdxTextArea).component("cdx-checkbox",t.CdxCheckbox).component("cdx-select",t.CdxSelect).component("cdx-button",t.CdxButton).component("cdx-button-group",t.CdxButtonGroup)}catch(n){}}function an(e){let t=e.indexOf("?"),o=(t>=0?e.slice(t+1):e).split("&").filter(Boolean),i={};for(let l of o){let[r,s]=l.split("=");if(r)try{i[decodeURIComponent(r)]=s?decodeURIComponent(s):""}catch(d){i[r]=s||""}}return i}function G(e){if(e instanceof Error)return e;if(typeof e=="string")return new Error(e);if(typeof e=="number"||typeof e=="boolean"||typeof e=="bigint")return new Error(String(e));if(typeof e=="symbol")return new Error(e.description||"Unknown error");if(typeof e=="function")return new Error(e.name||"Unknown error");try{return new Error(JSON.stringify(e))}catch(t){return new Error("Unknown error")}}function fe(e){if(!e)return{pageTitle:null,sectionId:null};let t=e.querySelector("a.qe-target")||e.querySelector('a[href*="action=edit"]');if(!t||!t.getAttribute)return{pageTitle:null,sectionId:null};let n=t.getAttribute("href")||"",o=an(n),i=o.title?decodeURIComponent(o.title):null,l=null;if(o.section){let r=parseInt(o.section,10);isNaN(r)||(l=r)}return{pageTitle:i,sectionId:l}}function Q(e,t){if(!e)return"";let n="=".repeat(Math.max(1,Math.min(6,t)));return`
${n}${e}${n}`}function me(e,t,n,o){return new Promise((i,l)=>{if(!e||typeof t!="number"||isNaN(t)){l(new Error("Invalid pageTitle or sectionId"));return}let r=a.getApi(),s={action:"edit",title:e,section:String(t),appendtext:n,format:"json",formatversion:"2"};o&&(s.summary=o),r.postWithToken("csrf",s).done(d=>{let g=d;g.edit&&g.edit.result==="Success"?(console.log("[ReviewTool][appendTextToSection] Append successful"),mw.notify(a.convByVar({hant:"已成功將內容附加到指定段落。",hans:"已成功将内容附加到指定段落。"})),ot()):g.error&&g.error.code==="editconflict"?(console.error("[ReviewTool][appendTextToSection] Edit conflict occurred"),mw.notify(a.convByVar({hant:"附加內容時發生編輯衝突。請重新嘗試。",hans:"附加内容时发生编辑冲突。请重新尝试。"}))):(console.error("[ReviewTool][appendTextToSection] Append failed",d),mw.notify(a.convByVar({hant:"附加內容失敗。請稍後再試。",hans:"附加内容失败。请稍后再试。"}))),i(d)}).fail(d=>l(G(d)))})}function ot(){setTimeout(()=>{location.reload()},2e3)}function K(e,t){return new Promise((n,o)=>{if(!e){o(new Error("Invalid pageTitle"));return}let i=a.getApi(),l={action:"query",prop:"revisions",titles:e,rvslots:"main",rvprop:["timestamp","content"],curtimestamp:!0,format:"json",formatversion:"2"};typeof t=="number"&&!isNaN(t)&&(l.rvsection=String(t)),i.postWithToken("csrf",l).done(r=>{var s,d,g,p;try{let c=r,u=(d=(s=c.query)==null?void 0:s.pages)==null?void 0:d[0],f=(g=u==null?void 0:u.revisions)==null?void 0:g[0];if(f){let h=((p=f.slots)==null?void 0:p.main)||{"*":""},m=typeof h.content=="string"?h.content:h["*"];n({text:m,starttimestamp:c.curtimestamp||"",basetimestamp:f.timestamp||""});return}}catch(c){o(G(c));return}o(new Error("No content found"))}).fail(r=>o(G(r)))})}async function it(e,t,n,o,i){if(!e||typeof t!="number"||isNaN(t))throw new Error("Invalid pageTitle or sectionId");let l=a.getApi(),r=i==null?void 0:i.starttimestamp,s=i==null?void 0:i.basetimestamp;if(!r||!s){let p=await K(e,t);r=p.starttimestamp,s=p.basetimestamp}let d={action:"edit",title:e,section:String(t),text:n,starttimestamp:r,basetimestamp:s,format:"json",formatversion:"2"};return o&&(d.summary=o),await new Promise((p,c)=>{l.postWithToken("csrf",d).done(u=>{var h;((h=u.edit)==null?void 0:h.result)==="Success"&&ot(),p(u)}).fail(u=>c(G(u)))})}function he(e,t){return new Promise((n,o)=>{try{let i=a.getApi(),l={action:"parse",text:e||"",contentmodel:"wikitext",format:"json"};t&&(l.title=t),i.post(l).done(r=>{var s;try{let d=r;if((s=d.parse)!=null&&s.text){n(d.parse.text["*"]||"");return}}catch(d){}n("")}).fail(r=>o(G(r)))}catch(i){o(G(i))}})}function ve(e,t){return new Promise((n,o)=>{try{let i=a.getApi(),l={action:"compare",fromslots:"main","fromtext-main":e||"",fromtitle:mw.config.get("wgPageName"),frompst:!0,toslots:"main","totext-main":t||"",totitle:mw.config.get("wgPageName"),topst:!0};i.postWithToken("csrf",l).done(r=>{try{let s=r;s.compare&&s.compare["*"]&&n('<table class="diff"><colgroup><col class="diff-marker"/><col class="diff-content"/><col class="diff-marker"/><col class="diff-content"/></colgroup>'+s.compare["*"]+"</table>"),n(a.convByVar({hant:"無差異。",hans:"无差异。"}))}catch(s){o(G(s))}}).fail(r=>o(G(r)))}catch(i){o(G(i))}})}function sn(e,t){if(!(!e||!t)){try{if(typeof mw!="undefined"&&mw&&mw.hook&&typeof mw.hook=="function"){let n=window.jQuery;mw.hook("wikipage.content").fire(n?n(e):e)}}catch(n){}if(t.indexOf('class="diff')!==-1)try{mw&&mw.loader&&mw.loader.load&&mw.loader.load("mediawiki.diff.styles")}catch(n){}}}function ln(e,t){var n,o;return t==="preview"?(n=e.previewHtml)!=null?n:null:(o=e.diffHtml)!=null?o:null}function ie(e,t){e.$nextTick(()=>{let n=ln(e,t);if(!n)return;let o=t==="preview"?"previewHtmlHost":"diffHtmlHost",l=e.$refs[o];Array.isArray(l)&&(l=l[0]),l&&((!l.innerHTML||!l.innerHTML.trim())&&(l.innerHTML=n),sn(l,n))})}function rt(e,t){e.$nextTick(()=>{var i,l;let n=(i=t==null?void 0:t.previewStepIndex)!=null?i:1,o=(l=t==null?void 0:t.diffStepIndex)!=null?l:2;e.currentStep===n&&e.previewHtml?ie(e,"preview"):e.currentStep===o&&e.diffHtml&&ie(e,"diff")})}function ke(e,t){var l;let n=(l=t.totalSteps)!=null?l:3;if(e.currentStep>=n-1)return!1;let o=e.currentStep+1;e.currentStep=o;let i=()=>{o===1&&t.onEnterEditStep?t.onEnterEditStep.call(e):o===2&&t.onEnterPreviewStep?t.onEnterPreviewStep.call(e):o===3&&t.onEnterDiffStep&&t.onEnterDiffStep.call(e),rt(e,t)};return typeof e.$nextTick=="function"?e.$nextTick(i):i(),!0}function Ee(e){return e.currentStep<=0?!1:(e.currentStep--,rt(e),!0)}function cn(){return{submitting:a.convByVar({hant:"添加中…",hans:"添加中…"}),submit:a.convByVar({hant:"添加",hans:"添加"}),cancel:a.convByVar({hant:"取消",hans:"取消"}),dialogTitle:a.convByVar({hant:"為「",hans:"为「"})+a.articleTitle+a.convByVar({hant:"」添加評審意見",hans:"」添加评审意见"}),submitUnderOpinionSubsection:a.convByVar({hant:"將評審內容置於「",hans:"将评审内容置于「"})+a.userName+a.convByVar({hant:"的意見」小節內",hans:"的意见」小节内"}),selectCriterion:a.convByVar({hant:"評審標準:",hans:"评审标准:"}),criterionPlaceholder:a.convByVar({hant:"選擇評審標準",hans:"选择评审标准"}),addCriteriaToReview:a.convByVar({hant:"將以下標準加入評審",hans:"将以下标准加入评审"}),next:a.convByVar({hant:"下一步",hans:"下一步"}),previous:a.convByVar({hant:"上一步",hans:"上一步"}),previewHeading:a.convByVar({hant:"預覽",hans:"预览"}),diffHeading:a.convByVar({hant:"差異",hans:"差异"}),editHeading:a.convByVar({hant:"檢查編輯",hans:"检查编辑"}),editInstruction:a.convByVar({hant:"在此調整要新增的維基語法內容,再前往預覽或差異。",hans:"在此调整要新增的维基语法内容,再前往预览或差异。"}),editPlaceholder:a.convByVar({hant:"在此輸入或修改評審建議的維基語法內容…",hans:"在此输入或修改评审建议的维基语法内容…"}),noSpecificCriteria:a.convByVar({hant:"未選擇評審標準。",hans:"未选择评审标准。"}),noDiff:a.convByVar({hant:"無差異。",hans:"无差异。"})}}var at={data(){return{open:!0,isSubmitting:!1,currentStep:0,submitUnderOpinionSubsection:!a.inTalkPage,selectedAssessmentType:a.assessmentType||"",selectedCriteria:[],criterion:null,previewHtml:"",diffHtml:"",previewWikitext:"",existingSectionText:"",pendingNewSectionText:"",sectionRevisionInfo:null,editedDraft:""}},computed:{assessmentLabels(){return Ye()},codexOptions(){return Object.entries(this.assessmentLabels).map(([e,t])=>({value:e,label:t}))},suggestedCriteria(){if(!this.selectedAssessmentType)return[];let t=be()[this.selectedAssessmentType];return t&&Array.isArray(t.suggested_criteria)?t.suggested_criteria:[]},codexCriteriaItems(){return this.suggestedCriteria.map(e=>({value:e,label:e}))},primaryAction(){return this.currentStep<3?{label:this.$options.i18n.next||"Next",actionType:"primary",disabled:!1}:{label:this.isSubmitting?this.$options.i18n.submitting:this.$options.i18n.submit,actionType:"progressive",disabled:this.isSubmitting}},defaultAction(){return this.currentStep>0?{label:this.$options.i18n.previous||"Previous"}:{label:this.$options.i18n.cancel}}},beforeCreate(){this.$options.i18n=cn()},methods:{triggerContentHooks(e){ie(this,e)},getPendingReviewSectionInfo(){var i;let e=a.pendingReviewHeading||null,t=fe(e),n=t&&t.pageTitle?t.pageTitle:a.articleTitle||"",o=typeof(t==null?void 0:t.sectionId)=="number"?t.sectionId:(i=t==null?void 0:t.sectionId)!=null?i:null;return{headingEl:e,sec:t,pageTitleToUse:n,sectionIdToUse:o}},buildHeadersForCriteria(e){return Array.isArray(this.selectedCriteria)&&this.selectedCriteria.length>0?this.selectedCriteria.map(t=>Q(String(t),e)).join(""):this.criterion?Q(String(this.criterion),e):""},buildOpinionContent(e){let t=this.buildHeadersForCriteria(e);return t&&t.trim()?t:""},reportMissingOpinionEntries(e=!1){let t=a.convByVar({hant:"請先選擇或輸入評審子項,再提交。",hans:"请先选择或输入评审子项,再提交。"});if(mw&&mw.notify&&mw.notify(t,{type:"error",title:"[ReviewTool]"}),e)try{alert(t)}catch(n){}return t},prepareEditDraft(){this.editedDraft=this.buildDraftContent().trim()},buildDraftContent(){let e=this.submitUnderOpinionSubsection?4:3;return this.submitUnderOpinionSubsection?this.buildOpinionContent(e):this.buildHeadersForCriteria(e)},getDraftFragment(){let e=(this.editedDraft||"").trim();return e?`
${e}`:""},preparePreviewContent(){let{pageTitleToUse:e,sectionIdToUse:t}=this.getPendingReviewSectionInfo(),n=this.submitUnderOpinionSubsection?4:3;this.previewHtml="",this.previewWikitext="",this.pendingNewSectionText="",this.existingSectionText="",this.sectionRevisionInfo=null;let o=this.getDraftFragment();if(!this.submitUnderOpinionSubsection){let d=o||this.buildHeadersForCriteria(n);if(!d||!d.trim()){this.reportMissingOpinionEntries();return}this.previewWikitext=d,he(d,e).then(g=>{this.previewHtml=g||"",this.previewHtml&&this.currentStep===2&&this.triggerContentHooks("preview")}).catch(g=>{console.error("[ReviewTool] parseWikitextToHtml failed",g),this.previewHtml=""});return}let i=`${a.userName}${a.convByVar({hant:" 的意見",hans:" 的意见"})}`,l=o||this.buildOpinionContent(4);if(!l||!l.trim()){this.reportMissingOpinionEntries(!0),this.isSubmitting=!1;return}let r=l?Q(i,3)+l:"",s=(d,g,p)=>{this.previewWikitext=d,this.existingSectionText=g,this.pendingNewSectionText=p,he(d,e).then(c=>{this.previewHtml=c||"",this.previewHtml&&this.currentStep===2&&this.triggerContentHooks("preview")}).catch(c=>{console.error("[ReviewTool] parseWikitextToHtml failed",c),this.previewHtml=""})};t!=null?K(e,t).then(({text:d,starttimestamp:g,basetimestamp:p})=>{this.sectionRevisionInfo={starttimestamp:g,basetimestamp:p};let c=d||"",u=this.computeOpinionInsertion(c,l,i);s(u.previewFragment,c,u.newSectionText)}).catch(d=>{console.error("[ReviewTool] retrieveFullText failed",d),this.sectionRevisionInfo=null,s(r,"",r)}):s(r,"",r)},prepareDiffContent(){let{pageTitleToUse:e,sectionIdToUse:t}=this.getPendingReviewSectionInfo();this.diffHtml="";let n=this.getDraftFragment();if(!this.submitUnderOpinionSubsection){let s=this.previewWikitext||n||this.buildHeadersForCriteria(3);if(!s||!s.trim()){this.reportMissingOpinionEntries();return}let d=(g,p)=>{ve(g||"",p).then(c=>{this.diffHtml=c||"",this.diffHtml&&this.currentStep===3&&this.triggerContentHooks("diff")}).catch(c=>{console.error("[ReviewTool] compareWikitext failed",c),this.diffHtml=""})};t!=null?K(e,t).then(({text:g,starttimestamp:p,basetimestamp:c})=>{this.sectionRevisionInfo={starttimestamp:p,basetimestamp:c};let u=g||"";this.existingSectionText=u,d(u,(u||"")+s)}).catch(g=>{console.error("[ReviewTool] retrieveFullText failed",g),this.sectionRevisionInfo=null,d("",s)}):d("",s);return}let o=`${a.userName}${a.convByVar({hant:" 的意見",hans:" 的意见"})}`,i=n||this.buildOpinionContent(4),l=(s,d)=>{this.existingSectionText=s,this.pendingNewSectionText=d,ve(s||"",d).then(g=>{this.diffHtml=g||"",this.diffHtml&&this.currentStep===3&&this.triggerContentHooks("diff")}).catch(g=>{console.error("[ReviewTool] compareWikitext failed",g),this.diffHtml=""})};if(this.pendingNewSectionText){l(this.existingSectionText||"",this.pendingNewSectionText);return}let r=i?Q(o,3)+i:"";t!=null?K(e,t).then(({text:s,starttimestamp:d,basetimestamp:g})=>{this.sectionRevisionInfo={starttimestamp:d,basetimestamp:g};let p=s||"",c=this.computeOpinionInsertion(p,i,o);l(p,c.newSectionText)}).catch(s=>{console.error("[ReviewTool] retrieveFullText failed",s),this.sectionRevisionInfo=null,l("",r)}):l("",r)},computeOpinionInsertion(e,t,n){if(!t||!t.trim())return{previewFragment:"",newSectionText:e,insertedIntoExisting:!1};let o=/^\s*(={1,6})\s*([^\r\n]*?)\s*\1\s*$/gm,i=g=>{if(!g)return"";let p=g.replace(/'''+/g,"").replace(/''/g,"");try{let c=document.createElement("textarea");c.innerHTML=p,p=c.value}catch(c){}return p.replace(/\s+/g," ").trim()},l=i(n),r;for(;(r=o.exec(e))!==null;){let g=r[0],p=r[2];if(i(p)===l){let c=r[1].length,u=r.index+g.length,f=e.slice(u),h=/^\s*(={1,6})\s*([^\r\n]*?)\s*\1\s*$/gm,m=e.length,x;for(;(x=h.exec(f))!==null;)if(x[1].length<=c){m=u+x.index;break}let k=e.slice(0,m),T=e.slice(m),A=!k.length||/\r?\n$/.test(k),b=t;A?b=b.replace(/^(?:\r?\n)+/,""):/^\r?\n/.test(b)||(b=`
`+b),/\r?\n$/.test(b)||(b+=`
`),T.length&&!/^\r?\n/.test(T)&&(b+=`
`);let C=k+b+e.slice(m);return{previewFragment:t,newSectionText:C,insertedIntoExisting:!0}}}let s=Q(n,3)+t,d=e+s;return{previewFragment:s,newSectionText:d,insertedIntoExisting:!1}},getStepClass(e){return{"review-tool-multistep-dialog__stepper__step--active":e<=this.currentStep}},onPrimaryAction(){ke(this,{totalSteps:4,onEnterEditStep:this.prepareEditDraft,onEnterPreviewStep:this.preparePreviewContent,onEnterDiffStep:this.prepareDiffContent,previewStepIndex:2,diffStepIndex:3})||this.submitReview()},onDefaultAction(){Ee(this)||this.closeDialog()},onUpdateOpen(e){e||this.closeDialog()},closeDialog(){this.open=!1,setTimeout(()=>{B()},300)},submitReview(){if(!this.selectedAssessmentType){mw&&mw.notify&&mw.notify(a.convByVar({hant:"請選擇評審標準。",hans:"请选择评审标准。"}),{type:"error",title:"[ReviewTool]"});return}this.isSubmitting=!0;let e=a.pendingReviewHeading||null,t=fe(e);if(!t||!t.sectionId){let u=a.convByVar({hant:"無法識別章節編號,請在討論頁的章節標題附近點擊「管理評審」。",hans:"无法识别章节编号,请在讨论页的章节标题附近点击“管理评审”。"});mw&&mw.notify&&mw.notify(u,{type:"error",title:"[ReviewTool]"}),alert(u),this.isSubmitting=!1;return}let n=this.submitUnderOpinionSubsection?4:3,o=this.getDraftFragment(),i=(u,f)=>u.map(h=>Q(String(h),f)).join(""),l=t.pageTitle||a.articleTitle||"",r=t.sectionId;if(!this.submitUnderOpinionSubsection){let u=o||(Array.isArray(this.selectedCriteria)&&this.selectedCriteria.length>0?i(this.selectedCriteria,n):this.criterion?Q(String(this.criterion),n):"");if(!u||!u.trim()){this.reportMissingOpinionEntries(!0),this.isSubmitting=!1;return}me(l,r,u,a.convByVar({hant:"使用 [[User:SuperGrey/gadgets/ReviewTool|ReviewTool]] 新增評審項目",hans:"使用 [[User:SuperGrey/gadgets/ReviewTool|ReviewTool]] 新增评审项目"})).then(()=>{mw&&mw.notify&&mw.notify(a.convByVar({hant:"已成功新增評審項目。",hans:"已成功新增评审项目。"}),{tag:"review-tool"}),this.isSubmitting=!1,this.open=!1,a.pendingReviewHeading=null,setTimeout(()=>{B()},200)}).catch(f=>{console.error("[ReviewTool] appendTextToSection failed",f);let h=a.convByVar({hant:"新增評審項目失敗,請稍後再試。",hans:"新增评审项目失败,请稍后再试。"});mw&&mw.notify&&mw.notify(h,{type:"error",title:"[ReviewTool]"}),alert(h),this.isSubmitting=!1});return}let s=`${a.userName}${a.convByVar({hant:" 的意見",hans:" 的意见"})}`,d=o||this.buildOpinionContent(4),g=this.sectionRevisionInfo;if(!g){let u=a.convByVar({hant:"請先預覽並檢視差異,以取得最新段落資訊後再提交。",hans:"请先预览并查看差异,以取得最新段落资讯后再提交。"});mw&&mw.notify&&mw.notify(u,{type:"error",title:"[ReviewTool]"}),alert(u),this.isSubmitting=!1;return}let p=typeof this.existingSectionText=="string"?this.existingSectionText:"",c=this.computeOpinionInsertion(p,d,s);c.insertedIntoExisting?it(l,r,c.newSectionText,a.convByVar({hant:"使用 [[User:SuperGrey/gadgets/ReviewTool|ReviewTool]] 新增評審子項",hans:"使用 [[User:SuperGrey/gadgets/ReviewTool|ReviewTool]] 新增评审子项"}),g).then(()=>{mw&&mw.notify&&mw.notify(a.convByVar({hant:"已成功新增評審子項。",hans:"已成功新增评审子项。"}),{tag:"review-tool"}),this.isSubmitting=!1,this.open=!1,a.pendingReviewHeading=null,setTimeout(()=>{B()},200)}).catch(u=>{console.error("[ReviewTool] replaceSectionText failed",u);let f=a.convByVar({hant:"新增評審子項失敗,請稍後再試。",hans:"新增评审子项失败,请稍后再试。"});mw&&mw.notify&&mw.notify(f,{type:"error",title:"[ReviewTool]"}),alert(f),this.isSubmitting=!1}):me(l,r,c.previewFragment,a.convByVar({hant:"使用 [[User:SuperGrey/gadgets/ReviewTool|ReviewTool]] 新增評審項",hans:"使用 [[User:SuperGrey/gadgets/ReviewTool|ReviewTool]] 新增评审项目"})).then(()=>{mw&&mw.notify&&mw.notify(a.convByVar({hant:"已成功新增評審項目。",hans:"已成功新增评审项目。"}),{tag:"review-tool"}),this.isSubmitting=!1,this.open=!1,a.pendingReviewHeading=null,setTimeout(()=>{B()},200)}).catch(u=>{console.error("[ReviewTool] appendTextToSection failed",u);let f=a.convByVar({hant:"新增評審項目失敗,請稍後再試。",hans:"新增评审项目失败,请稍后再试。"});mw&&mw.notify&&mw.notify(f,{type:"error",title:"[ReviewTool]"}),alert(f),this.isSubmitting=!1})}}};function dn(e,t){let{toDisplayString:n,createElementVNode:o,renderList:i,Fragment:l,openBlock:r,createElementBlock:s,normalizeClass:d,createTextVNode:g,resolveComponent:p,withCtx:c,createVNode:u,createBlock:f,createCommentVNode:h}=window.Vue,m=p("cdx-checkbox"),x=p("cdx-select"),k=p("cdx-text-area"),T=p("cdx-dialog");return r(),f(T,{open:e.open,"onUpdate:open":[t[4]||(t[4]=A=>e.open=A),e.onUpdateOpen],title:e.$options.i18n.dialogTitle,"use-close-button":!0,"primary-action":e.primaryAction,"default-action":e.defaultAction,onPrimary:e.onPrimaryAction,onDefault:e.onDefaultAction,class:"review-tool-dialog review-tool-review-management-dialog review-tool-multistep-dialog"},{header:c(()=>[o("div",{class:"review-tool-multistep-dialog__header-top"},[o("h2",null,n(e.$options.i18n.dialogTitle),1)]),o("div",{class:"review-tool-multistep-dialog__stepper"},[o("div",{class:"review-tool-multistep-dialog__stepper__label"},n(e.currentStep+1+" / 4"),1),o("div",{class:"review-tool-multistep-dialog__stepper__steps","aria-hidden":""},[(r(),s(l,null,i([0,1,2,3],A=>o("span",{key:A,class:d(["review-tool-multistep-dialog__stepper__step",e.getStepClass(A)])},null,2)),64))])])]),default:c(()=>[e.currentStep===0?(r(),s("div",{key:0},[o("div",{class:"review-tool-form-section"},[u(m,{modelValue:e.submitUnderOpinionSubsection,"onUpdate:modelValue":t[0]||(t[0]=A=>e.submitUnderOpinionSubsection=A)},{default:c(()=>[g(n(e.$options.i18n.submitUnderOpinionSubsection),1)]),_:1},8,["modelValue"])]),o("div",{class:"review-tool-form-section"},[o("label",{class:"review-tool-select-label"},n(e.$options.i18n.selectCriterion),1),u(x,{selected:e.selectedAssessmentType,"onUpdate:selected":t[1]||(t[1]=A=>e.selectedAssessmentType=A),"menu-items":e.codexOptions,"default-label":e.$options.i18n.criterionPlaceholder},null,8,["selected","menu-items","default-label"])]),e.selectedAssessmentType?(r(),s("div",{key:0,class:"review-tool-form-section"},[o("label",{class:"review-tool-checkbox-label"},n(e.$options.i18n.addCriteriaToReview),1),o("div",{class:"review-tool-suggested-criteria-grid"},[(r(!0),s(l,null,i(e.codexCriteriaItems,(A,b)=>(r(),f(m,{key:b,modelValue:e.selectedCriteria,"onUpdate:modelValue":t[2]||(t[2]=R=>e.selectedCriteria=R),"input-value":A.value},{default:c(()=>[g(n(A.label),1)]),_:2},1032,["modelValue","input-value"]))),128))])])):h("v-if",!0)])):e.currentStep===1?(r(),s("div",{key:1,class:"review-tool-edit-step"},[o("h3",null,n(e.$options.i18n.editHeading),1),o("p",{class:"review-tool-edit-step__instruction"},n(e.$options.i18n.editInstruction),1),u(k,{modelValue:e.editedDraft,"onUpdate:modelValue":t[3]||(t[3]=A=>e.editedDraft=A),placeholder:e.$options.i18n.editPlaceholder,rows:"16"},null,8,["modelValue","placeholder"])])):e.currentStep===2?(r(),s("div",{key:2,class:"review-tool-preview"},[o("h3",null,n(e.$options.i18n.previewHeading),1),e.previewHtml?(r(),s("div",{key:0,class:"review-tool-preview-pre review-tool-preview-pre--html",ref:"previewHtmlHost",innerHTML:e.previewHtml},null,8,["innerHTML"])):(r(),s("pre",{key:1,class:"review-tool-preview-pre"},n(e.previewWikitext||e.editedDraft||(e.selectedCriteria.length?e.selectedCriteria.join(`
`):e.criterion||e.$options.i18n.noSpecificCriteria)),1))])):e.currentStep===3?(r(),s("div",{key:3,class:"review-tool-diff"},[o("h3",null,n(e.$options.i18n.diffHeading),1),e.diffHtml?(r(),s("div",{key:0,class:"review-tool-diff-pre review-tool-diff-pre--html",ref:"diffHtmlHost",innerHTML:e.diffHtml},null,8,["innerHTML"])):(r(),s("div",{key:1},[o("p",null,n(e.$options.i18n.noDiff),1)]))])):h("v-if",!0)]),_:1},8,["open","title","primary-action","default-action","onPrimary","onDefault","onUpdate:open"])}at.render=dn;var st=at;function un(){j().then(({Vue:e,Codex:t})=>{let n=e.createMwApp(st);X(n,t),z(n)}).catch(e=>{console.error("[ReviewTool] 無法加載 Codex:",e),mw&&mw.notify&&mw.notify(a.convByVar({hant:"無法加載對話框組件。",hans:"无法加载对话框组件。"}),{type:"error",title:"[ReviewTool]"})})}function lt(){q&&q()&&B(),un()}var pn="reviewtool:annotations:";function Ne(e){return pn+(e||"unknown")}function re(e){if(typeof window=="undefined")return null;try{return e==="local"?window.localStorage:window.sessionStorage}catch(t){return console.error(`[ReviewTool] ${e}Storage unavailable`,t),null}}function ct(e){return{pageName:e,createdAt:Date.now(),annotations:[]}}function gn(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function dt(e){return!!e&&typeof e=="object"}function fn(e){if(!dt(e)||typeof e.id!="string"||typeof e.sectionPath!="string"||typeof e.sentenceText!="string"||typeof e.opinion!="string"||typeof e.createdBy!="string"||typeof e.createdAt!="number")return null;let t=typeof e.sentencePos=="string"?e.sentencePos:"",n=typeof e.resolved=="boolean"?e.resolved:void 0;return{id:e.id,sectionPath:e.sectionPath,sentencePos:t,sentenceText:e.sentenceText,opinion:e.opinion,createdBy:e.createdBy,createdAt:e.createdAt,resolved:n}}function we(e){let t=Ne(e),n=re("local"),o=re("session"),i=null,l=null;if(n)try{i=n.getItem(t),i&&(l="local")}catch(c){console.error("[ReviewTool] failed to read annotations from localStorage",c)}if(!i&&o)try{i=o.getItem(t),i&&(l="session")}catch(c){console.error("[ReviewTool] failed to read annotations from sessionStorage",c)}if(!i)return ct(e);let r=null;try{r=JSON.parse(i)}catch(c){return console.warn("[ReviewTool] failed to parse annotations payload",c),ct(e)}let s=dt(r)?r:null,g=(s&&Array.isArray(s.annotations)?s.annotations:[]).map(c=>fn(c)).filter(c=>!!c),p={pageName:typeof(s==null?void 0:s.pageName)=="string"?s.pageName:e,createdAt:typeof(s==null?void 0:s.createdAt)=="number"?s.createdAt:Date.now(),annotations:g};if(l==="session"&&n)try{n.setItem(t,JSON.stringify(p)),o==null||o.removeItem(t)}catch(c){console.error("[ReviewTool] failed to migrate annotations from sessionStorage to localStorage",c)}return p}function He(e){let t=Ne(e.pageName),n=JSON.stringify(e),o=re("local");if(o)try{o.setItem(t,n);return}catch(l){console.error("[ReviewTool] failed to save annotations to localStorage",l)}let i=re("session");if(i)try{i.setItem(t,n)}catch(l){console.error("[ReviewTool] failed to save annotations to sessionStorage fallback",l)}else console.error("[ReviewTool] no available storage to save annotations")}function ut(e,t,n,o,i=""){let l=we(e),r=t==="目次"?"序言":t,s={id:gn(),sectionPath:r,sentencePos:i,sentenceText:n,opinion:o,createdBy:a.userName||"unknown",createdAt:Date.now(),resolved:!1};return l.annotations.push(s),He(l),s}function pt(e,t){return we(e).annotations.find(o=>o.id===t)||null}function gt(e,t,n){let o=we(e),i=o.annotations.findIndex(r=>r.id===t);if(i===-1)return null;let l=oe(oe({},o.annotations[i]),n);return o.annotations[i]=l,He(o),l}function Ie(e,t){let n=we(e),o=n.annotations.length;return n.annotations=n.annotations.filter(i=>i.id!==t),n.annotations.length!==o?(He(n),!0):!1}function ft(e){let t=Ne(e),n=re("local"),o=re("session"),i=!1;if(n)try{n.getItem(t)!==null&&(i=!0),n.removeItem(t)}catch(l){console.error("[ReviewTool] failed to clear annotations from localStorage",l)}if(o)try{o.getItem(t)!==null&&(i=!0),o.removeItem(t)}catch(l){console.error("[ReviewTool] failed to clear annotations from sessionStorage",l)}return i}function mn(e){return[...e].sort((t,n)=>t.createdAt-n.createdAt)}function ae(e){let t=we(e);if(!t.annotations.length)return[];let n=new Map;for(let i of t.annotations){let l=typeof i.sectionPath=="string"&&i.sectionPath.trim()?i.sectionPath.trim():"",r=n.get(l);r?r.push(i):n.set(l,[i])}let o=[];for(let[i,l]of n.entries())o.push({sectionPath:i,annotations:mn(l)});return o.sort((i,l)=>{var d,g,p,c;let r=(g=(d=i.annotations[0])==null?void 0:d.createdAt)!=null?g:Number.MAX_SAFE_INTEGER,s=(c=(p=l.annotations[0])==null?void 0:p.createdAt)!=null?c:Number.MAX_SAFE_INTEGER;return r===s?i.sectionPath.localeCompare(l.sectionPath):r-s}),o}var mt="#mw-content-text";function hn(e){return e?typeof e=="string"?document.querySelector(e):e:document.querySelector(mt)}function vn(e){let t=0,n=e?e.previousElementSibling:null;for(;n;)t++,n=n.previousElementSibling;return t}function wn(e,t){if(!e)return null;let n=hn(t);if(!n||!n.contains(e))return null;let o=[],i=e;for(;i&&i!==n;)o.push(vn(i)),i=i.parentElement;return i!==n?null:(o.reverse(),o)}function yn(e,t=6){if(!e)return null;let n=Math.max(1,t|0);return e.map(o=>String(o).padStart(n,"0")).join(".")}function ht(e,t){var o,i;let n=wn(e,(o=t==null?void 0:t.root)!=null?o:mt);return yn(n,(i=t==null?void 0:t.paddingWidth)!=null?i:6)}function se(e,t){if(!e&&!t)return 0;if(!e)return-1;if(!t)return 1;let n=e.split(".").map(l=>parseInt(l,10)),o=t.split(".").map(l=>parseInt(l,10)),i=Math.min(n.length,o.length);for(let l=0;l<i;l++)if(n[l]!==o[l])return n[l]-o[l];return n.length-o.length}function bn(){return{dialogTitle:a.convByVar({hant:"檢查「",hans:"检查「"})+a.articleTitle+a.convByVar({hant:"」的文筆",hans:"」的文笔"}),save:a.convByVar({hant:"儲存",hans:"保存"}),saving:a.convByVar({hant:"儲存中…",hans:"保存中…"}),cancel:a.convByVar({hant:"取消",hans:"取消"}),addChapter:a.convByVar({hant:"新增章節",hans:"新增章节"}),removeChapter:a.convByVar({hant:"刪除章節",hans:"删除章节"}),addSuggestion:a.convByVar({hant:"新增意見",hans:"新增意见"}),removeSuggestion:a.convByVar({hant:"刪除意見",hans:"删除意见"}),chapterTitleLabel:a.convByVar({hant:"章節標題",hans:"章节标题"}),quoteLabel:a.convByVar({hant:"引用原文",hans:"引用原文"}),quotePlaceholder:a.convByVar({hant:"原文句子(可留空)",hans:"原文句子(可留空)"}),suggestionPlaceholder:a.convByVar({hant:"意見或建議",hans:"意见或建议"}),next:a.convByVar({hant:"下一步",hans:"下一步"}),previous:a.convByVar({hant:"上一步",hans:"上一步"}),previewHeading:a.convByVar({hant:"預覽",hans:"预览"}),diffHeading:a.convByVar({hant:"差異",hans:"差异"}),diffLoading:a.convByVar({hant:"差異載入中…",hans:"差异载入中…"}),editHeading:a.convByVar({hant:"檢查編輯",hans:"检查编辑"}),editInstruction:a.convByVar({hant:"在此調整要新增的維基語法內容,再前往預覽或差異。",hans:"在此调整要新增的维基语法内容,再前往预览或差异。"}),editPlaceholder:a.convByVar({hant:"在此輸入或修改文筆建議的維基語法內容…",hans:"在此输入或修改文笔建议的维基语法内容…"}),loadAnnotations:a.convByVar({hant:"載入批註",hans:"载入批注"}),importFromFile:a.convByVar({hant:"從檔案載入",hans:"从文件载入"}),importSuccess:a.convByVar({hant:"已從檔案載入批註。",hans:"已从文件载入批注。"}),importError:a.convByVar({hant:"載入檔案時發生錯誤。",hans:"读取文件时发生错误。"}),importInvalid:a.convByVar({hant:"無效的批註檔案。",hans:"无效的批注文件。"}),annotationFallbackChapter:a.convByVar({hant:"(未指定章節)",hans:"(未指定章节)"})}}function ye(e){return!!e&&typeof e=="object"}var vt={data(){return{open:!0,isSaving:!1,isLoadingAnnotations:!1,currentStep:0,chapters:[{title:"",suggestions:[{quote:"",suggestion:""}]}],previewWikitext:"",previewHtml:"",existingSectionText:"",pendingNewSectionText:"",diffHtml:"",diffLines:[],editedDraft:""}},computed:{primaryAction(){return this.currentStep<3?{label:this.$options.i18n.next||"Next",actionType:"progressive",disabled:!1}:{label:this.isSaving?this.$options.i18n.saving:this.$options.i18n.save,actionType:"progressive",disabled:this.isSaving}},defaultAction(){return this.currentStep>0?{label:this.$options.i18n.previous||"Previous",disabled:!1}:{label:this.$options.i18n.cancel,disabled:!1}},showAnnotationLoaderButton(){return this.currentStep===0}},beforeCreate(){this.$options.i18n=bn()},methods:{triggerContentHooks(e){ie(this,e)},getPendingCheckWritingSectionInfo(){var i;let e=a.pendingReviewHeading||null,t=fe(e),n=t&&t.pageTitle?t.pageTitle:a.articleTitle||"",o=typeof(t==null?void 0:t.sectionId)=="number"?t.sectionId:(i=t==null?void 0:t.sectionId)!=null?i:null;return{headingEl:e,sec:t,pageTitleToUse:n,sectionIdToUse:o}},getStepClass(e){return{"review-tool-multistep-dialog__stepper__step--active":e<=this.currentStep}},prepareEditDraft(){this.editedDraft=this.buildWikitext().trim()},preparePreviewContent(){let{pageTitleToUse:e,sectionIdToUse:t}=this.getPendingCheckWritingSectionInfo();this.previewHtml="",this.previewWikitext="",this.pendingNewSectionText="",this.existingSectionText="",this.diffHtml="",this.diffLines=[];let n=this.buildPreviewBundle();if(!n)return;let{previewFragment:o,appendSuffix:i}=n;this.previewWikitext=o;let l=r=>{let s=r||"";this.existingSectionText=s,this.pendingNewSectionText=s+i,he(o,e).then(d=>{this.previewHtml=d||"",this.previewHtml&&this.currentStep===2&&this.triggerContentHooks("preview")}).catch(d=>{console.error("[ReviewTool] parseWikitextToHtml failed",d),this.previewHtml=""})};t!=null?K(e,t).then(({text:r})=>{l(r||"")}).catch(r=>{console.error("[ReviewTool] retrieveFullText failed",r),l("")}):l("")},prepareDiffContent(){let{pageTitleToUse:e,sectionIdToUse:t}=this.getPendingCheckWritingSectionInfo();this.diffHtml="",this.diffLines=[];let n=this.buildPreviewBundle();if(!n)return;let{previewFragment:o,appendSuffix:i}=n;this.previewWikitext=o;let l=r=>{let s=r||"",d=s+i;this.existingSectionText=s,this.pendingNewSectionText=d,ve(s,d).then(g=>{this.diffHtml=g||"",this.diffHtml&&this.currentStep===3?this.triggerContentHooks("diff"):this.diffLines=this.buildDiffLines(s,i)}).catch(g=>{console.error("[ReviewTool] compareWikitext failed",g),this.diffHtml="",this.diffLines=this.buildDiffLines(s,i)})};if(this.pendingNewSectionText&&typeof this.existingSectionText=="string"&&this.pendingNewSectionText===this.existingSectionText+i){l(this.existingSectionText);return}t!=null?K(e,t).then(({text:r})=>{l(r||"")}).catch(r=>{console.error("[ReviewTool] retrieveFullText failed",r),l("")}):l("")},onPrimaryAction(){ke(this,{totalSteps:4,onEnterEditStep:this.prepareEditDraft,onEnterPreviewStep:this.preparePreviewContent,onEnterDiffStep:this.prepareDiffContent,previewStepIndex:2,diffStepIndex:3})||this.saveCheckWriting()},onDefaultAction(){Ee(this)||this.closeDialog()},onUpdateOpen(e){e||this.closeDialog()},closeDialog(){this.open=!1,setTimeout(()=>{B()},300)},buildPreviewBundle(){let t=(this.editedDraft||"").trim()||this.buildWikitext().trim();if(!t)return null;let n=`

${t}`;return{previewFragment:t,appendSuffix:n}},buildWikitext(){let e="";for(let t of this.chapters){let n=(t.title||"").trim();e+="'''"+n+`'''
`;for(let o of t.suggestions||[]){let i=(o.quote||"").trim(),l=(o.suggestion||"").trim().replace(/\n{2,}/g,"{{pb}}").replace(/\n/g,"<br>");e+=`* {{rvw|1=${i}}} —— ${l}
`}e+=`--~~~~

`}return e=e.replace("{{rvw|1=}} —— ",""),e},buildDiffLines(e,t){let n=(e||"").split(/\r?\n/),i=(t||"").replace(/^\s*\n+/,"").split(/\r?\n/),l=[];return l.push("--- Existing section ---"),l.push(...n.map(r=>"  "+r)),l.push(""),l.push("+++ New content to append +++"),l.push(...i.map(r=>"+ "+r)),l},handleImportClick(){let e=this.$refs.annotationImportInput,t=e instanceof HTMLInputElement?e:null;t&&typeof t.click=="function"?(t.value="",t.click()):console.warn("[ReviewTool] file input not available for import")},generateImportAnnotationId(){return`import-${Date.now()}-${Math.random().toString(36).slice(2,9)}`},normalizeImportedAnnotation(e,t=""){let n=ye(e)?e:{},o=typeof n.id=="string"&&n.id.trim()?n.id.trim():this.generateImportAnnotationId(),i=typeof n.sectionPath=="string"&&n.sectionPath.trim()?n.sectionPath.trim():t||"";return{id:o,sectionPath:i,sentencePos:typeof n.sentencePos=="string"?n.sentencePos:"",sentenceText:typeof n.sentenceText=="string"?n.sentenceText:typeof n.quote=="string"?n.quote:"",opinion:typeof n.opinion=="string"?n.opinion:typeof n.suggestion=="string"?n.suggestion:"",createdBy:typeof n.createdBy=="string"?n.createdBy:a.userName||"import",createdAt:typeof n.createdAt=="number"?n.createdAt:Date.now(),resolved:!!n.resolved}},onAnnotationFileSelected(e){let t=e.target instanceof HTMLInputElement?e.target:null;if(!t||!t.files||!t.files.length)return;let n=t.files[0],o=new FileReader;o.onload=i=>{var l;try{let r=(l=i.target)==null?void 0:l.result,d=JSON.parse(typeof r=="string"?r:"");if(!(a.articleTitle||"")){this.reportAnnotationLoadFailure(a.convByVar({hant:"無法識別條目名稱,無法載入檔案中的批註。",hans:"无法识别条目名称,无法载入文件中的批注。"}));return}let p=[];if(ye(d)&&Array.isArray(d.annotations))for(let u of d.annotations)p.push(this.normalizeImportedAnnotation(u));else if(ye(d)&&Array.isArray(d.groups))for(let u of d.groups){let f=ye(u)?u:{},h=typeof f.sectionPath=="string"?f.sectionPath:"",m=Array.isArray(f.annotations)?f.annotations:[];for(let x of m){let k=ye(x)?x:{},T=typeof k.sectionPath=="string"?k.sectionPath:h,A=Re(oe({},k),{sectionPath:T});p.push(this.normalizeImportedAnnotation(A,h))}}else throw new Error("invalid-format");if(!p.length)throw new Error("empty-import");this.applyImportedAnnotations(p);let c=this.$options.i18n.importSuccess||"Imported annotations from file.";mw&&mw.notify&&mw.notify(c,{tag:"review-tool"})}catch(r){console.error("[ReviewTool] failed to import annotations from file",r);let s=this.$options.i18n.importInvalid||"Invalid annotation file.";this.reportAnnotationLoadFailure(s)}},o.onerror=i=>{console.error("[ReviewTool] FileReader error",i);let l=this.$options.i18n.importError||"Failed to read file.";this.reportAnnotationLoadFailure(l)},o.readAsText(n,"utf-8")},loadAnnotationsIntoForm(){if(!this.isLoadingAnnotations){this.isLoadingAnnotations=!0;try{let e=a.articleTitle||"";if(!e){this.reportAnnotationLoadFailure(a.convByVar({hant:"無法識別條目名稱,無法載入批註。",hans:"无法识别条目名称,无法载入批注。"}));return}let t=ae(e);if(!t.length){this.reportAnnotationLoadFailure(a.convByVar({hant:"目前沒有可載入的批註。",hans:"目前没有可载入的批注。"}));return}let n=this.buildChaptersFromAnnotationGroups(t);if(!n.length){this.reportAnnotationLoadFailure(a.convByVar({hant:"批註內容為空,請稍後再試。",hans:"批注内容为空,请稍后再试。"}));return}this.applyAnnotationChapters(n);let o=a.convByVar({hant:"已將批註載入表單,請檢查後繼續。",hans:"已将批注载入表单,请检查后继续。"});mw&&mw.notify&&mw.notify(o,{tag:"review-tool"})}finally{this.isLoadingAnnotations=!1}}},buildChaptersFromAnnotationGroups(e){if(!e.length)return[];let t=this.$options.i18n.annotationFallbackChapter||"";return e.map(i=>Re(oe({},i),{annotations:this.sortAnnotationsByPosition(i.annotations)})).sort((i,l)=>{let r=i.annotations[0],s=l.annotations[0],d=se(r==null?void 0:r.sentencePos,s==null?void 0:s.sentencePos);return d!==0?d:(i.sectionPath||"").localeCompare(l.sectionPath||"")}).map(i=>{let l=(i.annotations||[]).map(s=>({quote:s.sentenceText||"",suggestion:s.opinion||""})),r=l.length?l:[{quote:"",suggestion:""}];return{title:i.sectionPath||t,suggestions:r}}).filter(i=>Array.isArray(i.suggestions)&&i.suggestions.length)},applyAnnotationChapters(e){e.length&&(this.chapters=e,this.currentStep===2?this.preparePreviewContent():this.currentStep===3&&this.prepareDiffContent())},sortAnnotationsByPosition(e){return Array.isArray(e)?e.slice().sort((t,n)=>{let o=se(t==null?void 0:t.sentencePos,n==null?void 0:n.sentencePos);return o!==0?o:(t.createdAt||0)-(n.createdAt||0)}):[]},groupAnnotationsBySection(e){let t=new Map;return e.forEach(n=>{let o=(n.sectionPath||"").trim(),i=t.get(o);i?i.push(n):t.set(o,[n])}),Array.from(t.entries()).map(([n,o])=>({sectionPath:n,annotations:o}))},applyImportedAnnotations(e){if(!Array.isArray(e)||!e.length)throw new Error("empty-import");let t=this.groupAnnotationsBySection(e),n=this.buildChaptersFromAnnotationGroups(t);if(!n.length)throw new Error("empty-chapters");this.applyAnnotationChapters(n)},reportAnnotationLoadFailure(e){mw&&mw.notify&&mw.notify(e,{type:"warn",title:"[ReviewTool]"}),alert(e)},saveCheckWriting(){this.isSaving=!0;let{sec:e,pageTitleToUse:t,sectionIdToUse:n}=this.getPendingCheckWritingSectionInfo();if(!e||n==null){let i=a.convByVar({hant:"無法識別文筆章節編號,請在討論頁的文筆章節附近點擊「檢查文筆」。",hans:"无法识别文笔章节编号,请在讨论页的文笔章节附近点击“检查文笔”。"});mw&&mw.notify&&mw.notify(i,{type:"error",title:"[ReviewTool]"}),alert(i),this.isSaving=!1;return}let o=this.buildPreviewBundle();if(!o){let i=a.convByVar({hant:"請先輸入文筆建議內容,再嘗試儲存。",hans:"请先输入文笔建议内容,再尝试保存。"});mw&&mw.notify&&mw.notify(i,{type:"error",title:"[ReviewTool]"}),alert(i),this.isSaving=!1;return}me(t,n,o.appendSuffix,a.convByVar({hant:"使用 [[User:SuperGrey/gadgets/ReviewTool|ReviewTool]] 新增文筆建議",hans:"使用 [[User:SuperGrey/gadgets/ReviewTool|ReviewTool]] 新增文笔建议"})).then(()=>{mw&&mw.notify&&mw.notify(a.convByVar({hant:"已成功新增文筆建議。",hans:"已成功新增文笔建议。"}),{tag:"review-tool"}),this.isSaving=!1,this.open=!1,a.pendingReviewHeading=null,setTimeout(()=>{B()},200)}).catch(i=>{console.error("[ReviewTool] appendTextToSection failed",i);let l=a.convByVar({hant:"新增文筆建議失敗,請稍後再試。",hans:"新增文笔建议失败,请稍后再试。"});mw&&mw.notify&&mw.notify(l,{type:"error",title:"[ReviewTool]"}),alert(l),this.isSaving=!1})},addChapter(){this.chapters.push({title:"",suggestions:[{quote:"",suggestion:""}]})},removeChapter(e){this.chapters.length<=1||this.chapters.splice(e,1)},addSuggestion(e){this.chapters[e].suggestions.push({quote:"",suggestion:""})},removeSuggestion(e,t){let n=this.chapters[e].suggestions;n.length<=1||n.splice(t,1)}}};function xn(e,t){let{toDisplayString:n,createElementVNode:o,renderList:i,Fragment:l,openBlock:r,createElementBlock:s,normalizeClass:d,resolveComponent:g,createVNode:p,withModifiers:c,withCtx:u,createTextVNode:f,createBlock:h,createCommentVNode:m}=window.Vue,x=g("cdx-text-input"),k=g("cdx-text-area"),T=g("cdx-button"),A=g("cdx-dialog");return r(),h(A,{open:e.open,"onUpdate:open":[t[2]||(t[2]=b=>e.open=b),e.onUpdateOpen],title:e.$options.i18n.dialogTitle,"use-close-button":!0,class:"review-tool-dialog review-tool-check-writing-dialog review-tool-multistep-dialog"},{header:u(()=>[o("div",{class:"review-tool-multistep-dialog__header-top"},[o("h2",null,n(e.$options.i18n.dialogTitle),1)]),o("div",{class:"review-tool-multistep-dialog__stepper"},[o("div",{class:"review-tool-multistep-dialog__stepper__label"},n(e.currentStep+1+" / 4"),1),o("div",{class:"review-tool-multistep-dialog__stepper__steps","aria-hidden":""},[(r(),s(l,null,i([0,1,2,3],b=>o("span",{key:b,class:d(["review-tool-multistep-dialog__stepper__step",e.getStepClass(b)])},null,2)),64))])])]),footer:u(()=>[o("div",{class:"review-tool-multistep-dialog__footer-left"},[e.showAnnotationLoaderButton?(r(),h(T,{key:0,weight:"quiet",disabled:e.isLoadingAnnotations,onClick:c(e.loadAnnotationsIntoForm,["prevent"])},{default:u(()=>[f(n(e.$options.i18n.loadAnnotations),1)]),_:1},8,["disabled","onClick"])):m("v-if",!0),e.showAnnotationLoaderButton?(r(),h(T,{key:1,weight:"quiet",onClick:c(e.handleImportClick,["prevent"])},{default:u(()=>[f(n(e.$options.i18n.importFromFile),1)]),_:1},8,["onClick"])):m("v-if",!0),o("input",{ref:"annotationImportInput",type:"file",accept:"application/json,.json",style:{display:"none"},onChange:t[1]||(t[1]=(...b)=>e.onAnnotationFileSelected&&e.onAnnotationFileSelected(...b))},null,544)]),o("div",{class:"review-tool-multistep-dialog__actions"},[e.defaultAction?(r(),h(T,{key:0,action:"normal",disabled:e.defaultAction.disabled,onClick:c(e.onDefaultAction,["prevent"])},{default:u(()=>[f(n(e.defaultAction.label),1)]),_:1},8,["disabled","onClick"])):m("v-if",!0),e.primaryAction?(r(),h(T,{key:1,action:e.primaryAction.actionType,disabled:e.primaryAction.disabled,onClick:c(e.onPrimaryAction,["prevent"])},{default:u(()=>[f(n(e.primaryAction.label),1)]),_:1},8,["action","disabled","onClick"])):m("v-if",!0)])]),default:u(()=>[e.currentStep===0?(r(),s("div",{key:0},[(r(!0),s(l,null,i(e.chapters,(b,R)=>(r(),s("div",{key:R,class:"review-tool-form-section chapter-block"},[p(x,{modelValue:b.title,"onUpdate:modelValue":C=>b.title=C,placeholder:e.$options.i18n.chapterTitleLabel,class:"chapter-title-input"},null,8,["modelValue","onUpdate:modelValue","placeholder"]),o("div",{class:"chapter-suggestions"},[(r(!0),s(l,null,i(b.suggestions,(C,L)=>(r(),s("div",{key:L,class:"suggestion-row"},[o("div",{class:"suggestion-bullet","aria-hidden":"true"}),o("div",{class:"suggestion-columns"},[o("div",{class:"quote-col"},[p(k,{class:"quote-area",modelValue:C.quote,"onUpdate:modelValue":v=>C.quote=v,placeholder:e.$options.i18n.quotePlaceholder,rows:"1"},null,8,["modelValue","onUpdate:modelValue","placeholder"])]),o("div",{class:"suggestion-col"},[p(k,{class:"suggestion-area",modelValue:C.suggestion,"onUpdate:modelValue":v=>C.suggestion=v,placeholder:e.$options.i18n.suggestionPlaceholder,rows:"1"},null,8,["modelValue","onUpdate:modelValue","placeholder"])]),o("div",{class:"suggestion-controls"},[p(T,{size:"small",class:"cdx-button--icon-only","aria-label":e.$options.i18n.removeSuggestion,disabled:b.suggestions.length<=1,onClick:c(v=>e.removeSuggestion(R,L),["prevent"])},{default:u(()=>[(r(),s("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",width:"16",height:"16"},[o("path",{d:"M3 6h18v2H3V6zm2 3h14l-1 11H6L5 9zm3-6h6l1 2H7l1-2z"})]))]),_:1},8,["aria-label","disabled","onClick"])])])]))),128))]),o("div",{class:"row-controls"},[o("div",{class:"suggestion-add"},[p(T,{size:"small",onClick:c(C=>e.addSuggestion(R),["prevent"])},{default:u(()=>[(r(),s("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",width:"16",height:"16",style:{"margin-right":"6px"}},[o("path",{d:"M11 11V6h2v5h5v2h-5v5h-2v-5H6v-2z"})])),f(" "+n(e.$options.i18n.addSuggestion),1)]),_:1},8,["onClick"])]),o("div",{class:"chapter-controls"},[R===e.chapters.length-1?(r(),h(T,{key:0,size:"small",onClick:c(e.addChapter,["prevent"])},{default:u(()=>[(r(),s("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",width:"16",height:"16",style:{"margin-right":"6px"}},[o("path",{d:"M11 11V6h2v5h5v2h-5v5h-2v-5H6v-2z"})])),f(" "+n(e.$options.i18n.addChapter),1)]),_:1},8,["onClick"])):m("v-if",!0),p(T,{size:"small",disabled:e.chapters.length<=1,onClick:c(C=>e.removeChapter(R),["prevent"])},{default:u(()=>[(r(),s("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",width:"16",height:"16",style:{"margin-right":"6px"}},[o("path",{d:"M3 6h18v2H3V6zm2 3h14l-1 11H6L5 9zm3-6h6l1 2H7l1-2z"})])),f(" "+n(e.$options.i18n.removeChapter),1)]),_:1},8,["disabled","onClick"])])])]))),128))])):e.currentStep===1?(r(),s("div",{key:1,class:"review-tool-edit-step"},[o("h3",null,n(e.$options.i18n.editHeading),1),o("p",{class:"review-tool-edit-step__instruction"},n(e.$options.i18n.editInstruction),1),p(k,{modelValue:e.editedDraft,"onUpdate:modelValue":t[0]||(t[0]=b=>e.editedDraft=b),placeholder:e.$options.i18n.editPlaceholder,rows:"16"},null,8,["modelValue","placeholder"])])):e.currentStep===2?(r(),s("div",{key:2,class:"review-tool-preview"},[o("h3",null,n(e.$options.i18n.previewHeading),1),e.previewHtml?(r(),s("div",{key:0,class:"review-tool-preview-pre review-tool-preview-pre--html",ref:"previewHtmlHost",innerHTML:e.previewHtml},null,8,["innerHTML"])):(r(),s("pre",{key:1,class:"review-tool-preview-pre"},n(e.previewWikitext),1))])):e.currentStep===3?(r(),s("div",{key:3,class:"review-tool-diff"},[o("h3",null,n(e.$options.i18n.diffHeading),1),e.diffHtml?(r(),s("div",{key:0,class:"review-tool-diff-pre review-tool-diff-pre--html",ref:"diffHtmlHost",innerHTML:e.diffHtml},null,8,["innerHTML"])):(r(),s("div",{key:1},[o("p",null,n(e.$options.i18n.diffLoading),1),o("pre",{class:"review-tool-diff-pre"},n(e.diffLines.join(`
`)),1)]))])):m("v-if",!0)]),_:1},8,["open","title","onUpdate:open"])}vt.render=xn;var wt=vt;function Tn(){j().then(({Vue:e,Codex:t})=>{let n=e.createMwApp(wt);X(n,t),z(n)}).catch(e=>{console.error("[ReviewTool] 無法加載 Codex:",e),mw&&mw.notify&&mw.notify(a.convByVar({hant:"無法加載對話框組件。",hans:"无法加载对话框组件。"}),{type:"error",title:"[ReviewTool]"})})}function yt(){q()&&B(),Tn()}function Me(e,t,n){let o=document.createElement("a");o.href="#",o.className="review-tool-button",o.textContent=e,o.setAttribute("title",t),o.onclick=s=>{s.preventDefault(),s.stopPropagation(),n(s)};let i=document.createElement("span");i.className="mw-editsection-bracket",i.textContent=" [";let l=document.createElement("span");l.className="mw-editsection-bracket",l.textContent="]";let r=document.createElement("span");return r.className="review-tool-button-group",r.appendChild(i),r.appendChild(o),r.appendChild(l),r}function U(e){if(!e)return null;let t=e instanceof HTMLHeadingElement?e:e.querySelector("h1, h2, h3, h4, h5, h6");if(!t)return null;if(t.id)return t.id;let n=t.querySelector("[id]");if(n&&n.id)return n.id;let o=t.getAttribute&&t.getAttribute("data-mw-thread-id");return o||t.textContent&&t.textContent.trim()||null}function le(e,t){let n=e.querySelector(".mw-editsection");if(n){try{let o=t.querySelector&&t.querySelector("a")||null;if(o&&typeof o.onclick=="function"){let i=o.onclick;o.onclick=l=>{try{a.pendingReviewHeading=e}catch(r){throw console.error("[ReviewTool][appendButtonToHeading] failed to set pendingReviewHeading",r),r}try{i.call(o,l)}catch(r){throw console.error("[ReviewTool][appendButtonToHeading] original click handler failed",r),r}}}else o&&o.addEventListener("click",()=>{try{a.pendingReviewHeading=e}catch(i){throw console.error("[ReviewTool][appendButtonToHeading] failed to set pendingReviewHeading",i),i}})}catch(o){throw console.error("[ReviewTool][appendButtonToHeading] failed to append button or import state",o),o}n.append(t)}}function bt(e,t,n,o,i){let l=document.getElementById("p-views");if(!l)return console.warn("[ReviewTool] Vector menu #p-views not found"),null;let r=l.querySelector(".vector-menu-content-list");if(!r)return console.warn("[ReviewTool] Vector menu content list not found"),null;if(document.getElementById(e))return document.getElementById(e);let s=document.createElement("li");s.id=e,s.className="vector-tab-noicon mw-list-item",i!=null&&i.selected&&s.classList.add("selected");let d=document.createElement("a");d.href="#",d.title=n,d.onclick=c=>{c.preventDefault(),c.stopPropagation(),o(c)};let g=document.createElement("span");g.textContent=t,d.appendChild(g),s.appendChild(d);let p=r.querySelector("#ca-watch");return p?r.insertBefore(s,p):r.appendChild(s),s}function xt(e,t,n){let o=["p-cactions","p-tb"],i=document.getElementById(e);if(!i)for(let p of o){let c=mw.util.addPortletLink(p,"#",t,e,t);if(c){i=c;break}}if(!i)return;let l=i.querySelector("a");l&&(l.textContent=t,l.title=t,l.href="#");let r=i.cloneNode(!0);i.replaceWith(r);let s=document.getElementById(e),d=s==null?void 0:s.querySelector("a"),g=p=>{p.preventDefault(),n()};d?(d.addEventListener("click",g),d.addEventListener("keydown",p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),n())})):s&&s.addEventListener("click",g)}function An(e){var n,o;if(!e)return"";if(typeof mw!="undefined"&&((n=mw==null?void 0:mw.Title)!=null&&n.newFromText))try{let i=mw.Title.newFromText(e),l=(o=i==null?void 0:i.getSubjectPage)==null?void 0:o.call(i);if(l!=null&&l.getPrefixedText)return l.getPrefixedText()}catch(i){console.warn("[ReviewTool] deriveSubjectArticleTitle failed to parse Title",i)}let t=[{regex:/^User_talk:/i,replacement:"User:"},{regex:/^Wikipedia_talk:/i,replacement:"Wikipedia:"},{regex:/^Project_talk:/i,replacement:"Project:"},{regex:/^Template_talk:/i,replacement:"Template:"},{regex:/^Help_talk:/i,replacement:"Help:"},{regex:/^Category_talk:/i,replacement:"Category:"},{regex:/^Portal_talk:/i,replacement:"Portal:"},{regex:/^Draft_talk:/i,replacement:"Draft:"},{regex:/^Module_talk:/i,replacement:"Module:"},{regex:/^Talk:/i,replacement:""}];for(let{regex:i,replacement:l}of t)if(i.test(e))return e.replace(i,l);return e}function kt(e,t){let n=null;if(a.inTalkPage){let o=Be();for(let[i,l]of Object.entries(o))if(l.test(t)){n=i;break}}else e==="Wikipedia:Wikipedia:優良條目評選"?n="good":e==="Wikipedia:Wikipedia:典范条目评选"?n="featured":e==="Wikipedia:Wikipedia:特色列表评选"&&(n="featured_list");return n}function Tt(e,t){let n=kt(e,t);return Me(a.convByVar({hant:"管理評審",hans:"管理评审"}),a.convByVar({hant:"使用 ReviewTool 小工具管理評審",hans:"使用 ReviewTool 小工具管理评审"}),()=>{a.articleTitle=e,a.assessmentType=n,lt()})}function Fe(e,t){let n=kt(e,t);return Me(a.convByVar({hant:"檢查文筆",hans:"检查文笔"}),a.convByVar({hant:"使用 ReviewTool 小工具檢查文筆",hans:"使用 ReviewTool 小工具检查文笔"}),()=>{a.articleTitle=e,a.assessmentType=n,yt()})}function Et(e,t){var r,s;if(document.querySelector("#review-tool-buttons-added"))return;let n=document.querySelectorAll(".mw-heading.mw-heading2"),o=typeof mw!="undefined"&&((r=mw==null?void 0:mw.Title)!=null&&r.newFromText)?mw.Title.newFromText(t):null;if(o&&typeof o.isTalkPage=="function"&&o.isTalkPage()||(typeof e=="number"?e%2===1:!1)){a.inTalkPage=!0;let d=An(t);a.articleTitle=d,Array.from(n).filter(p=>{let c=U(p);return c?Object.values(Be()).some(u=>u.test(c))||Je.some(u=>u.test(c)):!1}).forEach(p=>{let c=U(p);c&&(le(p,Tt(d,c)),le(p,Fe(d,c)),At(p,d,c))})}else a.inTalkPage=!1,n.forEach(d=>{let g=U(d);g&&(le(d,Tt(g,g)),le(d,Fe(g,g)),At(d,g,g))});let l=document.createElement("div");l.id="review-tool-buttons-added",l.style.display="none",(s=document.querySelector("#mw-content-text .mw-parser-output"))==null||s.appendChild(l)}function At(e,t,n){let o=e.nextElementSibling;for(;o&&!o.classList.contains("mw-heading2");){if(o.classList.contains("mw-heading")){let i=U(o);i&&/文[筆笔]/.test(i)&&le(o,Fe(t,n))}o=o.nextElementSibling}}var kn=(...e)=>window.Vue&&window.Vue.defineComponent?window.Vue.defineComponent(...e):e[0],Ct=kn({__name:"annotation_editor",props:{mode:{type:String,required:!1,default:"create"},sectionPath:{type:String,required:!1,default:""},sentenceText:{type:String,required:!1,default:""},initialOpinion:{type:String,required:!1,default:""},allowDelete:{type:Boolean,required:!1,default:!1},onResolve:{type:Function,required:!1,default:void 0}},setup(e,{expose:t}){t();function n(){return{titleCreate:a.convByVar({hant:"新增批註",hans:"新增批注"}),titleEdit:a.convByVar({hant:"編輯批註",hans:"编辑批注"}),sectionLabel:a.convByVar({hant:"章節:",hans:"章节:"}),sentenceLabel:a.convByVar({hant:"句子:",hans:"句子:"}),opinionLabel:a.convByVar({hant:"批註內容",hans:"批注内容"}),opinionPlaceholder:a.convByVar({hant:"請輸入批註內容…",hans:"请输入批注内容…"}),opinionRequired:a.convByVar({hant:"批註內容不能為空",hans:"批注内容不能为空"}),cancel:a.convByVar({hant:"取消",hans:"取消"}),save:a.convByVar({hant:"儲存",hans:"保存"}),create:a.convByVar({hant:"新增",hans:"新增"}),delete:a.convByVar({hant:"刪除",hans:"删除"}),deleteConfirm:a.convByVar({hant:"確定要刪除這條批註?",hans:"确定要删除这条批注?"})}}let o=window.Vue;if(!o)throw new Error("Vue runtime not found");let{ref:i,computed:l,watch:r}=o,s=e,d=n(),g=i(!0),p=i(typeof s.initialOpinion=="string"?s.initialOpinion:""),c=i(!1),u=l(()=>s.mode==="edit"?d.titleEdit:d.titleCreate),f=l(()=>s.mode==="edit"?d.save:d.create),h=l(()=>!!(p.value||"").trim());r(p,()=>{c.value&&h.value&&(c.value=!1)});function m(){g.value=!1,setTimeout(()=>B(),200)}function x(){var R;if(!h.value){c.value=!0;return}(R=s.onResolve)==null||R.call(s,{action:"save",opinion:p.value.trim()}),m()}function k(){var R;(R=s.onResolve)==null||R.call(s,{action:"cancel"}),m()}function T(){var C;!s.allowDelete||!window.confirm(d.deleteConfirm)||((C=s.onResolve)==null||C.call(s,{action:"delete"}),m())}function A(R){R||k()}let b={buildI18n:n,VueRuntime:o,ref:i,computed:l,watch:r,props:s,i18n:d,open:g,opinion:p,showValidationError:c,dialogTitle:u,primaryLabel:f,canSave:h,closeDialog:m,onPrimaryAction:x,onCancelAction:k,onDeleteClick:T,onUpdateOpen:A};return Object.defineProperty(b,"__isScriptSetup",{enumerable:!1,value:!0}),b}});function En(e,t,n,o,i,l){let{toDisplayString:r,createElementVNode:s,resolveComponent:d,createVNode:g,openBlock:p,createElementBlock:c,createCommentVNode:u,createTextVNode:f,withModifiers:h,withCtx:m,createBlock:x}=window.Vue,k=d("cdx-text-area"),T=d("cdx-button"),A=d("cdx-dialog");return p(),x(A,{open:o.open,"onUpdate:open":[t[1]||(t[1]=b=>o.open=b),o.onUpdateOpen],title:o.dialogTitle,"use-close-button":!0,class:"review-tool-dialog review-tool-annotation-editor-dialog"},{footer:m(()=>[s("div",{class:"review-tool-annotation-editor__footer"},[o.props.allowDelete?(p(),x(T,{key:0,weight:"quiet",action:"destructive",class:"review-tool-annotation-editor__delete",onClick:h(o.onDeleteClick,["prevent"])},{default:m(()=>[f(r(o.i18n.delete),1)]),_:1})):u("v-if",!0),s("div",{class:"review-tool-annotation-editor__actions"},[g(T,{weight:"quiet",onClick:h(o.onCancelAction,["prevent"])},{default:m(()=>[f(r(o.i18n.cancel),1)]),_:1}),g(T,{action:"progressive",disabled:!o.canSave,onClick:h(o.onPrimaryAction,["prevent"])},{default:m(()=>[f(r(o.primaryLabel),1)]),_:1},8,["disabled"])])])]),default:m(()=>[s("div",{class:"review-tool-form-section"},[s("div",{class:"review-tool-annotation-editor__label"},r(o.i18n.sectionLabel),1),s("div",{class:"review-tool-annotation-editor__section"},r(o.props.sectionPath),1)]),s("div",{class:"review-tool-form-section"},[s("div",{class:"review-tool-annotation-editor__label"},r(o.i18n.sentenceLabel),1),s("div",{class:"review-tool-annotation-editor__quote"},r(o.props.sentenceText),1)]),s("div",{class:"review-tool-form-section"},[s("label",{class:"review-tool-annotation-editor__label",for:"annotation-opinion-input"},r(o.i18n.opinionLabel),1),g(k,{id:"annotation-opinion-input",modelValue:o.opinion,"onUpdate:modelValue":t[0]||(t[0]=b=>o.opinion=b),rows:"5",placeholder:o.i18n.opinionPlaceholder},null,8,["modelValue","placeholder"]),o.showValidationError?(p(),c("div",{key:0,class:"review-tool-annotation-editor__error"},r(o.i18n.opinionRequired),1)):u("v-if",!0)])]),_:1},8,["open","title"])}Ct.render=En;var St=Ct;function Vt(e){var n;let t={sectionPath:e.sectionPath,sentenceText:e.sentenceText,initialOpinion:e.initialOpinion||"",mode:e.mode||"create",allowDelete:(n=e.allowDelete)!=null?n:e.mode==="edit"};return q()&&B(),j().then(({Vue:o,Codex:i})=>new Promise(l=>{let r=!1,s=g=>{r||(r=!0,l(g))},d=o.createMwApp({render(){return o.h(St,{sectionPath:t.sectionPath,sentenceText:t.sentenceText,initialOpinion:t.initialOpinion,mode:t.mode,allowDelete:t.allowDelete,onResolve:s})}});X(d,i),z(d)})).catch(o=>{throw console.error("[ReviewTool] Failed to open annotation editor dialog",o),mw&&mw.notify&&mw.notify(a.convByVar({hant:"無法開啟批註對話框。",hans:"无法开启批注对话框。"}),{type:"error",title:"[ReviewTool]"}),o})}var Cn=(...e)=>window.Vue&&window.Vue.defineComponent?window.Vue.defineComponent(...e):e[0],Rt=Cn({__name:"annotation_viewer",props:{initialGroups:{type:Array,required:!1,default:()=>[]},onEditAnnotation:{type:Function,required:!1,default:void 0},onDeleteAnnotation:{type:Function,required:!1,default:void 0},onClearAllAnnotations:{type:Function,required:!1,default:void 0},onClosed:{type:Function,required:!1,default:void 0}},setup(e,{expose:t}){function n(){return{title:a.convByVar({hant:"批註列表",hans:"批注列表"}),empty:a.convByVar({hant:"尚無批註",hans:"尚无批注"}),edit:a.convByVar({hant:"編輯",hans:"编辑"}),delete:a.convByVar({hant:"刪除",hans:"删除"}),deleteConfirm:a.convByVar({hant:"確定刪除?",hans:"确定删除?"}),clearAll:a.convByVar({hant:"清除全部",hans:"清除全部"}),clearAllConfirm:a.convByVar({hant:"確定刪除所有批註?",hans:"确定删除所有批注?"}),clearAllDone:a.convByVar({hant:"已清除所有批註。",hans:"已清除所有批注。"}),clearAllNothing:a.convByVar({hant:"沒有可清除的批註。",hans:"没有可清除的批注。"}),clearAllError:a.convByVar({hant:"清除批註時發生錯誤。",hans:"清除批注时发生错误。"}),sectionFallback:a.convByVar({hant:"(未指定章節)",hans:"(未指定章节)"}),close:a.convByVar({hant:"關閉",hans:"关闭"}),export:a.convByVar({hant:"匯出",hans:"导出"}),exportDone:a.convByVar({hant:"已匯出批註。",hans:"已导出批注。"}),exportError:a.convByVar({hant:"匯出批註時發生錯誤。",hans:"导出批注时发生错误。"}),sortLabel:a.convByVar({hant:"排序方式",hans:"排序方式"}),sortCreatedAsc:a.convByVar({hant:"最早時間優先",hans:"最早时间优先"}),sortCreatedDesc:a.convByVar({hant:"最新時間優先",hans:"最新时间优先"}),sortPosition:a.convByVar({hant:"頁面位置",hans:"页面位置"})}}let o=window.Vue;if(!o)throw new Error("Vue runtime not found");let{ref:i,computed:l}=o,r=e,s=n(),d=i(!0),g=i(r.initialGroups||[]),p=i(null),c=i(!1),u=i("position");t({open:d,groups:g});let f=l(()=>!!r.onClearAllAnnotations),h=l(()=>!Array.isArray(g.value)||!g.value.length?!0:g.value.every(y=>!y.annotations||y.annotations.length===0)),m=l(()=>{if(!Array.isArray(g.value))return[];let y=[];return g.value.forEach(E=>{Array.isArray(E.annotations)&&E.annotations.forEach(_=>y.push(_))}),y}),x=l(()=>[{value:"position",label:s.sortPosition||"頁面位置"},{value:"created-desc",label:s.sortCreatedDesc||"最新時間優先"},{value:"created-asc",label:s.sortCreatedAsc||"最早時間優先"}]);function k(){let y=new Map;m.value.forEach(_=>{let N=(_.sectionPath||"").trim(),H=y.get(N);H?H.push(_):y.set(N,[_])});let E=Array.from(y.entries()).map(([_,N])=>({sectionPath:_,annotations:N.slice().sort((H,D)=>{let ue=se(H.sentencePos,D.sentencePos);return ue!==0?ue:(H.createdAt||0)-(D.createdAt||0)})}));return E.sort((_,N)=>{let H=_.annotations[0],D=N.annotations[0],ue=se(H==null?void 0:H.sentencePos,D==null?void 0:D.sentencePos);return ue!==0?ue:(_.sectionPath||"").localeCompare(N.sectionPath||"")}),E}function T(y){let E=m.value.slice().sort((N,H)=>{let D=(N.createdAt||0)-(H.createdAt||0);return y==="asc"?D:-D}),_=[];return E.forEach(N=>{let H=(N.sectionPath||"").trim(),D=_[_.length-1];!D||D.sectionPath!==H?_.push({sectionPath:H,annotations:[N]}):D.annotations.push(N)}),_}let A=l(()=>u.value==="created-desc"?T("desc"):u.value==="created-asc"?T("asc"):k());function b(y){if(!y)return"";let E=y.trim();return E.length<=60?E:`${E.slice(0,57)}…`}function R(y){if(!y)return"";try{return new Date(y).toLocaleString()}catch(E){return""}}function C(y,E){var _;(_=r.onEditAnnotation)==null||_.call(r,y,E)}function L(y,E){!r.onDeleteAnnotation||!window.confirm(s.deleteConfirm)||(p.value=y,Promise.resolve(r.onDeleteAnnotation(y,E)).catch(N=>{console.error("[ReviewTool] Failed to delete annotation",N),mw&&mw.notify&&mw.notify(a.convByVar({hant:"刪除批註時發生錯誤。",hans:"删除批注时发生错误。"}),{type:"error",title:"[ReviewTool]"})}).finally(()=>{p.value=null}))}function v(){!r.onClearAllAnnotations||h.value||!window.confirm(s.clearAllConfirm)||(c.value=!0,Promise.resolve(r.onClearAllAnnotations()).then(E=>{let _=!!E;mw&&mw.notify&&mw.notify(_?s.clearAllDone:s.clearAllNothing,{tag:"review-tool"})}).catch(E=>{console.error("[ReviewTool] Failed to clear annotations",E),mw&&mw.notify&&mw.notify(s.clearAllError,{type:"error",title:"[ReviewTool]"})}).finally(()=>{c.value=!1}))}function w(){if(!h.value)try{let y={exportedAt:Date.now(),groups:g.value},E=JSON.stringify(y,null,2),_=new Blob([E],{type:"application/json;charset=utf-8"}),N=`review-tool-annotations-${new Date().toISOString().replace(/[:.]/g,"")}.json`,H=URL.createObjectURL(_),D=document.createElement("a");D.href=H,D.download=N,document.body.appendChild(D),D.click(),D.remove(),URL.revokeObjectURL(H),mw&&mw.notify&&mw.notify(s.exportDone,{tag:"review-tool"})}catch(y){console.error("[ReviewTool] Failed to export annotations",y),mw&&mw.notify&&mw.notify(s.exportError,{type:"error",title:"[ReviewTool]"})}}function I(y){y||P()}function P(){d.value=!1,setTimeout(()=>{var y;B(),(y=r.onClosed)==null||y.call(r)},200)}let V={buildI18n:n,VueRuntime:o,ref:i,computed:l,props:r,i18n:s,open:d,groups:g,deletingAnnotationId:p,clearingAll:c,sortMethod:u,canClearAll:f,isEmpty:h,flattenedAnnotations:m,sortingOptions:x,buildPositionSortedGroups:k,buildTimeSortedGroups:T,sortedGroups:A,quotePreview:b,formatTimestamp:R,handleEdit:C,handleDelete:L,handleClearAll:v,handleExport:w,onUpdateOpen:I,closeDialog:P};return Object.defineProperty(V,"__isScriptSetup",{enumerable:!1,value:!0}),V}});function Sn(e,t,n,o,i,l){let{toDisplayString:r,openBlock:s,createElementBlock:d,createCommentVNode:g,renderList:p,Fragment:c,createElementVNode:u,createTextVNode:f,resolveComponent:h,withModifiers:m,withCtx:x,createVNode:k,createBlock:T}=window.Vue,A=h("cdx-button"),b=h("cdx-select"),R=h("cdx-dialog");return s(),T(R,{open:o.open,"onUpdate:open":[t[1]||(t[1]=C=>o.open=C),o.onUpdateOpen],title:o.i18n.title,"use-close-button":!0,"default-action":{label:o.i18n.close},onDefault:o.closeDialog,class:"review-tool-dialog review-tool-annotation-viewer-dialog"},{footer:x(()=>[u("div",{class:"review-tool-annotation-viewer__footer"},[u("div",{class:"review-tool-annotation-viewer__footer-left"},[k(b,{selected:o.sortMethod,"onUpdate:selected":t[0]||(t[0]=C=>o.sortMethod=C),"menu-items":o.sortingOptions,disabled:o.isEmpty,"aria-label":o.i18n.sortLabel,class:"review-tool-annotation-viewer__sort-select"},null,8,["selected","menu-items","disabled","aria-label"])]),u("div",{class:"review-tool-annotation-viewer__footer-actions"},[o.isEmpty?g("v-if",!0):(s(),T(A,{key:0,weight:"quiet",onClick:m(o.handleExport,["prevent"])},{default:x(()=>[f(r(o.i18n.export),1)]),_:1})),o.canClearAll&&!o.isEmpty?(s(),T(A,{key:1,action:"destructive",weight:"quiet",disabled:o.clearingAll,onClick:m(o.handleClearAll,["prevent"])},{default:x(()=>[f(r(o.i18n.clearAll),1)]),_:1},8,["disabled"])):g("v-if",!0)])])]),default:x(()=>[o.isEmpty?(s(),d("div",{key:0,class:"review-tool-annotation-viewer__empty"},r(o.i18n.empty),1)):(s(),d("div",{key:1,class:"review-tool-annotation-viewer__list"},[(s(!0),d(c,null,p(o.sortedGroups,C=>(s(),d("div",{key:C.sectionPath||"default",class:"review-tool-annotation-viewer__section"},[u("h4",{class:"review-tool-annotation-viewer__section-title"},r(C.sectionPath||o.i18n.sectionFallback),1),u("ul",{class:"review-tool-annotation-viewer__items"},[(s(!0),d(c,null,p(C.annotations,L=>(s(),d("li",{key:L.id,class:"review-tool-annotation-viewer__item"},[u("div",{class:"review-tool-annotation-viewer__quote"},"“"+r(o.quotePreview(L.sentenceText))+"”",1),u("div",{class:"review-tool-annotation-viewer__opinion"},r(L.opinion),1),u("div",{class:"review-tool-annotation-viewer__meta"},r(L.createdBy)+" · "+r(o.formatTimestamp(L.createdAt)),1),u("div",{class:"review-tool-annotation-viewer__actions"},[k(A,{size:"small",weight:"quiet",onClick:m(v=>o.handleEdit(L.id,C.sectionPath),["prevent"])},{default:x(()=>[f(r(o.i18n.edit),1)]),_:1},8,["onClick"]),k(A,{size:"small",weight:"quiet",action:"destructive",disabled:o.deletingAnnotationId===L.id,onClick:m(v=>o.handleDelete(L.id,C.sectionPath),["prevent"])},{default:x(()=>[f(r(o.i18n.delete),1)]),_:1},8,["disabled","onClick"])])]))),128))])]))),128))]))]),_:1},8,["open","title","default-action"])}Rt.render=Sn;var _t=Rt;var J=null,O=null;function Oe(){return!!J}function We(){J&&(J.open=!1,setTimeout(()=>B(),200),J=null,O=null)}function $e(e){J&&(J.groups=e)}function Bt(e){O={groups:e.groups||[],onEditAnnotation:e.onEditAnnotation,onDeleteAnnotation:e.onDeleteAnnotation,onClearAllAnnotations:e.onClearAllAnnotations},q()&&B(),j().then(({Vue:t,Codex:n})=>{let o=t.createMwApp({render(){return t.h(_t,{initialGroups:(O==null?void 0:O.groups)||[],onEditAnnotation:O==null?void 0:O.onEditAnnotation,onDeleteAnnotation:O==null?void 0:O.onDeleteAnnotation,onClearAllAnnotations:O==null?void 0:O.onClearAllAnnotations,onClosed:()=>{J=null,O=null}})}});X(o,n),J=z(o)}).catch(t=>{console.error("[ReviewTool] Failed to open annotation viewer dialog",t),mw&&mw.notify&&mw.notify(a.convByVar({hant:"無法開啟批註列表。",hans:"无法开启批注列表。"}),{type:"error",title:"[ReviewTool]"})})}var S=null,M="review-tool-annotation-ui",F="sentence",Vn="floating-button",Y=null,Ce=null,qe=null,te=null,Ge=!1,ne=!1,ce=null,Rn=180,_n=120,ee=null,W=null,de=new Map,Ue="__article__",Dt="ca-reviewtool-toggle",Ht=e=>In(e),It=e=>Mn(e),Mt=e=>On(e),Ft=e=>Wn(e);function Bn(e){if(!e)return"";let t=e.cloneNode(!0);try{t.querySelectorAll("sup.reference, sup.mw-ref, .reference, .mw-ref, .citation, .ref, .reference-text, .qeec-ref-tag-copy-btn").forEach(o=>o.remove()),t.querySelectorAll("[data-reference], [data-ref], .reference-note, .qeec-ref-tag-copy-btn").forEach(o=>o.remove())}catch(o){throw console.error("[ReviewTool][getCleanTextFromElement] failed to remove decoration nodes",o),o}return(t.textContent||"").replace(/Copy permalink/g,"").replace(/\s+/g," ").trim()}function Dn(e){try{e.querySelectorAll("sup.reference, sup.mw-ref, .reference, .mw-ref, .citation, .ref, .reference-text, .qeec-ref-tag-copy-btn, style, ipe-quick-edit").forEach(t=>t.remove()),e.querySelectorAll("[data-reference], [data-ref], .reference-note, .qeec-ref-tag-copy-btn").forEach(t=>t.remove())}catch(t){throw console.error("[ReviewTool][removeDecorationsFromContainer] failed",t),t}}function Pn(e){if(!e)return"";let t=e.cloneContents(),n=document.createElement("div");n.appendChild(t),Dn(n);let o=n.textContent||"";return o=o.replace(/Copy permalink/g,""),o.replace(/\s+/g," ").trim()}function Ln(e){if(!e)return"";let t=e.replace(/\[\s*\d+\s*\]/g,"");return t=t.replace(/[\u00B9\u00B2\u00B3\u2070-\u2079]+/g,""),t.replace(/\s+/g," ").trim()}function Nn(e,t,n,o,i=!1){Ot(),Y=t,Ce=n,qe=o,te=e,Ge=i,document.addEventListener("selectionchange",Se),document.addEventListener("mouseup",It),document.addEventListener("mousedown",Ht),document.addEventListener("touchstart",Mt,{passive:!0}),document.addEventListener("touchend",Ft)}function Ot(){document.removeEventListener("selectionchange",Se),document.removeEventListener("mouseup",It),document.removeEventListener("mousedown",Ht),document.removeEventListener("touchstart",Mt),document.removeEventListener("touchend",Ft),ee&&(clearTimeout(ee),ee=null),W&&(clearTimeout(W),W=null),Z(),document.documentElement.classList.remove("rt-selecting"),Y=null,Ce=null,qe=null,te=null,Ge=!1}function Pt(e){if(!e||!Y)return!1;let t=null;if(e.nodeType===Node.TEXT_NODE?t=e.parentElement:e instanceof Element&&(t=e),!t)return!1;if(Y===t||Y.contains(t))return!0;if(!Ce)return Ge?!1:(Y.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING)!==0;let n=(Y.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING)!==0,o=(t.compareDocumentPosition(Ce)&Node.DOCUMENT_POSITION_FOLLOWING)!==0;return n&&o}function Hn(){let e=document.getSelection();if(!e||e.isCollapsed)return null;let t=e.getRangeAt(0);if(!Y)return null;let n=Pt(t.startContainer),o=Pt(t.endContainer);return!n||!o?null:t}function In(e){let t=e==null?void 0:e.target;t&&S&&(t===S||S.contains(t))||(e&&(ce={x:e.clientX,y:e.clientY}),ne=!0,document.documentElement.classList.add("rt-selecting"),Z())}function Mn(e){let t=e==null?void 0:e.target;if(t&&S&&(t===S||S.contains(t))){ne=!1,ce=null,document.documentElement.classList.remove("rt-selecting");return}ne=!1,ce=null,document.documentElement.classList.remove("rt-selecting"),Se()}function Fn(e){if(!ce)return!1;let t=Math.abs(e.clientX-ce.x),n=Math.abs(e.clientY-ce.y);return t>3||n>3}function On(e){let t=e==null?void 0:e.target;t&&S&&(t===S||S.contains(t))||(ne=!0,document.documentElement.classList.add("rt-selecting"),Z())}function Wn(e){let t=e==null?void 0:e.target;if(t&&S&&(t===S||S.contains(t))){ne=!1,document.documentElement.classList.remove("rt-selecting");return}ne=!1,document.documentElement.classList.remove("rt-selecting"),Se()}function Se(){ne||(ee&&(clearTimeout(ee),ee=null),ee=window.setTimeout(()=>{let e=Hn();if(!e){Z();return}let t=e.getBoundingClientRect(),n=Math.max(40,Math.min(window.innerWidth-40,t.left+t.width/2)),o=Math.max(8,t.top+window.scrollY-8),i=e.cloneRange();$t(n+window.scrollX,o,()=>{let l=Pn(e);if(!l){Z();return}if(te){Z();let r=document.getSelection();r&&r.removeAllRanges();let s=Wt(e?e.startContainer:null),d=je(e?e.startContainer:null);Ve(te,null,s,{sentenceText:l,selectionRange:i,sentencePos:d})}})},_n))}function Lt(e){let t=e;for(;t&&t!==document.body;){if(t instanceof Element&&t.classList.contains(F))return t;t=t.parentNode}return null}function je(e){let t=e?e instanceof Element&&e.classList.contains(F)?e:Lt(e):null;return t&&ht(t)||""}function $n(e){if(!e)return null;if(e.previousSibling){let t=e.previousSibling;for(;t&&t.lastChild;)t=t.lastChild;return t}return e.parentNode}function Un(e){let t=e;for(;t;){if(t instanceof Element){let n=t,o=(n.tagName||"").toLowerCase();if(["h1","h2","h3","h4","h5","h6"].includes(o)||n.classList&&n.classList.contains("mw-heading"))return n}t=t.parentNode}return null}function qn(e){if(!e)return{level:null,title:null};let t=(e.tagName||"").toLowerCase();if(["h1","h2","h3","h4","h5","h6"].includes(t)){let i=parseInt(t.charAt(1),10),l=U(e)||null;return{level:i,title:l}}let n=e.querySelector("h1,h2,h3,h4,h5,h6");if(n){let i=parseInt((n.tagName||"").charAt(1),10),l=U(e)||U(n)||null;return{level:i,title:l}}return{level:null,title:U(e)}}function Wt(e){let t=a.articleTitle||a.convByVar({hant:"導言",hans:"导言"});if(!e)return t;let n=e;if(n.nodeType===Node.TEXT_NODE&&(n=n.parentNode),!n)return t;let o=new Map,i=n;for(;i&&(i=$n(i),!!i);){let r=Un(i);if(!r)continue;let s=qn(r);if(!(!s.title||s.level===null)&&s.level!==1&&!o.has(s.level)&&(o.set(s.level,s.title),s.level===2))break}if(o.size===0)return t;let l=[];for(let r=2;r<=6;r++){let s=o.get(r);s&&l.push(s)}return l.join("—")}function $t(e,t,n){S?S.onclick=o=>{o.stopPropagation(),o.preventDefault(),n()}:(S=document.createElement("button"),S.className=`${M} ${Vn}`,S.textContent=a.convByVar({hant:"批註",hans:"批注"}),S.onclick=o=>{o.stopPropagation(),o.preventDefault(),n()},S.style.pointerEvents="auto",document.body.appendChild(S)),W&&(clearTimeout(W),W=null),S.style.position="absolute",S.style.left=`${e}px`,S.style.top=`${t}px`,S.style.transform="translate(-50%, -100%)",S.style.zIndex="9999",S.style.display="block",S.onmouseenter=()=>{W&&(clearTimeout(W),W=null)},S.onmouseleave=()=>{W&&clearTimeout(W),W=window.setTimeout(()=>Z(),Rn)}}function Z(){W&&(clearTimeout(W),W=null),S&&(S.style.display="none")}function Ut(e,t){function n(c){var h;let u=null;for(c instanceof Element&&(u=c),!u&&c&&c.parentElement&&(u=c.parentElement);u;){let m=u.getAttribute("lang")||u.getAttribute("xml:lang");if(m)return m.toLowerCase();u=u.parentElement}let f=(h=document.documentElement)==null?void 0:h.getAttribute("lang");return f?f.toLowerCase():null}function o(c){return c?!(c.startsWith("zh")||c.startsWith("ja")):!1}function i(c){let u=c?"。!??!….":"。!?…";return new RegExp(`[」』】〗〕\\)\\]\\}\\"'’”〉》]*[${u}]+[」』】〗〕\\)\\]\\}\\"'’”〉》]*`,"g")}function l(c,u){let f=u?"。!?!?;;」』】〗〕\\]]}}\\.":"。!?;;」』】〗〕\\]]}}",h=new RegExp(`(?<=[${f}])\\s*`,"g");return c.split(h).filter(m=>m.trim())}function r(c){if(c.nodeType!==Node.ELEMENT_NODE)return!1;let u=c;if(u.classList.contains(M)||u.hasAttribute("data-gadget")||u.hasAttribute("data-widget"))return!0;let f=["mw-editsection","mw-indicator","navbox","infobox","metadata","noprint","navigation","catlinks","printfooter","mw-jump-link","skin-","vector-","qeec-ref-tag-copy-btn","ipe__in-article-link","ipe-quick-edit","ipe-quick-edit--create-only"];for(let h of f)if(u.className&&(u.classList.contains(h)||typeof u.className=="string"&&u.className.includes(h)))return!0;return!!(u.id&&(u.id.startsWith("mw-")||u.id.startsWith("footer-")||u.id.startsWith("p-")||u.id==="siteSub"||u.id==="contentSub"))}let s=[];if(e&&e.childNodes&&e.childNodes.length>0&&!t)e.childNodes.forEach(c=>{r(c)?console.log("[ReviewTool] Skipping element to preserve other scripts:",c):s.push(c)});else{let c=e.nextSibling;for(;c&&c!==t;)r(c)?console.log("[ReviewTool] Skipping element to preserve other scripts:",c):s.push(c),c=c.nextSibling}let d=0;console.log("[ReviewTool] wrapSectionSentences: processing",s.length,"child nodes");function g(c,u){let f=[];if(!c||!c.trim())return f;let h=i(o(u)),m=0;for(;h.exec(c)!==null;){let x=h.lastIndex;c.slice(m,x).trim()&&f.push({start:m,end:x}),m=x}if(m<c.length&&c.slice(m).trim()&&f.push({start:m,end:c.length}),f.length<=1){let x=[],k=new RegExp(`${i(o(u)).source}|(?:\\r?\\n)+|(?:\\s{2,})`,"g"),T=0;for(;k.exec(c)!==null;){let A=k.lastIndex;c.slice(T,A).trim()&&x.push({start:T,end:A}),T=A}if(T<c.length&&c.slice(T).trim()&&x.push({start:T,end:c.length}),x.length>1)return x}return f}function p(c){let u=o(n(c));function f(v){if(!v||!v.tagName)return!1;let w=v.tagName.toLowerCase();return new Set(["a","span","em","strong","b","i","small","sup","sub","code","cite","abbr","time","mark","var","img","kbd"]).has(w)}if(Array.from(c.childNodes).filter(v=>v.nodeType===Node.ELEMENT_NODE).some(v=>!f(v))){Array.from(c.childNodes).forEach(v=>{if(v.nodeType===Node.TEXT_NODE){let w=v,I=w.nodeValue||"";if(!I.trim())return;let P=g(I,n(w)).map(V=>I.slice(V.start,V.end)).filter(V=>V.trim());if(P.length<=1){let V=document.createElement("span");V.className=`${M} ${F}`,V.setAttribute("data-sentence-index",String(d++)),V.textContent=I,w.parentNode&&w.parentNode.replaceChild(V,w)}else{let V=document.createDocumentFragment();P.forEach(y=>{let E=document.createElement("span");E.className=`${M} ${F}`,E.setAttribute("data-sentence-index",String(d++)),E.textContent=y,V.appendChild(E)}),w.parentNode&&w.parentNode.replaceChild(V,w)}}else v.nodeType===Node.ELEMENT_NODE&&p(v)});return}let x=v=>{if(v.nodeType!==Node.TEXT_NODE)return NodeFilter.FILTER_SKIP;let w=v.parentElement;for(;w&&w!==c;){if(r(w))return NodeFilter.FILTER_REJECT;w=w.parentElement}return NodeFilter.FILTER_ACCEPT},k=document.createTreeWalker(c,NodeFilter.SHOW_TEXT,{acceptNode:x}),T=[],A="",b=k.nextNode();for(;b;){let v=b.nodeValue||"";v&&(T.push({node:b,start:A.length,end:A.length+v.length}),A+=v),b=k.nextNode()}if(!T.length)return;let R=g(A,n(c)),C=[];for(let v of R){let w=null,I=0,P=null,V=0;for(let y of T)if(v.start>=y.start&&v.start<=y.end&&(w=y.node,I=v.start-y.start),v.end>=y.start&&v.end<=y.end&&(P=y.node,V=v.end-y.start),w&&P)break;w&&P&&C.push({startNode:w,startOffset:I,endNode:P,endOffset:V,absStart:v.start,absEnd:v.end})}if(!C.length)return;C.sort((v,w)=>w.absStart-v.absStart);let L=0;for(let v of C)if(!(v.absStart>=v.absEnd))try{if(!v.startNode.isConnected||!v.endNode.isConnected){console.warn("[ReviewTool] mapped nodes not connected, skipping",v);continue}if(!c.contains(v.startNode)||!c.contains(v.endNode)){console.warn("[ReviewTool] mapped nodes no longer in root, skipping",v);continue}let w=document.createRange();w.setStart(v.startNode,v.startOffset),w.setEnd(v.endNode,v.endOffset);let I=w.extractContents(),P=document.createElement("span");P.className=`${M} ${F}`,P.setAttribute("data-sentence-index",String(d++)),P.appendChild(I),w.insertNode(P);let V=w.detach;typeof V=="function"&&V.call(w),L++}catch(w){console.warn("[ReviewTool] range wrapping failed for one range, continuing",w,v)}if(L===0){console.warn("[ReviewTool] no mapped ranges wrapped successfully, performing fallback wrapping for this root");let v=document.createTreeWalker(c,NodeFilter.SHOW_TEXT,{acceptNode:x}),w=v.nextNode();for(;w;){let I=w.nodeValue||"";if(!I.trim()){w=v.nextNode();continue}let P=l(I,u);if(P.length<=1){let V=document.createElement("span");V.className=`${M} ${F}`,V.setAttribute("data-sentence-index",String(d++)),V.textContent=I,w.parentNode&&w.parentNode.replaceChild(V,w)}else{let V=document.createDocumentFragment();P.forEach(y=>{let E=document.createElement("span");E.className=`${M} ${F}`,E.setAttribute("data-sentence-index",String(d++)),E.textContent=y,V.appendChild(E)}),w.parentNode&&w.parentNode.replaceChild(V,w)}w=v.nextNode()}}}s.forEach(c=>{if(c.nodeType===Node.ELEMENT_NODE){let u=c,f=(u.tagName||"").toLowerCase();f==="ul"||f==="ol"||f==="dl"?Array.from(u.children).forEach(m=>{p(m)}):p(u)}else if(c.nodeType===Node.TEXT_NODE){let u=c,f=u.textContent||"";if(!f.trim())return;let h=l(f,o(n(u)));if(h.length<=1){let m=document.createElement("span");m.className=`${M} ${F}`,m.setAttribute("data-sentence-index",String(d++)),m.textContent=f,u.parentNode&&u.parentNode.replaceChild(m,u)}else{let m=document.createDocumentFragment();h.forEach(x=>{let k=document.createElement("span");k.className=`${M} ${F}`,k.setAttribute("data-sentence-index",String(d++)),k.textContent=x,m.appendChild(k)}),u.parentNode&&u.parentNode.replaceChild(m,u)}}});try{Qn(e,t)}catch(c){throw console.error("[ReviewTool] attachSentenceClickHandlers failed",c),c}try{let c=`.${M}.${F}`,u=e.querySelectorAll?e.querySelectorAll(c):document.querySelectorAll(c);console.log("[ReviewTool] wrapSectionSentences: sentence spans found in section:",u.length)}catch(c){throw console.error("[ReviewTool] counting sentence spans failed",c),c}}function Nt(e,t,n,o){if(!e)return;let i=`.${M}.${F}`;function l(){try{return t===null&&e.querySelectorAll?e.querySelectorAll(i).length:Array.from(document.querySelectorAll(i)).filter(c=>e.contains(c)).length}catch(p){return 0}}let r,s=typeof o=="number"?Math.max(0,o):250;Array.isArray(n)?r=n.filter(p=>typeof p=="number"):r=[0,s,s*3,s*6,s*12,s*20],!Array.isArray(n)&&typeof n=="number"&&(r=r.slice(0,Math.max(1,n)));let d=0;function g(){try{Ut(e,t)}catch(c){console.warn("[ReviewTool] ensureWrappedSection wrap failed",c)}let p=l();console.log("[ReviewTool] ensureWrappedSection: attempt",d+1,"found",p),!(p>0)&&(d++,d<r.length&&setTimeout(g,r[d]))}setTimeout(g,r[0])}function Gn(){document.querySelectorAll(`.${M}.${F}`).forEach(e=>{let t=e.parentNode;if(!t)return;let n=document.createDocumentFragment();for(;e.firstChild;)n.appendChild(e.firstChild);t.replaceChild(n,e)}),document.querySelectorAll(".review-tool-annotation-badge").forEach(e=>e.remove()),qt()}function qt(){de.forEach(e=>{try{e.remove()}catch(t){console.error("[ReviewTool] failed to remove inline annotation bubble",t,e)}}),de.clear(),document.querySelectorAll(".review-tool-inline-annotation").forEach(e=>{e.remove()})}function jn(e,t,n,o){let i=document.createElement("span");i.className="review-tool-inline-annotation",i.dataset.annoId=n,i.dataset.sectionPath=t,i.title=o;let l=document.createElement("span");return l.className="review-tool-inline-annotation__icon",l.textContent="💬",l.title=o,l.setAttribute("role","button"),l.tabIndex=0,l.onclick=r=>{r.preventDefault(),r.stopPropagation(),Ve(e,n,t)},l.onkeydown=r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),l.click())},i.appendChild(l),i}function zn(e,t,n,o,i){if(!e){console.warn("[ReviewTool] Cannot insert inline annotation bubble without a selection range.");return}ze(o);let l=jn(t,n,o,i);de.set(o,l);let r=e.cloneRange();r.collapse(!1),r.insertNode(l)}function Xn(e,t){let n=de.get(e);n&&(n.setAttribute("data-opinion",t),n.title=t,n.firstElementChild&&(n.firstElementChild.title=t))}function ze(e){let t=de.get(e);t&&(t.remove(),de.delete(e))}async function Ve(e,t,n,o={}){let i=o.selectionRange?o.selectionRange.cloneRange():null,l=t!==null,r=l&&t?pt(e,t):null,s=l?(r==null?void 0:r.sentenceText)||"":Ln(o.sentenceText||""),d=l&&(r==null?void 0:r.opinion)||"",g=Oe();n=n==="目次"?"序言":n;try{g&&We();let p=await Vt({sectionPath:n,sentenceText:s,initialOpinion:d,mode:l?"edit":"create",allowDelete:l});if(!p||p.action==="cancel")return;if(p.action==="delete"&&l&&t){Ie(e,t)&&ze(t);return}if(p.action==="save")if(l&&t)gt(e,t,{opinion:p.opinion})&&Xn(t,p.opinion);else{let c=o.sentencePos||je(i?i.startContainer:null),u=ut(e,n,s,p.opinion,c);zn(i,e,n,u.id,p.opinion)}}catch(p){console.error("[ReviewTool] Failed to open annotation editor dialog",p)}finally{g&&Gt(e)}}function Qn(e,t){if(!e)return;if(!t){e.querySelectorAll(`.${M}.${F}`).forEach(l=>{l instanceof HTMLElement&&o(l)}),e instanceof HTMLElement&&e.classList.contains(M)&&e.classList.contains(F)&&o(e);return}let n=e.nextSibling;for(;n&&n!==t;){if(n.nodeType===Node.ELEMENT_NODE){let i=n;i.querySelectorAll(`.${M}.${F}`).forEach(l=>{l instanceof HTMLElement&&o(l)}),i instanceof HTMLElement&&i.classList.contains(M)&&i.classList.contains(F)&&o(i)}n=n.nextSibling}function o(i){if(i.dataset.clickAttached)return;i.dataset.clickAttached="1";try{i.dataset._rtHandler="1"}catch(r){}try{i.style.pointerEvents="auto"}catch(r){throw console.error("[ReviewTool] failed to set pointerEvents on sentence span",r,i),r}try{i.style.cursor="pointer"}catch(r){throw console.error("[ReviewTool] failed to set cursor on sentence span",r,i),r}let l=i.style.background;i.addEventListener("mouseenter",()=>{try{i.style.background="rgba(255,235,59,0.18)"}catch(r){throw console.error("[ReviewTool] span mouseenter styling failed",r,i),r}}),i.addEventListener("mouseleave",()=>{try{i.style.background=l||""}catch(r){throw console.error("[ReviewTool] span mouseleave styling failed",r,i),r}}),i.addEventListener("click",r=>{if(Fn(r))return;let s=window.getSelection();if(s&&!s.isCollapsed||(r.stopPropagation(),r.preventDefault(),!te||!qe))return;let d=Bn(i),g=document.createRange();g.selectNodeContents(i);let p=g.cloneRange(),c=window.getSelection();c&&(c.removeAllRanges(),c.addRange(g));let u=i.getBoundingClientRect(),f=Math.max(40,Math.min(window.innerWidth-40,u.left+u.width/2)),h=Math.max(8,u.top+window.scrollY-8);$t(f+window.scrollX,h,()=>{if(te){Z();let m=window.getSelection();m&&m.removeAllRanges();let x=Wt(i),k=je(i);Ve(te,null,x,{sentenceText:d,selectionRange:p,sentencePos:k})}})})}}function Gt(e){if(Oe()){We();return}let t=ae(e);Bt({groups:t,onEditAnnotation:(n,o)=>{Ve(e,n,o)},onDeleteAnnotation:n=>{Ie(e,n)&&(ze(n),$e(ae(e)))},onClearAllAnnotations:()=>{let n=ft(e);return qt(),$e(ae(e)),n}})}function jt(e){document.querySelector("#ca-annotate")||(bt("ca-annotate",a.convByVar({hant:"批註模式",hans:"批注模式"}),a.convByVar({hant:"切換批註模式",hans:"切换批注模式"}),()=>zt(e)),Kn(e),Xt(a.isAnnotationModeActive(Ue),e))}function Kn(e){if(document.querySelector(".review-tool-global-button"))return;let t=document.createElement("button");t.className="review-tool-global-button",t.textContent=a.convByVar({hant:"查看批註",hans:"查看批注"}),t.title=a.convByVar({hant:"查看本頁所有批註",hans:"查看本页所有批注"}),t.style.position="fixed",t.style.bottom="20px",t.style.right="20px",t.style.zIndex="10100",t.style.padding="10px 16px",t.style.backgroundColor="#36c",t.style.color="#fff",t.style.border="none",t.style.borderRadius="4px",t.style.cursor="pointer",t.style.fontSize="14px",t.style.fontWeight="bold",t.style.boxShadow="0 2px 8px rgba(0,0,0,0.2)",t.style.display="none",t.onclick=()=>{try{Gt(a.articleTitle||e)}catch(n){throw console.error("[ReviewTool] failed to open viewer",n),n}},t.onmouseenter=()=>{t.style.backgroundColor="#447ff5"},t.onmouseleave=()=>{t.style.backgroundColor="#36c"},document.body.appendChild(t)}function zt(e){a.toggleAnnotationModeState(Ue);let t=a.isAnnotationModeActive(Ue);if(Xt(t,e),t){document.documentElement.classList.add("review-tool-annotation-mode"),mw&&mw.notify&&mw.notify(a.convByVar({hant:"批註模式已啟用。",hans:"批注模式已启用。"}),{tag:"review-tool"}),console.log(`[ReviewTool] 條目「${a.articleTitle}」批註模式已啟用。`);let n=["#mw-content-text .mw-parser-output","#mw-content-text",".mw-parser-output","#content","#bodyContent"],o=null;for(let s of n){let d=document.querySelector(s);if(d){o=d;break}}if(o?console.log("[ReviewTool] chosen content container:",o.tagName,o.id||"(no id)",o.className||"(no class)"):console.warn("[ReviewTool] could not find a content container with selectors",n),!o){console.warn("[ReviewTool] 未找到主要內容容器,無法啟用批註模式。");return}let i=a.articleTitle||e;Nn(a.articleTitle||e,o,null,i,!0),(Nt||Ut)(o,null,4,220);let r=document.querySelector(".review-tool-global-button");r&&(r.style.display="block")}else{console.log(`[ReviewTool] 條目「${a.articleTitle}」批註模式已停用。`),Ot(),Gn();try{document.documentElement.classList.remove("review-tool-annotation-mode")}catch(n){throw console.error("[ReviewTool] failed to remove annotation mode class",n),n}try{mw&&mw.notify&&mw.notify(a.convByVar({hant:"批註模式已停用。",hans:"批注模式已停用。"}),{tag:"review-tool"})}catch(n){throw console.error("[ReviewTool] mw.notify failed",n),n}try{let n=document.querySelector(".review-tool-global-button");n&&(n.style.display="none")}catch(n){throw console.error("[ReviewTool] failed to hide global viewer button",n),n}}}function Jn(e){return a.convByVar({hant:e?"關閉批註模式":"啟用批註模式",hans:e?"关闭批注模式":"开启批注模式"})}function Xt(e,t){let n=document.getElementById("ca-annotate");if(n){let i=n.querySelector("a > span");i&&i instanceof HTMLElement&&(i.style.fontWeight=e?"bold":"normal"),n.classList.toggle("selected",e)}xt(Dt,Jn(e),()=>{zt(t)});let o=document.getElementById(Dt);o&&o.classList.toggle("selected",e)}function Yn(e){if(e)try{let t=document.createElement("style");t.appendChild(document.createTextNode(e)),document.head.appendChild(t)}catch(t){let n=document.createElement("div");n.innerHTML=`<style>${e}</style>`,document.head.appendChild(n.firstChild)}}function Zn(){typeof document!="undefined"&&Yn(Ke);let e=mw.config.get("wgNamespaceNumber"),t=mw.config.get("wgPageName"),n=[0,1],o=["Wikipedia:同行评审","Wikipedia:優良條目評選","Wikipedia:典范条目评选","Wikipedia:特色列表评选","User:SuperGrey/gadgets/ReviewTool/TestPage","User_talk:SuperGrey/gadgets/ReviewTool/TestPage"];if(!n.includes(e)&&!o.some(i=>t.startsWith(i))){console.log("[ReviewTool] 不是目標頁面,小工具終止。");return}a.initHanAssist().then(()=>{e===0||t==="User:SuperGrey/gadgets/ReviewTool/TestPage"?(a.articleTitle=t,mw.hook("wikipage.content").add(function(){jt(t)})):mw.hook("wikipage.content").add(function(){Et(e,t)})})}Zn();})();
// </nowiki>