SyntaxLite_min

Library for simplifying code logic and syntax (Lite)

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/487608/1711627/SyntaxLite_min.js

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         SyntaxLite
// @version      2025.12.11
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax (Lite)
// @namespace    https://greasyfork.org/users/989635
// @match        *://*/*
// @license      MPL-2.0
// ==/UserScript==
const Lib=(()=>{function y(a=document,b,c){if(1!==a?.nodeType&&9!==a?.nodeType)return c?[]:void 0;const e=b[0],d=b.slice(1);if(/[ .#:[\]>+~*,()^$=]/.test(d))return c?a.querySelectorAll(b):a.querySelector(b);if(!c&&"#"===e)return 9===a.nodeType?a.getElementById(d):a.querySelector(b);if("."===b[0])return a=a.getElementsByClassName(d),c?[...a]:a[0];a=a.getElementsByTagName(b);return c?[...a]:a[0]}async function V(a,b,c=crypto.randomUUID(),e=!0){let d=B.get(c);if(e||!d)d||(d=document.createElement(a),
d.id=c,(a=J.head)?a.appendChild(d):W("head").then(g=>{g.appendChild(d)})),d.textContent+=b,B.set(c,d)}async function W(a,b,c={}){const e=Array.isArray(a)?X.queryMap:X.queryElement,{raf:d=!1,all:g=!1,timeout:h=8,throttle:n=0,debounce:q=50,visibility:f=!0,subtree:k=!0,childList:m=!0,attributes:r=!0,characterData:p=!1,timeoutResult:l=!1,root:w=document}=c||{};return new Promise((t,u)=>{const v=async function(){let C,x;if(d){let D;const I=()=>{(x=e(a,g))?(cancelAnimationFrame(D),clearTimeout(C),b?.(x),
t(x)):D=requestAnimationFrame(I)};D=requestAnimationFrame(I);C=setTimeout(()=>{cancelAnimationFrame(D);l&&(b?.(x),t(x))},1E3*h)}else{const [D,I]=0<n?[K,n]:[L,q],M=new MutationObserver(D(()=>{if(x=e(a,g))M.disconnect(),clearTimeout(C),b?.(x),t(x)},I));M.observe(w,{subtree:k,childList:m,attributes:r,characterData:p});C=setTimeout(()=>{M.disconnect();l&&(b?.(x),t(x))},1E3*h)}};f&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>v(),{once:!0}):v()})}function Y(a){if(!a||
!a.trim())return 0;if(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(a)){var b=(new Date(a)).getTime();if(!isNaN(b))return Math.floor(b/1E3)}b=new Date;var c=[...a.matchAll(/(\d+)\s*([YyMDdhms])/g)];if(0===c.length)return 0;var e=a=0,d=0,g=0,h=0,n=0;for(const q of c){c=parseInt(q[1],10);const f=q[2];switch(f.toLowerCase()){case "y":a+=c;break;case "d":d+=c;break;case "h":g+=c;break;case "s":n+=c;break;default:"M"===f?e+=c:"m"===f&&(h+=c)}}b.setFullYear(b.getFullYear()+a);b.setMonth(b.getMonth()+e);
b.setDate(b.getDate()+d);b.setHours(b.getHours()+g);b.setMinutes(b.getMinutes()+h);b.setSeconds(b.getSeconds()+n);return Math.floor(b.getTime()/1E3)}function N(a,b,c,{space:e=0,expireStr:d}={}){const g=G(c);c={type:g,data:Z[g]?.(c)??c};(d=Y(d))&&(c.expire=d);a(b,JSON.stringify(c,null,e))}function O(a,b,c,{autoRemove:e=!1,removeer:d}={}){a=a(b);if(null==a)return c;try{a=JSON.parse(a);const g=a instanceof Object;if(g&&a.expire&&Date.now()>1E3*a.expire)return d(b),c;let h,n;g?(h=a.type??"Object",n=a.data??
a):(h=G(a),n=a);const q=aa[h]?.(n)??n;e&&d(b);return q}catch{return"object"===typeof a&&J.isEmpty(a)||"string"===typeof a&&a.startsWith("[object")?c:a}}function K(a,b){let c=0;return(...e)=>{const d=Date.now();d-c>=b&&(c=d,a(...e))}}function L(a,b){let c;return(...e)=>{clearTimeout(c);c=setTimeout(function(){a(...e)},b)}}function ba(a){a=new Blob([a],{type:"application/javascript"});const b=URL.createObjectURL(a),c=new Worker(b),e=c.terminate;c.terminate=function(){e.call(c);URL.revokeObjectURL(b)};
return c}function P(a,b="https://cdnjs.cloudflare.com/ajax/libs/pako/2.1.0/pako.min.js"){function c(f){return new Promise((k,m)=>{const r=new Blob([f],{type:"application/octet-stream"}),p=new FileReader;p.onload=function(l){l=l.target.result;l=l.substring(l.indexOf(",")+1);k(l)};p.onerror=function(l){m(l)};p.readAsDataURL(r)})}function e(f,k,m){return new Promise(r=>{const p=n++;q.set(p,r);d.postMessage({type:f,data:k,level:m,requestId:p},[k.buffer])})}let d=ba(`${a||`importScripts('${b}')`}onmessage = function(e) {const { type, data, level, requestId } = e.data;const bytes = type === "compress" ? pako.deflate(data, { level }) : pako.inflate(data);postMessage({ data: bytes, requestId }, [bytes.buffer]);}`);
const g=new TextEncoder,h=new TextDecoder;let n=0;const q=new Map;d.onmessage=f=>{const {requestId:k,data:m}=f.data;q.has(k)&&(q.get(k)(m),q.delete(k))};return{async destroyWorker(){d&&(d.terminate(),d=null)},async compress(f,{level:k=5,base64:m=!0,stringify:r=!0}={}){if(null==f)return f;f=await e("compress",g.encode(r?JSON.stringify(f):f),k);return m?await c(f):f},async decompress(f,k=!0){if(null==f)return f;if(!(f instanceof Uint8Array)){f=atob(f);const m=f.length,r=new Uint8Array(m);
for(let p=0;p<m;p++)r[p]=f.charCodeAt(p);f=r}f=await e("decompress",f);f=h.decode(f);return k?JSON.parse(f):f}}}function ca(a){if(null==a){for(const b of H)GM_unregisterMenuCommand(b);H.clear()}else Array.isArray(a)?a.forEach(b=>{H.delete(b)&&GM_unregisterMenuCommand(b)}):H.delete(a)&&GM_unregisterMenuCommand(a)}const ha=new DOMParser,G=a=>Object.prototype.toString.call(a).slice(8,-1);[Document.prototype,Element.prototype].forEach(a=>{a.$q=function(b){return y(this,b,!1)};a.$qa=function(b){return y(this,
b,!0)}});let z=null;const Q=()=>window.trustedTypes?.getPolicy?.("default")??window.trustedTypes?.createPolicy?.(Symbol("myPolicy").toString(),{createHTML:a=>a}),R={$text(a){return null==a?this?.textContent?.trim():this.textContent=a?.trim()??""},$copy(a=!0){return this.cloneNode(a)},$iHtml(a){return null==a?this.innerHTML:this.innerHTML=a},$safeiHtml(a){if(null==a)return this.innerHTML;try{z??=Q(),z?this.appendChild(document.createRange().createContextualFragment(z.createHTML(a))):this.innerHTML=
a}catch(b){console.error(b)}},$oHtml(a){return null==a?this.outerHTML:this.outerHTML=a},$iAdjacent(a,b="beforeend"){null!=a&&(1===a.nodeType?this.insertAdjacentElement(b,a):this.insertAdjacentHTML(b,a))},$safeiAdjacent(a,b="beforeend"){if(null!=a){if(1===a.nodeType)return this.insertAdjacentElement(b,a);try{z??=Q(),z?this.insertAdjacentHTML(b,z.createHTML(a)):this.insertAdjacentHTML(b,a)}catch(c){console.error(c)}}},$safeiBefore(a,b="beforeend"){if(null!=a)try{z??=Q();if(!z)throw Error("Policy not found");
const c=document.createRange().createContextualFragment(z.createHTML(a));switch(b){case "beforebegin":this.parentNode?.insertBefore(c,this);break;case "afterbegin":this.insertBefore(c,this.firstChild);break;case "beforeend":this.appendChild(c);break;case "afterend":this.parentNode?.insertBefore(c,this.nextSibling)}}catch(c){console.error(c)}},$sAttr(a,b){this.setAttribute(a,b)},$dAttr(a){this.removeAttribute(a)},$gAttr(a){return this.getAttribute(a)},$hAttr(a){return this.hasAttribute(a)},$addClass(...a){this.classList.add(...a)},
$delClass(...a){this.classList.remove(...a)},$toggleClass(a,b){this.classList.toggle(a,b)},$replaceClass(a,b){this.classList.replace(a,b)},$hasClass(a){return this.classList.contains(a)}};Object.assign(Node.prototype,R);const da=Object.keys(R)[0];Object.defineProperty(Object.prototype,da,{value:function(a=null){return R[da].call(this,a)},writable:!0,configurable:!0});const J={$q:document.$q.bind(document),$Q:(a,b)=>y(a,b,!1),$qa:document.$qa.bind(document),$Qa:(a,b)=>y(a,b,!0),html:document.documentElement,
get head(){const a=document.head;a&&Object.defineProperty(this,"head",{value:a,writable:!1});return a},get body(){const a=document.body;a&&Object.defineProperty(this,"body",{value:a,writable:!1});return a},img:document.images,link:document.links,script:document.scripts,style:document.styleSheets,$url:location.href,get url(){return location.href},$origin:location.origin,get origin(){return location.origin},$domain:location.hostname,get domain(){return location.hostname},$lang:navigator.language,get lang(){return navigator.language},
$agen:navigator.userAgent,get agen(){return navigator.userAgent},isEmpty(a){for(const b in a)return!1;return!0},createDomFragment:a=>document.createRange().createContextualFragment(a),get createFragment(){return document.createDocumentFragment()},title:a=>null==a?document.title:document.title=a,cookie:a=>null==a?document.cookie:document.cookie=a,createUrl:a=>URL.createObjectURL(a),_on:(a,b)=>{const c={};for(const e of Object.keys(b)){let d=b[e];d&&("function"===typeof d&&(d={listen:d}),d.listen&&
(a.addEventListener(e,d.listen,d.add),c[e]=()=>a.removeEventListener(e,d.listen,d.add)))}return c},createElement(a,b,c,e){const [d,g,h={},n="beforeend"]="string"===typeof a?[void 0,a,b,c]:[a,b,c,e];if(g){var {class:q,text:f,html:k,rows:m,cols:r,on:p={},style:l={},attr:w={},...t}=h;a=document.createElement(g);q&&(a.className=q);f&&(a.textContent=f);k&&a.$safeiHtml(k);null!=m&&(a.rowSpan=m);null!=r&&(a.colSpan=r);Object.assign(a,t);"string"===typeof l?a.style.cssText=l:Object.assign(a.style,l);for(const v in w)a.setAttribute(v,
w[v]);var u="object"!==typeof p||this.isEmpty(p)?{}:this._on(a,p);Object.assign(a,{on(v,C,x){this.addEventListener(v,C,x);Object.assign(u,{[v]:()=>this.removeEventListener(v,C,x)})},off(v){u[v]?.();delete u[v]},offAll(){Object.keys(u).forEach(v=>{u[v]();delete u[v]})}});return 1===d?.nodeType?d.insertAdjacentElement(n,a):a}}},A=new Map,S={log:(...a)=>console.log(...a),warn:(...a)=>console.warn(...a),table:(...a)=>console.table(...a),trace:(...a)=>console.trace(...a),debug:(...a)=>console.debug(...a),
error:(...a)=>console.error(...a),count:a=>console.count(a)},B=new Map,T=new Map,X={queryMap:(a,b)=>{a=a.map(c=>y(document,c,b));return b?a.every(c=>0<c.length)&&a:a.every(Boolean)&&a},queryElement:(a,b)=>{a=y(document,a,b);return(b?0<a.length:a)&&a}},aa={Set:a=>new Set(a),Map:a=>new Map(a),Date:a=>new Date(a)},Z={Set:a=>a instanceof Set?[...a]:a,Map:a=>a instanceof Map?[...a]:a,Date:a=>a instanceof Date?a.toISOString():a},ea=localStorage.removeItem.bind(localStorage),ia=localStorage.setItem.bind(localStorage),
ja=localStorage.getItem.bind(localStorage),fa=sessionStorage.removeItem.bind(sessionStorage),ka=sessionStorage.setItem.bind(sessionStorage),la=sessionStorage.getItem.bind(sessionStorage);let E;const U={ko:"Korea","ko-KR":"Korea",ja:"Japan","ja-JP":"Japan",ru:"Russia","ru-RU":"Russia",en:"English","en-US":"English","en-GB":"English","en-AU":"English","en-CA":"English","en-NZ":"English","en-IE":"English","en-ZA":"English","en-IN":"English",zh:"Simplified","zh-CN":"Simplified","zh-SG":"Simplified","zh-MY":"Simplified",
"zh-TW":"Traditional","zh-HK":"Traditional","zh-MO":"Traditional"},H=new Set,F=new Map;return function(...a){const b={};for(const c of a)c&&Object.defineProperties(b,Object.getOwnPropertyDescriptors(c));return b}({get sX(){return window.scrollX},get sY(){return window.scrollY},get iW(){return window.innerWidth},get iH(){return window.innerHeight},get platform(){const a={desktop:!1,mobile:!1};window.matchMedia?.("(pointer: coarse)")?.matches||window.matchMedia?.("(hover: none)")?.matches?a.mobile=
!0:/Android|iPhone|iPad|iPod|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?a.mobile=!0:a.desktop=!0;Object.defineProperty(this,"platform",{value:a,writable:!1});return a}},J,{addStyle:(a,b,c)=>V("style",a,b,c),addScript:(a,b,c)=>V("script",a,b,c),delLocal:a=>ea(a),setLocal:(a,b,c)=>N(ia,a,b,{expireStr:c}),getLocal:(a,b,c)=>O(ja,a,b,{autoRemove:c,removeer:ea}),delSession:a=>fa(a),setSession:(a,b,c)=>N(ka,a,b,{expireStr:c}),getSession:(a,b,c)=>O(la,a,b,{autoRemove:c,removeer:fa}),
delV:a=>GM_deleteValue(a),allV:()=>GM_listValues()||void 0,setV:(a,b)=>GM_setValue(a,b),getV:(a,b)=>GM_getValue(a,b)||void 0,setJV:(a,b,{space:c,expireStr:e}={})=>N(GM_setValue,a,b,{space:c,expireStr:e}),getJV:(a,b,c)=>O(GM_getValue,a,b,{autoRemove:c,removeer:GM_deleteValue}),eventRecord:A,addRecord:B,observerRecord:T,type:G,onE:async function(a,b,c,e={},d){try{"string"===typeof a&&(a=y(document,a));let g=b.split(/\s*[,|/]\s*/).filter(Boolean);if(0===g.length)throw Error("No event types provided");
if(1===g.length)a.addEventListener(b,c,e);else{let h;const n=q=>{clearTimeout(h);h=setTimeout(()=>c(q),15)};g.forEach(q=>a.addEventListener(q,n,e))}d?.(!0)}catch{d?.(!1)}},onEvent:async function(a,b,c,e={}){const {mark:d,...g}=e;"string"===typeof a&&(a=y(document,a));e=d??a;const h=A.get(e);h?.has(b)||(a.addEventListener(b,c,g),h||A.set(e,new Map),A.get(e).set(b,{element:a,type:b,listener:c}))},offEvent:async function(a,b,c){if(null==a&&null==b&&null==c){for(const e of A.values())for(const {element:d,
type:g,listener:h}of e.values())d.removeEventListener(g,h);A.clear()}else if(a=c??"string"===typeof a?y(document,a):a,c=A.get(a))if(b=c.get(b)){const {element:e,type:d,listener:g}=b;e.removeEventListener(d,g);A.get(a).delete(d)}else{for(const {element:e,type:d,listener:g}of c.values())e.removeEventListener(d,g);A.delete(a)}},onUrlChange:function(a,b=15){function c(k){clearTimeout(d);h||"urlchange"!==k||(h=!0);d=setTimeout(()=>{h&&e(!1,!0);a({type:k,url:location.href,domain:location.hostname})},Math.max(15,
b))}function e(k=!0,m=!1){m&&g||(clearTimeout(d),history.pushState=n,history.replaceState=q,window.removeEventListener("popstate",f.popstate),window.removeEventListener("hashchange",f.hashchange),k&&window.removeEventListener("urlchange",f.urlchange),g=!0)}let d,g=!1,h=!1;const n=history.pushState,q=history.replaceState,f={urlchange:()=>c("urlchange"),popstate:()=>c("popstate"),hashchange:()=>c("hashchange")};window.addEventListener("urlchange",f.urlchange);window.addEventListener("popstate",f.popstate);
window.addEventListener("hashchange",f.hashchange);history.pushState=function(){n.apply(this,arguments);c("pushState")};history.replaceState=function(){q.apply(this,arguments);c("replacestate")};return{off:e}},log:function(...a){if(0!==a.length){var b={},c=a,e={dev:!0,group:null,collapsed:!0};if(1<a.length){const f=a[0],k=a.at(-1),m=f?.constructor===Object,r=k?.constructor===Object;if(r&&!m)b=k,c=a.slice(0,-1);else if(m&&!r)b=f,c=a.slice(1);else if(m&&r){const p=new Set(Object.keys(e));b=Object.keys(f).filter(l=>
p.has(l)).length;Object.keys(k).filter(l=>p.has(l)).length>b?(b=k,c=a.slice(0,-1)):(b=f,c=a.slice(1))}}var {dev:d,group:g,collapsed:h}={...e,...b};if(!d||0===c.length)return new Proxy({},{get(){}});var n=f=>{"count"===f?S.count(c[0]):(f=S[f]||S.log,g?(h?console.groupCollapsed(g):console.group(g),f(...c),console.groupEnd()):f(...c))},q=setTimeout(()=>n("log",c));return new Proxy({},{get(f,k){clearTimeout(q);n(k,c)}})}},delHead:async function(a){if(null==a){for(var b of B.values())b.remove();B.clear()}else if(b=
B.get(a))b.remove(),B.delete(a)},observer:async function(a,b,c={},e){const {mark:d="",debounce:g=0,throttle:h=100,subtree:n=!0,childList:q=!0,attributes:f=!0,characterData:k=!1}=c||{};if(d&&(c=T.get(d))){if(c.target===a)return;c.ob.disconnect()}const [m,r]=0<g?[L,g]:[K,h];c={subtree:n,childList:q,attributes:f,characterData:k};const p=new MutationObserver(m((l,w)=>{b(l,w)},r));p.observe(a,c);d&&T.set(d,{target:a,ob:p});e?.({ob:p,op:c})},waitEl:W,openDB:async function(a="StorageDB",b=1,c){return new Promise((e,
d)=>{const g=indexedDB.open(a,b),h=a.replace(/db$/i,"").toLowerCase();g.onupgradeneeded=n=>{n=n.target.result;n.objectStoreNames.contains(h)||n.createObjectStore(h)};g.onsuccess=n=>{async function q(k){return new Promise((m,r)=>{const p=f.transaction(h,"readwrite").objectStore(h).delete(k);p.onsuccess=()=>m(p.result);p.onerror=()=>r(p.error)})}const f=n.target.result;e({set:async function(k,m,{compress:r=!0,expireStr:p}={}){const l={};r?(E??=P(c),r=G(m),l.type=r,l.data=await E.compress(Z[r]?.(m)??
m,{base64:!1}),l.compressed=!0):l.data=m;if(m=Y(p))l.expire=m;return new Promise((w,t)=>{const u=f.transaction(h,"readwrite").objectStore(h).put(l,k);u.onsuccess=()=>w(u.result);u.onerror=()=>t(u.error)})},get:async function(k,m,r=!1){const p=f.transaction(h,"readonly").objectStore(h),l=await new Promise((w,t)=>{const u=p.get(k);u.onsuccess=()=>w(u.result);u.onerror=()=>t(m)});if(null==l)return m;try{const w=l instanceof Object;if(w&&l.expire&&Date.now()>1E3*l.expire)return q(k),m;let t;if(w){if(t=
l.data??l,l.compressed){E??=P(c);t=await E.decompress(t);const u=l.type||G(t);t=aa[u]?.(t)??t}}else t=l;r&&q(k);return t}catch{return l}},del:q,destroy:function(){f&&(f.close(),indexedDB.deleteDatabase(a),E.destroyWorker(),setTimeout(()=>E=null,100))}})};g.onerror=()=>d(g.error)})},throttle:K,debounce:L,createWorker:ba,createStrCompress:P,outputJson:async function(a,b,c){try{a="string"===typeof a?a:JSON.stringify(a,null,4);b="string"===typeof b?b.endsWith(".json")?b:`${b}.json`:`Untitled-${crypto.randomUUID().slice(9,
23)}.json`;const e=new Blob([a],{type:"application/json"}),d=document.createElement("a");d.href=URL.createObjectURL(e);d.download=b;d.click();URL.revokeObjectURL(d.href);d.remove();c?.({State:!0})}catch(e){c?.({State:!1,Info:e})}},runTime:function(a,{lable:b="Elapsed Time:",log:c=!0,format:e=!0,style:d="\u001b[1m\u001b[36m%s\u001b[0m"}={}){if(!a)return performance.now();a=e?`${((performance.now()-a)/1E3).toPrecision(3)}s`:performance.now()-a;return c?console.log(d,`${b} ${a}`):a},getDate:function(a){const b=
new Date,c={year:b.getFullYear(),month:`${b.getMonth()+1}`.padStart(2,"0"),date:`${b.getDate()}`.padStart(2,"0"),hour:`${b.getHours()}`.padStart(2,"0"),minute:`${b.getMinutes()}`.padStart(2,"0"),second:`${b.getSeconds()}`.padStart(2,"0")};return(e=>e.replace(/{([^}]+)}/g,(d,g)=>c[g]??"Error"))("string"===typeof a?a:"{year}-{month}-{date} {hour}:{minute}:{second}")},translMatcher:function(a,b=navigator.language,c="en-US"){return a[U[b]]??a[U[c]]??a[U["en-US"]]},regMenu:function(a,b={}){let {name:c=
"regMenu",index:e=1,reset:d=!1}=b||{};d&&ca();for(let [g,h]of Object.entries(a))a=`${c}-${e++}`,"function"===typeof h&&(h={func:h}),GM_registerMenuCommand(g,()=>{h.func()},{id:a,title:h.desc,autoClose:h.close,accessKey:h.hotkey}),H.add(a)},unMenu:ca,storageListen:function(a,b){a.forEach(c=>{if(!F.has(c)){const e=GM_addValueChangeListener(c,function(d,g,h,n){b({key:d,ov:g,nv:h,far:n})});F.set(c,e)}});return{off(c){const e=F.get(c);e&&(GM_removeValueChangeListener(e),F.delete(c))},offAll(){for(const c of F.values())GM_removeValueChangeListener(c);
F.clear()}}},sleep:a=>new Promise(b=>setTimeout(b,a)),domParse:a=>ha.parseFromString(a,"text/html")})})();