打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Gadget-libLocalObjectStorage.js

MediaWiki界面页面

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

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * !!!     Repository URL: https://github.com/SAPedia/InterfaceCodes     !!!
 * -------------------------------------------------------------------------
 */

/* <nowiki> */

"use strict";(()=>{var j=Object.defineProperty;var $=t=>{throw TypeError(t)};var I=(t,e,n)=>e in t?j(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var O=(t,e,n)=>I(t,typeof e!="symbol"?e+"":e,n),y=(t,e,n)=>e.has(t)||$("Cannot "+n);var o=(t,e,n)=>(y(t,e,"read from private field"),n?n.call(t):e.get(t)),g=(t,e,n)=>e.has(t)?$("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),p=(t,e,n,s)=>(y(t,e,"write to private field"),s?s.call(t,n):e.set(t,n),n);var h=[{type:"undefined",match:t=>typeof t=="undefined",encode:()=>"undefined",decode:()=>{}},{type:"bigint",match:t=>typeof t=="bigint",encode:t=>String(t),decode:t=>BigInt(t)},{type:"date",match:t=>t instanceof Date,encode:t=>t.toISOString(),decode:t=>new Date(t)},{type:"set",match:t=>t instanceof Set,encode:t=>JSON.stringify([...t.values()]),decode:t=>new Set(JSON.parse(t))},{type:"map",match:t=>t instanceof Map,encode:t=>JSON.stringify([...t.entries()]),decode:t=>new Map(JSON.parse(t))},{type:"regexp",match:t=>t instanceof RegExp,encode:t=>String(t),decode:t=>new RegExp(t.slice(1,t.length-1))}],v=[],l,i,c,d,m,u=class u{constructor(e="",{expires:n}={}){g(this,i);g(this,c);g(this,d,e=>{var n,s;return o(this,c)?`${o(u,l)}`+moment().add((n=e==null?void 0:e[0])!=null?n:o(this,c)[0],(s=e==null?void 0:e[1])!=null?s:o(this,c)[1]).valueOf()+"|":""});g(this,m,()=>Object.keys(localStorage).filter(e=>e.startsWith(o(this,i))));if(e==="default")throw new Error(`LocalObjectStorage can't accept prefix "${e}".`);if(e.includes("/"))throw new Error(`LocalObjectStorage can't accept prefix "${e}" including "/".`);if(p(this,i,`AnnTool-localObjectStorage/${(e==null?void 0:e.length)>0?`${e}/`:"default/"}`),n!==void 0){if(!Array.isArray(n)||n.length!==2)throw new Error("LocalObjectStorage can't accept invalid expires option.");p(this,c,n)}}get _keyPrefix(){return o(this,i)}getAllKeys(){return o(this,m).call(this).map(e=>e.replace(o(this,i),""))}get length(){return o(this,m).call(this).length}getItem(e,n){let s=localStorage.getItem(`${o(this,i)}${e}`);if(s===null)return n!=null?n:s;if(s.startsWith(o(u,l))){let r=s.indexOf("|");if(r!==-1)try{let a=+s.slice(o(u,l).length,r),f=o(this,c)?moment().add(o(this,c)[0],o(this,c)[1]).valueOf():Number.MAX_SAFE_INTEGER;if(Date.now()>=a)return console.info(`LocalObjectStorage key "${e}" is expired, removing item...`),this.removeItem(e),n!=null?n:null;if(a>f)return console.warn(`LocalObjectStorage key "${e}" exceeds max expires, removing item...`),this.removeItem(e),n!=null?n:null;s=s.slice(r+1)}catch(a){return console.error(`LocalObjectStorage can't parse expires prefix of key ${e}, removing item...`,a),this.removeItem(e),n!=null?n:null}}else if(o(this,c))return console.warn(`LocalObjectStorage key ${e} is missing expires prefix but the instance has expires option, removing item...`),this.removeItem(e),n!=null?n:null;for(let{type:r,decode:a}of h.concat(u.plugins.transformers.list)){if(r.includes("|")){console.error(`LocalObjectStorage can't accept type name ${r} including "|", skip...`);continue}if(r==="JSON"){console.error(`LocalObjectStorage can't accept type name ${r} from custom transformers, skip...`);continue}if(s.startsWith(`${r}|`))try{return a(s.replace(`${r}|`,""))}catch(f){console.error(`LocalObjectStorage can's transform value of key ${e} to type ${r} and skip...`)}}try{return JSON.parse(s.replace("JSON|",""))}catch(r){console.error(`LocalObjectStorage can's transform value of key ${e} to JSON and return \`undefined\`...`,r);return}}setItem(e,n,{expires:s}={}){for(let{type:r,match:a,encode:f}of h.concat(u.plugins.transformers.list)){if(r.includes("|")){console.error(`LocalObjectStorage can't accept type name ${r} including "|", skip...`);continue}if(r==="JSON"){console.error(`LocalObjectStorage can't accept type name ${r}, skip...`);continue}if(a(n))try{localStorage.setItem(`${o(this,i)}${e}`,`${o(this,d).call(this,s)}${r}|${f(n)}`);return}catch(w){console.error(`LocalObjectStorage can's transform value of key ${e} from type ${r} and skip...`,w)}}try{localStorage.setItem(`${o(this,i)}${e}`,`${o(this,d).call(this,s)}JSON|${JSON.stringify(n)}`)}catch(r){console.error(`LocalObjectStorage can's transform value of key ${e} from JSON and skip...`,r)}}removeItem(e){localStorage.removeItem(`${o(this,i)}${e}`)}clear(){o(this,m).call(this).forEach(e=>{localStorage.removeItem(e)})}key(e){return o(this,m).call(this)[e]}};l=new WeakMap,i=new WeakMap,c=new WeakMap,d=new WeakMap,m=new WeakMap,g(u,l,"__EXPIRES__"),O(u,"plugins",{transformers:{get list(){return v.map(e=>Object.assign(Object.create(null),e))},add:({type:e,match:n,decode:s,encode:r})=>e.includes("|")?(console.error(`LocalObjectStorage can't accept type name "${e}" including "|", skip...`),!1):["JSON"].includes(e)?(console.error(`LocalObjectStorage can't accept type name "${e}" from custom transformers, skip...`),!1):[...h,...u.plugins.transformers.list].some(({type:a})=>a===e)?(console.error(`LocalObjectStorage can't accept duplicated type name "${e}" from custom transformers, skip...`),!1):typeof n!="function"||typeof s!="function"||typeof r!="function"?(console.error(`LocalObjectStorage can't accept broken transformer [ type: "${e}", match: ${typeof n}, decode: ${typeof s}, encode: ${typeof r} ], skip...`),!1):(v.push({type:e,match:n,decode:s,encode:r}),!0)}});var S=u;window.LocalObjectStorage=S;})();

/* </nowiki> */