跳转到内容

MediaWiki:Gadget-LocalObjectStorage.js:修订间差异

来自萌娘共享
代码变动:103d1a56 - feat: rename (#594) by U:AnnAngela, co-authored-by: GH:github-actions[bot]
标签由机器人或全自动脚本执行的操作
标签由机器人或全自动脚本执行的操作
 
第4行: 第4行:
  * -------------------------------------------------------------------------
  * -------------------------------------------------------------------------
  */
  */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/LocalObjectStorage/Gadget-LocalObjectStorage.js|user=[[U:AnnAngela]]|co-authors=GH:github-actions[bot]|longId=103d1a563ea4ccc8ff29fb55c9bcd88329a56eb5|shortId=103d1a56|summary=feat: rename (#594)|body=<nowiki>Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com></nowiki>}}';  
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/LocalObjectStorage/Gadget-LocalObjectStorage.js|user=[[U:AnnAngela]]|co-authors=|longId=c61967347a25491d4253b6b176b667233dcd7900|shortId=c6196734|summary=refactor: use arrow functions for consistency in various gadgets}}';  


/* <pre> */
/* <pre> */


"use strict";var __classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(e,t,a,c,o){if("m"===c)throw new TypeError("Private method is not writable");if("a"===c&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===c?o.call(e,a):o?o.value=a:t.set(e,a),a},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(e,t,a,c){if("a"===a&&!c)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!c:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===a?c:"a"===a?c.call(e):c?c.value:t.get(e)};(()=>{var e,t,a;const c=[{type:"undefined",match:e=>void 0===e,encode:()=>"undefined",decode:()=>{}},{type:"bigint",match:e=>"bigint"==typeof e,encode:e=>`${e}`,decode:e=>BigInt(e)},{type:"date",match:e=>e instanceof Date,encode:e=>e.toISOString(),decode:e=>new Date(e)},{type:"set",match:e=>e instanceof Set,encode:e=>JSON.stringify([...e.values()]),decode:e=>new Set(JSON.parse(e))},{type:"map",match:e=>e instanceof Map,encode:e=>JSON.stringify([...e.entries()]),decode:e=>new Map(JSON.parse(e))},{type:"regexp",match:e=>e instanceof RegExp,encode:e=>`${e}`,decode:e=>new RegExp(e.slice(1,e.length-1))}],o=[];class LocalObjectStorage{constructor(a=""){if(e.add(this),t.set(this,void 0),"default"===a)throw new Error(`LocalObjectStorage can't accept prefix "${a}".`);if(a.includes("/"))throw new Error(`LocalObjectStorage can't accept prefix "${a}" including "/".`);__classPrivateFieldSet(this,t,"AnnTool-localObjectStorage/"+(a?.length>0?`${a}/`:"default/"),"f")}get _keyPrefix(){return __classPrivateFieldGet(this,t,"f")}getAllKeys(){return __classPrivateFieldGet(this,e,"m",a).call(this).map(e=>e.replace(__classPrivateFieldGet(this,t,"f"),""))}get length(){return __classPrivateFieldGet(this,e,"m",a).call(this).length}getItem(e,a){const o=localStorage.getItem(`${__classPrivateFieldGet(this,t,"f")}${e}`);if(null===o)return a||o;for(const{type:t,decode:a}of c.concat(LocalObjectStorage.plugins.transformations.list))if(t.includes("|"))console.error(`LocalObjectStorage can't accept type name "${t}" including "|", skip...`);else if("JSON"!==t){if(o.startsWith(`${t}|`))try{return a(o.replace(`${t}|`,""))}catch(a){console.error(`LocalObjectStorage can's transform value of key "${e}" to type "${t}" and skip...`)}}else console.error(`LocalObjectStorage can't accept type name "${t}", skip...`);try{return JSON.parse(o.replace("JSON|",""))}catch(t){return void console.error(`LocalObjectStorage can's transform value of key "${e}" to JSON and return \`undefined\`...`,t)}}setItem(e,a){for(const{type:o,match:r,encode:n}of c.concat(LocalObjectStorage.plugins.transformations.list))if(o.includes("|"))console.error(`LocalObjectStorage can't accept type name "${o}" including "|", skip...`);else if("JSON"!==o){if(r(a))try{return void localStorage.setItem(`${__classPrivateFieldGet(this,t,"f")}${e}`,`${o}|${n(a)}`)}catch(t){console.error(`LocalObjectStorage can's transform value of key "${e}" from type "${o}" and skip...`,t)}}else console.error(`LocalObjectStorage can't accept type name "${o}", skip...`);try{return void localStorage.setItem(`${__classPrivateFieldGet(this,t,"f")}${e}`,`JSON|${JSON.stringify(a)}`)}catch(t){console.error(`LocalObjectStorage can's transform value of key "${e}" from JSON and skip...`,t)}}removeItem(e){localStorage.removeItem(`${__classPrivateFieldGet(this,t,"f")}${e}`)}clear(){__classPrivateFieldGet(this,e,"m",a).call(this).forEach(e=>{localStorage.removeItem(e)}),this.length=0}key(t){return __classPrivateFieldGet(this,e,"m",a).call(this)[t]}}t=new WeakMap,e=new WeakSet,a=function _LocalObjectStorage_getAllKeys(){return Object.keys(localStorage).filter(e=>e.startsWith(__classPrivateFieldGet(this,t,"f")))},LocalObjectStorage.plugins={transformations:{get list(){return o.map(e=>Object.assign(Object.create(null),e))},add:({type:e,match:t,decode:a,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}", skip...`),!1):[...c,...LocalObjectStorage.plugins.transformations.list].some(({type:t})=>t===e)?(console.error(`LocalObjectStorage can't accept duplicated type name "${e}", skip...`),!1):"function"!=typeof t||"function"!=typeof a||"function"!=typeof r?(console.error(`LocalObjectStorage can't accept broken transformation [ type: "${e}", match: ${typeof t}, decode: ${typeof a}, encode: ${typeof r} ], skip...`),!1):(o.push({type:e,match:t,decode:a,encode:r}),!0)}},window.LocalObjectStorage=LocalObjectStorage})();  
"use strict";var __classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(e,t,a,c,o){if("m"===c)throw new TypeError("Private method is not writable");if("a"===c&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===c?o.call(e,a):o?o.value=a:t.set(e,a),a},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(e,t,a,c){if("a"===a&&!c)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!c:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===a?c:"a"===a?c.call(e):c?c.value:t.get(e)};(()=>{var e,t;const a=[{type:"undefined",match:e=>void 0===e,encode:()=>"undefined",decode:()=>{}},{type:"bigint",match:e=>"bigint"==typeof e,encode:e=>`${e}`,decode:e=>BigInt(e)},{type:"date",match:e=>e instanceof Date,encode:e=>e.toISOString(),decode:e=>new Date(e)},{type:"set",match:e=>e instanceof Set,encode:e=>JSON.stringify([...e.values()]),decode:e=>new Set(JSON.parse(e))},{type:"map",match:e=>e instanceof Map,encode:e=>JSON.stringify([...e.entries()]),decode:e=>new Map(JSON.parse(e))},{type:"regexp",match:e=>e instanceof RegExp,encode:e=>`${e}`,decode:e=>new RegExp(e.slice(1,e.length-1))}],c=[];class LocalObjectStorage{constructor(a=""){if(e.set(this,void 0),t.set(this,()=>Object.keys(localStorage).filter(t=>t.startsWith(__classPrivateFieldGet(this,e,"f")))),"default"===a)throw new Error(`LocalObjectStorage can't accept prefix "${a}".`);if(a.includes("/"))throw new Error(`LocalObjectStorage can't accept prefix "${a}" including "/".`);__classPrivateFieldSet(this,e,"AnnTool-localObjectStorage/"+(a?.length>0?`${a}/`:"default/"),"f")}get _keyPrefix(){return __classPrivateFieldGet(this,e,"f")}getAllKeys(){return __classPrivateFieldGet(this,t,"f").call(this).map(t=>t.replace(__classPrivateFieldGet(this,e,"f"),""))}get length(){return __classPrivateFieldGet(this,t,"f").call(this).length}getItem(t,c){const o=localStorage.getItem(`${__classPrivateFieldGet(this,e,"f")}${t}`);if(null===o)return c||o;for(const{type:e,decode:c}of a.concat(LocalObjectStorage.plugins.transformations.list))if(e.includes("|"))console.error(`LocalObjectStorage can't accept type name "${e}" including "|", skip...`);else if("JSON"!==e){if(o.startsWith(`${e}|`))try{return c(o.replace(`${e}|`,""))}catch(a){console.error(`LocalObjectStorage can's transform value of key "${t}" to type "${e}" and skip...`)}}else console.error(`LocalObjectStorage can't accept type name "${e}", skip...`);try{return JSON.parse(o.replace("JSON|",""))}catch(e){return void console.error(`LocalObjectStorage can's transform value of key "${t}" to JSON and return \`undefined\`...`,e)}}setItem(t,c){for(const{type:o,match:r,encode:n}of a.concat(LocalObjectStorage.plugins.transformations.list))if(o.includes("|"))console.error(`LocalObjectStorage can't accept type name "${o}" including "|", skip...`);else if("JSON"!==o){if(r(c))try{return void localStorage.setItem(`${__classPrivateFieldGet(this,e,"f")}${t}`,`${o}|${n(c)}`)}catch(e){console.error(`LocalObjectStorage can's transform value of key "${t}" from type "${o}" and skip...`,e)}}else console.error(`LocalObjectStorage can't accept type name "${o}", skip...`);try{return void localStorage.setItem(`${__classPrivateFieldGet(this,e,"f")}${t}`,`JSON|${JSON.stringify(c)}`)}catch(e){console.error(`LocalObjectStorage can's transform value of key "${t}" from JSON and skip...`,e)}}removeItem(t){localStorage.removeItem(`${__classPrivateFieldGet(this,e,"f")}${t}`)}clear(){__classPrivateFieldGet(this,t,"f").call(this).forEach(e=>{localStorage.removeItem(e)}),this.length=0}key(e){return __classPrivateFieldGet(this,t,"f").call(this)[e]}}e=new WeakMap,t=new WeakMap,LocalObjectStorage.plugins={transformations:{get list(){return c.map(e=>Object.assign(Object.create(null),e))},add:({type:e,match:t,decode:o,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}", skip...`),!1):[...a,...LocalObjectStorage.plugins.transformations.list].some(({type:t})=>t===e)?(console.error(`LocalObjectStorage can't accept duplicated type name "${e}", skip...`),!1):"function"!=typeof t||"function"!=typeof o||"function"!=typeof r?(console.error(`LocalObjectStorage can't accept broken transformation [ type: "${e}", match: ${typeof t}, decode: ${typeof o}, encode: ${typeof r} ], skip...`),!1):(c.push({type:e,match:t,decode:o,encode:r}),!0)}},window.LocalObjectStorage=LocalObjectStorage})();  


/* </pre> */
/* </pre> */

2025年9月21日 (日) 17:52的最新版本

/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/LocalObjectStorage/Gadget-LocalObjectStorage.js|user=[[U:AnnAngela]]|co-authors=|longId=c61967347a25491d4253b6b176b667233dcd7900|shortId=c6196734|summary=refactor: use arrow functions for consistency in various gadgets}}'; 

/* <pre> */

"use strict";var __classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(e,t,a,c,o){if("m"===c)throw new TypeError("Private method is not writable");if("a"===c&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===c?o.call(e,a):o?o.value=a:t.set(e,a),a},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(e,t,a,c){if("a"===a&&!c)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!c:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===a?c:"a"===a?c.call(e):c?c.value:t.get(e)};(()=>{var e,t;const a=[{type:"undefined",match:e=>void 0===e,encode:()=>"undefined",decode:()=>{}},{type:"bigint",match:e=>"bigint"==typeof e,encode:e=>`${e}`,decode:e=>BigInt(e)},{type:"date",match:e=>e instanceof Date,encode:e=>e.toISOString(),decode:e=>new Date(e)},{type:"set",match:e=>e instanceof Set,encode:e=>JSON.stringify([...e.values()]),decode:e=>new Set(JSON.parse(e))},{type:"map",match:e=>e instanceof Map,encode:e=>JSON.stringify([...e.entries()]),decode:e=>new Map(JSON.parse(e))},{type:"regexp",match:e=>e instanceof RegExp,encode:e=>`${e}`,decode:e=>new RegExp(e.slice(1,e.length-1))}],c=[];class LocalObjectStorage{constructor(a=""){if(e.set(this,void 0),t.set(this,()=>Object.keys(localStorage).filter(t=>t.startsWith(__classPrivateFieldGet(this,e,"f")))),"default"===a)throw new Error(`LocalObjectStorage can't accept prefix "${a}".`);if(a.includes("/"))throw new Error(`LocalObjectStorage can't accept prefix "${a}" including "/".`);__classPrivateFieldSet(this,e,"AnnTool-localObjectStorage/"+(a?.length>0?`${a}/`:"default/"),"f")}get _keyPrefix(){return __classPrivateFieldGet(this,e,"f")}getAllKeys(){return __classPrivateFieldGet(this,t,"f").call(this).map(t=>t.replace(__classPrivateFieldGet(this,e,"f"),""))}get length(){return __classPrivateFieldGet(this,t,"f").call(this).length}getItem(t,c){const o=localStorage.getItem(`${__classPrivateFieldGet(this,e,"f")}${t}`);if(null===o)return c||o;for(const{type:e,decode:c}of a.concat(LocalObjectStorage.plugins.transformations.list))if(e.includes("|"))console.error(`LocalObjectStorage can't accept type name "${e}" including "|", skip...`);else if("JSON"!==e){if(o.startsWith(`${e}|`))try{return c(o.replace(`${e}|`,""))}catch(a){console.error(`LocalObjectStorage can's transform value of key "${t}" to type "${e}" and skip...`)}}else console.error(`LocalObjectStorage can't accept type name "${e}", skip...`);try{return JSON.parse(o.replace("JSON|",""))}catch(e){return void console.error(`LocalObjectStorage can's transform value of key "${t}" to JSON and return \`undefined\`...`,e)}}setItem(t,c){for(const{type:o,match:r,encode:n}of a.concat(LocalObjectStorage.plugins.transformations.list))if(o.includes("|"))console.error(`LocalObjectStorage can't accept type name "${o}" including "|", skip...`);else if("JSON"!==o){if(r(c))try{return void localStorage.setItem(`${__classPrivateFieldGet(this,e,"f")}${t}`,`${o}|${n(c)}`)}catch(e){console.error(`LocalObjectStorage can's transform value of key "${t}" from type "${o}" and skip...`,e)}}else console.error(`LocalObjectStorage can't accept type name "${o}", skip...`);try{return void localStorage.setItem(`${__classPrivateFieldGet(this,e,"f")}${t}`,`JSON|${JSON.stringify(c)}`)}catch(e){console.error(`LocalObjectStorage can's transform value of key "${t}" from JSON and skip...`,e)}}removeItem(t){localStorage.removeItem(`${__classPrivateFieldGet(this,e,"f")}${t}`)}clear(){__classPrivateFieldGet(this,t,"f").call(this).forEach(e=>{localStorage.removeItem(e)}),this.length=0}key(e){return __classPrivateFieldGet(this,t,"f").call(this)[e]}}e=new WeakMap,t=new WeakMap,LocalObjectStorage.plugins={transformations:{get list(){return c.map(e=>Object.assign(Object.create(null),e))},add:({type:e,match:t,decode:o,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}", skip...`),!1):[...a,...LocalObjectStorage.plugins.transformations.list].some(({type:t})=>t===e)?(console.error(`LocalObjectStorage can't accept duplicated type name "${e}", skip...`),!1):"function"!=typeof t||"function"!=typeof o||"function"!=typeof r?(console.error(`LocalObjectStorage can't accept broken transformation [ type: "${e}", match: ${typeof t}, decode: ${typeof o}, encode: ${typeof r} ], skip...`),!1):(c.push({type:e,match:t,decode:o,encode:r}),!0)}},window.LocalObjectStorage=LocalObjectStorage})(); 

/* </pre> */