2023年政策修订增补工作正在进行中,欢迎参与!
User:BearBin/js/userStatus.js
< User:BearBin | js
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
- Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
- Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
- Opera:在“工具→首选项”中清除缓存
- 如果您已登录但该页面出现未登录状态,请尝试在地址栏的地址最后添加代码
?_=1
来访问最新页面。 - 添加代码后的本页地址如下:
-{R|https://moegirl.icu/User:BearBin/js/userStatus.js?_=1}-
var _addText = '{{Documentation|content=* 工具介绍见[[User:BearBin/js#userStatus]]。\n* 源代码见[https://github.com/BearBin1215/MoegirlPedia/blob/master/src/gadgets/userStatus GitHub]。}}';
// <nowiki>
(()=>{"use strict";$((()=>(async()=>{await mw.loader.using(["ext.gadget.LocalObjectStorage"]);const t=new LocalObjectStorage("UserStatus");try{const e={online:'<img class="pt-userstatus-img" src="https://img.moegirl.org.cn/common/9/94/Symbol_support_vote.svg"> <b style="color:green;">在线</b>',busy:'<img class="pt-userstatus-img" src="https://img.moegirl.org.cn/common/c/c5/Symbol_support2_vote.svg"> <b style="color:blue;">忙碌</b>',offline:'<img class="pt-userstatus-img" src="https://img.moegirl.org.cn/common/7/7f/Symbol_oppose_vote.svg"> <b style="color:red;">离线</b>',away:'<img class="pt-userstatus-img" src="https://img.moegirl.org.cn/common/6/6c/Time2wait.svg"> <b style="color:grey;">已离开</b>',sleeping:'<img class="pt-userstatus-img" src="https://img.moegirl.org.cn/common/5/54/Symbol_wait.svg"> <b style="color:purple;">在睡觉</b>',wikibreak:'<img class="pt-userstatus-img" src="https://img.moegirl.org.cn/common/6/61/Symbol_abstain_vote.svg"> <b style="color:brown;">正在放萌百假期</b>',holiday:'<img class="pt-userstatus-img" src="https://img.moegirl.org.cn/common/3/30/Symbol_deferred.svg"> <b style="color:#7B68EE;">处于假期中</b>',_unknown:'<img class="pt-userstatus-img" src="https://img.moegirl.org.cn/common/8/89/Symbol_neutral_vote.svg"> <i style="color:gray;">状态不详</i>'},a=Object.keys(e);mw.loader.addStyleTag(".skin-vector #pt-userstatus { margin-top: 0.75em !important; margin-bottom: 0px !important; } .pt-userstatus-img { width: 25px; } .skin-vector .pt-userstatus-img { margin-top: -0.25em; } .skin-moeskin #pt-userpage-link { display: flex; align-items: center; gap: .1em; @media (max-width: 768px) { #pt-userstatus { display: none; } }"),e.on=e.online,e.off=e.offline,e.break=e.wikibreak,e.sleep=e.sleeping;const i=mw.config.get("wgUserName");if(null===i)return;const o="User:".concat(i,"/Status"),s=(new Date).getTime();let n;try{const a=await t.getItem("localStatus");if(!(mw.config.get("wgPageName")!==o&&"number"==typeof a.timestamp&&a.timestamp>s-6e5&&a.status in e))throw new Error;n=a.status}catch{try{n=(await $.ajax({url:"".concat(mw.config.get("wgServer")).concat(mw.config.get("wgScriptPath"),"/index.php"),type:"GET",data:{title:o,action:"raw"},cache:!1})).trim(),n in e&&await t.setItem("localStatus",{timestamp:s,status:n})}catch{n="_unknown",await t.removeItem("localStatus")}}const r=n in e?e[n]:(()=>{const t=$("<div/>").html(n);return t.find("script, style, link, iframe, frame, object, param, audio, video, base, head, meta, title, body, h1, h2, h3, h4, h5, h6, blockquote, dd, dl, dir, dt, hr, li, ul, ol, pre, a, abbr, br, cite, code, data, em, rb, rp, rt, rtc, ruby, samp, time, tt, var, wbr, area, map, track, applet, embed, noembed, picture, source, canvas, noscript, caption, col, colgroup, table, tbody, thead, tfoot, td, th, tr, button, datalist, fieldset, form, input, label, legend, meter, optgroup, option, output, progress, select, textarea, details, dialog, menu, menuitem, summary, shadow, element, content, slot, template, bgsound, blink, center, command, frameset").remove(),t.find("img").attr("class","pt-userstatus-img"),t.html()})();let l;if("moeskin"===mw.config.get("skin"))l=$('<div id="pt-userstatus" class="search-button-area"><a id="pt-userpage-link" href="javascript:void(0);" dir="auto" title="您的状态"></a></div>'),$("#moe-global-header-inner .user-links").append(l);else l=$('<li id="pt-userstatus"><a id="pt-userpage-link" href="javascript:void(0);" dir="auto" title="您的状态"></a></li>'),$("#pt-userpage").after(l);l.find("#pt-userpage-link").html(r).on("click",(async()=>{await mw.loader.using(["oojs-ui","mediawiki.api"]);const i=new OO.ui.MessageDialog,s=new OO.ui.WindowManager;$("body").append(s.$element),s.addWindows([i]),i.title.$label.html("修改自己的状态");const r=$("<div/>");r.append('<p>修改<a href="'.concat(mw.config.get("wgServer")).concat(mw.config.get("wgScriptPath"),"/").concat(o,'">自己的状态</a>为:</p>'));const c=a.map(((t,a)=>"_unknown"===t?void 0:{data:t,label:"".concat(a),html:e[t]})).filter((t=>!!t)),m=new OO.ui.RadioSelectInputWidget({value:n,options:c.map((t=>{let{data:e,label:a}=t;return{data:e,label:a}}))});m.$element.find(".oo-ui-radioSelectWidget > .oo-ui-radioOptionWidget > .oo-ui-labelElement-label").each(((t,e)=>{$(e).css("overflow","visible").html((c.filter((t=>{let{label:a}=t;return $(e).text()===a}))[0]||{html:$(e).html()}).html)})),r.append(m.$element),r.append('<p>本工具在获取状态信息后有10分钟的缓存,您可以通过直接打开<a href="'.concat(mw.config.get("wgServer")).concat(mw.config.get("wgScriptPath"),"/").concat(o,'">自己的状态页</a>来强制获取最新状态信息。')),i.message.$label.append(r);const g=new OO.ui.ActionWidget({action:"confirm",label:"提交",flags:"primary"}),p=new OO.ui.ActionWidget({action:"cancel",label:"取消",flags:"primary"});return p.$element[0].addEventListener("click",(()=>{s.closeWindow(i)}),{capture:!0}),g.$element[0].addEventListener("click",(async()=>{s.closeWindow(i);const a=new OO.ui.MessageDialog;s.addWindows([a]);const r=new OO.ui.ActionWidget({action:"accept",label:"我知道了",flags:"primary"});r.$element[0].addEventListener("click",(()=>{s.closeWindow(a)}),{capture:!0});try{const i=m.getValue();await(new mw.Api).postWithToken("csrf",{action:"edit",title:o,text:i,summary:"修改状态为 - ".concat(i),tags:"Automation tool",minor:!0}),await t.setItem("localStatus",{timestamp:(new Date).getTime(),status:i}),l.find("#pt-userpage-link").html(e[i]),n=i,a.title.$label.html("状态修改完成!"),a.message.$label.html("<p>你的状态已修改为:".concat(e[i],"</p>"));const r=new OO.ui.ActionWidget({action:"confirm",label:"确定",flags:"primary"});r.$element[0].addEventListener("click",(()=>{s.closeWindow(a)}),{capture:!0}),s.openWindow(a,{actions:[r]})}catch(t){a.title.$label.html("状态修改发生错误……"),a.message.$label.html("错误信息为:".concat(t)),s.openWindow(a,{actions:[r]})}}),{capture:!0}),s.openWindow(i,{actions:[g,p]}),!1})),mw.loader.using(["oojs-ui","mediawiki.api"])}catch(t){sessionStorage.getItem("AnnTools-userstatus-img-Error")!==t.toString()&&(alert("显示用户状态工具发生错误:\n".concat(t)),sessionStorage.setItem("AnnTools-userstatus-img-Error",t))}})()))})();
// </nowiki>