2023年政策修订增补工作正在进行中,欢迎参与!
User:BearBin/js/HistoryViewer.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/HistoryViewer.js?_=1}-
var _addText = '{{Documentation|content=* 工具介绍见[[User:BearBin/js#HistoryViewer]]。\n* 源代码见[https://github.com/BearBin1215/MoegirlPedia/blob/master/src/gadgets/HistoryViewer GitHub]。}}';
// <nowiki>
(()=>{"use strict";var e={411:e=>{e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var r="",n=void 0!==t[5];return t[4]&&(r+="@supports (".concat(t[4],") {")),t[2]&&(r+="@media ".concat(t[2]," {")),n&&(r+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),r+=e(t),n&&(r+="}"),t[2]&&(r+="}"),t[4]&&(r+="}"),r})).join("")},t.i=function(e,r,n,o,a){"string"==typeof e&&(e=[[null,e,void 0]]);var i={};if(n)for(var s=0;s<this.length;s++){var c=this[s][0];null!=c&&(i[c]=!0)}for(var p=0;p<e.length;p++){var l=[].concat(e[p]);n&&i[l[0]]||(void 0!==a&&(void 0===l[5]||(l[1]="@layer".concat(l[5].length>0?" ".concat(l[5]):""," {").concat(l[1],"}")),l[5]=a),r&&(l[2]?(l[1]="@media ".concat(l[2]," {").concat(l[1],"}"),l[2]=r):l[2]=r),o&&(l[4]?(l[1]="@supports (".concat(l[4],") {").concat(l[1],"}"),l[4]=o):l[4]="".concat(o)),t.push(l))}},t}},922:e=>{e.exports=function(e){return e[1]}},393:(e,t,r)=>{r.d(t,{A:()=>s});var n=r(922),o=r.n(n),a=r(411),i=r.n(a)()(o());i.push([e.id,"#pagehistory li.after input[name=oldid],#pagehistory li.before input[name=diff],#pagehistory li.between input[type=radio]{visibility:unset}.bearbintool-historyviewer .userlink-avatar-small{max-height:1.5em;max-width:1.5em}",""]);const s=i},960:e=>{var t=[];function r(e){for(var r=-1,n=0;n<t.length;n++)if(t[n].identifier===e){r=n;break}return r}function n(e,n){for(var a={},i=[],s=0;s<e.length;s++){var c=e[s],p=n.base?c[0]+n.base:c[0],l=a[p]||0,d="".concat(p," ").concat(l);a[p]=l+1;var u=r(d),f={css:c[1],media:c[2],sourceMap:c[3],supports:c[4],layer:c[5]};if(-1!==u)t[u].references++,t[u].updater(f);else{var m=o(f,n);n.byIndex=s,t.splice(s,0,{identifier:d,updater:m,references:1})}i.push(d)}return i}function o(e,t){var r=t.domAPI(t);r.update(e);return function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap&&t.supports===e.supports&&t.layer===e.layer)return;r.update(e=t)}else r.remove()}}e.exports=function(e,o){var a=n(e=e||[],o=o||{});return function(e){e=e||[];for(var i=0;i<a.length;i++){var s=r(a[i]);t[s].references--}for(var c=n(e,o),p=0;p<a.length;p++){var l=r(a[p]);0===t[l].references&&(t[l].updater(),t.splice(l,1))}a=c}}},443:e=>{var t={};e.exports=function(e,r){var n=function(e){if(void 0===t[e]){var r=document.querySelector(e);if(window.HTMLIFrameElement&&r instanceof window.HTMLIFrameElement)try{r=r.contentDocument.head}catch(e){r=null}t[e]=r}return t[e]}(e);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");n.appendChild(r)}},628:e=>{e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},120:(e,t,r)=>{e.exports=function(e){var t=r.nc;t&&e.setAttribute("nonce",t)}},81:e=>{e.exports=function(e){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var t=e.insertStyleElement(e);return{update:function(r){!function(e,t,r){var n="";r.supports&&(n+="@supports (".concat(r.supports,") {")),r.media&&(n+="@media ".concat(r.media," {"));var o=void 0!==r.layer;o&&(n+="@layer".concat(r.layer.length>0?" ".concat(r.layer):""," {")),n+=r.css,o&&(n+="}"),r.media&&(n+="}"),r.supports&&(n+="}");var a=r.sourceMap;a&&"undefined"!=typeof btoa&&(n+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(a))))," */")),t.styleTagTransform(n,e,t.options)}(t,e,r)},remove:function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(t)}}}},849:e=>{e.exports=function(e,t){if(t.styleSheet)t.styleSheet.cssText=e;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(e))}}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={id:n,exports:{}};return e[n](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.nc=void 0,(()=>{var e={};r.r(e),r.d(e,{exclude:()=>A,extract:()=>w,parse:()=>b,parseUrl:()=>j,pick:()=>S,stringify:()=>x,stringifyUrl:()=>k});const t="%[a-f0-9]{2}",n=new RegExp("("+t+")|([^%]+?)","gi"),o=new RegExp("("+t+")+","gi");function a(e,t){try{return[decodeURIComponent(e.join(""))]}catch{}if(1===e.length)return e;t=t||1;const r=e.slice(0,t),n=e.slice(t);return Array.prototype.concat.call([],a(r),a(n))}function i(e){try{return decodeURIComponent(e)}catch{let t=e.match(n)||[];for(let r=1;r<t.length;r++)t=(e=a(t,r).join("")).match(n)||[];return e}}function s(e){if("string"!=typeof e)throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof e+"`");try{return decodeURIComponent(e)}catch{return function(e){const t={"%FE%FF":"��","%FF%FE":"��"};let r=o.exec(e);for(;r;){try{t[r[0]]=decodeURIComponent(r[0])}catch{const e=i(r[0]);e!==r[0]&&(t[r[0]]=e)}r=o.exec(e)}t["%C2"]="�";const n=Object.keys(t);for(const r of n)e=e.replace(new RegExp(r,"g"),t[r]);return e}(e)}}function c(e,t){if("string"!=typeof e||"string"!=typeof t)throw new TypeError("Expected the arguments to be of type `string`");if(""===e||""===t)return[];const r=e.indexOf(t);return-1===r?[]:[e.slice(0,r),e.slice(r+t.length)]}function p(e,t){const r={};if(Array.isArray(t))for(const n of t){const t=Object.getOwnPropertyDescriptor(e,n);t?.enumerable&&Object.defineProperty(r,n,t)}else for(const n of Reflect.ownKeys(e)){const o=Object.getOwnPropertyDescriptor(e,n);if(o.enumerable){t(n,e[n],e)&&Object.defineProperty(r,n,o)}}return r}const l=e=>null==e,d=e=>encodeURIComponent(e).replace(/[!'()*]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),u=Symbol("encodeFragmentIdentifier");function f(e){if("string"!=typeof e||1!==e.length)throw new TypeError("arrayFormatSeparator must be single character string")}function m(e,t){return t.encode?t.strict?d(e):encodeURIComponent(e):e}function y(e,t){return t.decode?s(e):e}function g(e){return Array.isArray(e)?e.sort():"object"==typeof e?g(Object.keys(e)).sort(((e,t)=>Number(e)-Number(t))).map((t=>e[t])):e}function h(e){const t=e.indexOf("#");return-1!==t&&(e=e.slice(0,t)),e}function v(e,t){return t.parseNumbers&&!Number.isNaN(Number(e))&&"string"==typeof e&&""!==e.trim()?e=Number(e):!t.parseBooleans||null===e||"true"!==e.toLowerCase()&&"false"!==e.toLowerCase()||(e="true"===e.toLowerCase()),e}function w(e){const t=(e=h(e)).indexOf("?");return-1===t?"":e.slice(t+1)}function b(e,t){f((t={decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1,...t}).arrayFormatSeparator);const r=function(e){let t;switch(e.arrayFormat){case"index":return(e,r,n)=>{t=/\[(\d*)]$/.exec(e),e=e.replace(/\[\d*]$/,""),t?(void 0===n[e]&&(n[e]={}),n[e][t[1]]=r):n[e]=r};case"bracket":return(e,r,n)=>{t=/(\[])$/.exec(e),e=e.replace(/\[]$/,""),t?void 0!==n[e]?n[e]=[...n[e],r]:n[e]=[r]:n[e]=r};case"colon-list-separator":return(e,r,n)=>{t=/(:list)$/.exec(e),e=e.replace(/:list$/,""),t?void 0!==n[e]?n[e]=[...n[e],r]:n[e]=[r]:n[e]=r};case"comma":case"separator":return(t,r,n)=>{const o="string"==typeof r&&r.includes(e.arrayFormatSeparator),a="string"==typeof r&&!o&&y(r,e).includes(e.arrayFormatSeparator);r=a?y(r,e):r;const i=o||a?r.split(e.arrayFormatSeparator).map((t=>y(t,e))):null===r?r:y(r,e);n[t]=i};case"bracket-separator":return(t,r,n)=>{const o=/(\[])$/.test(t);if(t=t.replace(/\[]$/,""),!o)return void(n[t]=r?y(r,e):r);const a=null===r?[]:r.split(e.arrayFormatSeparator).map((t=>y(t,e)));void 0!==n[t]?n[t]=[...n[t],...a]:n[t]=a};default:return(e,t,r)=>{void 0!==r[e]?r[e]=[...[r[e]].flat(),t]:r[e]=t}}}(t),n=Object.create(null);if("string"!=typeof e)return n;if(!(e=e.trim().replace(/^[?#&]/,"")))return n;for(const o of e.split("&")){if(""===o)continue;const e=t.decode?o.replace(/\+/g," "):o;let[a,i]=c(e,"=");void 0===a&&(a=e),i=void 0===i?null:["comma","separator","bracket-separator"].includes(t.arrayFormat)?i:y(i,t),r(y(a,t),i,n)}for(const[e,r]of Object.entries(n))if("object"==typeof r&&null!==r)for(const[e,n]of Object.entries(r))r[e]=v(n,t);else n[e]=v(r,t);return!1===t.sort?n:(!0===t.sort?Object.keys(n).sort():Object.keys(n).sort(t.sort)).reduce(((e,t)=>{const r=n[t];return e[t]=Boolean(r)&&"object"==typeof r&&!Array.isArray(r)?g(r):r,e}),Object.create(null))}function x(e,t){if(!e)return"";f((t={encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:",",...t}).arrayFormatSeparator);const r=r=>t.skipNull&&l(e[r])||t.skipEmptyString&&""===e[r],n=function(e){switch(e.arrayFormat){case"index":return t=>(r,n)=>{const o=r.length;return void 0===n||e.skipNull&&null===n||e.skipEmptyString&&""===n?r:null===n?[...r,[m(t,e),"[",o,"]"].join("")]:[...r,[m(t,e),"[",m(o,e),"]=",m(n,e)].join("")]};case"bracket":return t=>(r,n)=>void 0===n||e.skipNull&&null===n||e.skipEmptyString&&""===n?r:null===n?[...r,[m(t,e),"[]"].join("")]:[...r,[m(t,e),"[]=",m(n,e)].join("")];case"colon-list-separator":return t=>(r,n)=>void 0===n||e.skipNull&&null===n||e.skipEmptyString&&""===n?r:null===n?[...r,[m(t,e),":list="].join("")]:[...r,[m(t,e),":list=",m(n,e)].join("")];case"comma":case"separator":case"bracket-separator":{const t="bracket-separator"===e.arrayFormat?"[]=":"=";return r=>(n,o)=>void 0===o||e.skipNull&&null===o||e.skipEmptyString&&""===o?n:(o=null===o?"":o,0===n.length?[[m(r,e),t,m(o,e)].join("")]:[[n,m(o,e)].join(e.arrayFormatSeparator)])}default:return t=>(r,n)=>void 0===n||e.skipNull&&null===n||e.skipEmptyString&&""===n?r:null===n?[...r,m(t,e)]:[...r,[m(t,e),"=",m(n,e)].join("")]}}(t),o={};for(const[t,n]of Object.entries(e))r(t)||(o[t]=n);const a=Object.keys(o);return!1!==t.sort&&a.sort(t.sort),a.map((r=>{const o=e[r];return void 0===o?"":null===o?m(r,t):Array.isArray(o)?0===o.length&&"bracket-separator"===t.arrayFormat?m(r,t)+"[]":o.reduce(n(r),[]).join("&"):m(r,t)+"="+m(o,t)})).filter((e=>e.length>0)).join("&")}function j(e,t){t={decode:!0,...t};let[r,n]=c(e,"#");return void 0===r&&(r=e),{url:r?.split("?")?.[0]??"",query:b(w(e),t),...t&&t.parseFragmentIdentifier&&n?{fragmentIdentifier:y(n,t)}:{}}}function k(e,t){t={encode:!0,strict:!0,[u]:!0,...t};const r=h(e.url).split("?")[0]||"";let n=x({...b(w(e.url),{sort:!1}),...e.query},t);n&&(n=`?${n}`);let o=function(e){let t="";const r=e.indexOf("#");return-1!==r&&(t=e.slice(r)),t}(e.url);if(e.fragmentIdentifier){const n=new URL(r);n.hash=e.fragmentIdentifier,o=t[u]?n.hash:`#${e.fragmentIdentifier}`}return`${r}${n}${o}`}function S(e,t,r){r={parseFragmentIdentifier:!0,[u]:!1,...r};const{url:n,query:o,fragmentIdentifier:a}=j(e,r);return k({url:n,query:p(o,t),fragmentIdentifier:a},r)}function A(e,t,r){return S(e,Array.isArray(t)?e=>!t.includes(e):(e,r)=>!t(e,r),r)}const F=e;function O(e,t=!1,r,n){const o=$(`<td colspan="${e?2:1}" class="diff-otitle" />`),a=$(`<td colspan="${e?2:1}" class="diff-ntitle" />`);Array.isArray(r)?o.append(...r):o.append(r||"旧版本"),Array.isArray(n)?a.append(...n):a.append(n||"新版本");const i=$('<tr class="diff-title" />').append(o,a);return $('<table class="diff diff-contentalign-left" data-mw="interface" />').append(e&&'<colgroup><col class="diff-marker"><col class="diff-content"><col class="diff-marker"><col class="diff-content"></colgroup>',$("<tbody />").append(t?i:"",e||'<tr><td colspan="2" class="diff-notice"><div class="mw-diff-empty">(没有差异)</div></td></tr>'))}const N=async e=>{const t=new mw.Api,r=await t.post({action:"query",prop:"revisions",titles:e,rvprop:"content"}),[n]=Object.values(r.query.pages);if("revisions"in n)return n.revisions?.[0]["*"];if("missing"in n)throw"missingtitle"};var C=r(960),E=r.n(C),I=r(81),P=r.n(I),R=r(443),U=r.n(R),T=r(120),M=r.n(T),q=r(628),D=r.n(q),L=r(849),_=r.n(L),B=r(393),H={};H.styleTagTransform=_(),H.setAttributes=M(),H.insert=U().bind(null,"head"),H.domAPI=P(),H.insertStyleElement=D();E()(B.A,H);B.A&&B.A.locals&&B.A.locals;mw.loader.using("mediawiki.api").then((()=>{const{oldid:e,diff:t}=F.parse(location.search),r=$("#mw-content-text>.moderation-notice"),n=new mw.Api,o=mw.config.get("wgPageContentModel"),a={javascript:"js",json:"json",css:"css","sanitized-css":"css",Scribunto:"lua"},i=e=>{e.addClass(`prettyprint lang-${a[o]} linenums`),"function"==typeof window.prettyPrint?window.prettyPrint():mw.loader.load("/index.php?title=MediaWiki:Gadget-code-prettify.js&action=raw&ctype=text/javascript")},s=async e=>(await n.post({action:"parse",...e})).parse.text["*"],c=(e,t)=>$(`<a href="/User:${e}" class="mw-userlink" />`).append($('<span class="userlink-avatar" />').append(`<img class="userlink-avatar-small" src="https://img.moegirl.org.cn/common/avatars/${t}/128.png" />`),`<bdi>${e}</bdi>`),p=e=>$('<span class="mw-usertoollinks" />').append("(",`<a href="/User_talk:${e}" class="mw-usertoollinks-talk">讨论</a>`," | ",`<a href="/Special:用户贡献/${e}" class="mw-usertoollinks-contribs">贡献</a>`,")");if(t&&e){if(!$(".permissions-errors a[href]").text().includes("↺"))return;const r=$('<div class="bearbintool-historyviewer" />'),o=$("<a>加载当前差异</a>");o.on("click",(async a=>{a.preventDefault(),r.text("加载中……");try{const o=await n.get({action:"compare",utf8:!0,fromrev:e,torev:t,prop:["diff","user","parsedcomment","ids","title"]}),{fromtitle:a,fromrevid:i,fromparsedcomment:s,fromuser:l,fromuserid:d,totitle:u,torevid:f,toparsedcomment:m,touser:y,touserid:g}=o.compare,h=$(O(o.compare["*"],!0,[$('<div id="mw-diff-otitle1" />').append($("<strong />").append(`<a href="/index.php?title=${a}&oldid=${i}">版本${i}</a>`,`<span class="mw-diff-edit">(<a href="/index.php?title=${a}action=edit&oldid=${i}">编辑</a>)</span>`)),$('<div id="mw-diff-otitle2" />').append(c(l,d),p(l)),$('<div id="mw-diff-otitle3" />').append(s?`<span class="comment">(${s})</span>`:"")],[$('<div id="mw-diff-ntitle1" />').append($("<strong />").append(`<a href="/index.php?title=${u}&oldid=${f}">版本${f}</a>`,`<span class="mw-diff-edit">(<a href="/index.php?title=${u}&action=edit&oldid=${f}">编辑</a>)</span>`,`<span class="mw-diff-undo">(<a href="/index.php?title=${u}&action=edit&undoafter=${i}&undo=${f}">撤销</a>)</span>`)),$('<div id="mw-diff-ntitle2" />').append(c(y,g),p(y)),$('<div id="mw-diff-ntitle3" />').append(m?`<span class="comment">(${m})</span>`:"")]));r.text("加载成功!您现在可以查看版本差异。因compare api不支持,编辑时间戳和标记(如小编辑、机器人)不会显示。").append(h)}catch(e){r.empty().append(`加载失败:${e}。您可以尝试重新`,o,"。")}try{const t=await s({oldid:e,title:mw.config.get("wgPageName")});$("#mw-content-text").append('<hr class="diff-hr" id="mw-oldid">',`<h2 class="diff-currentversion-title">版本${e}</h2>`,$('<div class="mw-parser-output" />').html(t))}catch(t){$("#mw-content-text").append(`版本${e}解析失败:${t}。`)}})),$("#mw-content-text").append(r.append("或 ",o,"。"))}else if(e){if(!$(".permissions-errors a[href]").text().includes("↺"))return;const t=$('<div class="bearbintool-historyviewer" />'),r=$("<a>加载当前版本</a>");r.on("click",(async n=>{n.preventDefault(),t.text("加载中……");try{const r=await s({oldid:e,title:mw.config.get("wgPageName")});if(o in a){const e=$(r);$("#mw-content-text").append(e),mw.loader.moduleRegistry["ext.gadget.code-prettify"]&&i(e)}else $("#mw-content-text").append($('<div class="mw-parser-output" />').html(r));t.text("加载成功,您现在看到的是最新版本。部分依赖于js的功能(如折叠、tabs模板)可能无法正常工作。")}catch(e){t.empty().append(`加载失败:${e}。您可以尝试重新`,r,"。")}})),$("#mw-content-text").append(t.append("或 ",r,"。"))}else if(r.get(0)&&!r.children('a[href*="Special:Moderation"]').length){const e=$('<div class="history-revert-showcurrent" />'),t=$("<a>加载最新版本</a>");t.on("click",(async r=>{r.preventDefault(),e.text("加载中……");try{const t=await s({page:mw.config.get("wgPageName")});if(o in a){const e=$("#mw-content-text>.mw-code"),r=$(t);e.replaceWith(r),mw.loader.moduleRegistry["ext.gadget.code-prettify"]&&i(r)}else $("#mw-content-text>.mw-parser-output").html(t);e.text("加载成功,您现在看到的是最新版本(部分依赖于js的功能可能无法正常工作)。")}catch(r){e.empty().append(`加载失败:${r}。您可以尝试重新`,t,"。")}})),r.append(e.append("您也可以 ",t,"。"))}else if(document.querySelector('.permissions-errors a[href*="action=edit"]')){const e=$('<div class="history-revert-showcurrent" />'),t=$("<a>查看待审核内容</a>");t.on("click",(async r=>{r.preventDefault(),e.text("加载中……");try{const t=await N(mw.config.get("wgPageName")),r=await s({text:t,title:mw.config.get("wgPageName")});if(o in a){const e=$(r);$("#mw-content-text").append(e),mw.loader.moduleRegistry["ext.gadget.code-prettify"]&&i(e)}else $("#mw-content-text").append($('<div class="mw-parser-output" />').html(r));e.text("加载成功,您现在看到的是最新版本(部分依赖于js的功能可能无法正常工作)。")}catch(r){e.empty().append(`加载失败:${r}。您可以尝试重新`,t,"。")}})),$(".permissions-errors").append(e.append("您也可以",t,"。"))}}))})()})();
// </nowiki>