SyntaxLite

Library for simplifying code logic and syntax (Lite)

As of 30. 09. 2025. See the latest version.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/487608/1669404/SyntaxLite.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         SyntaxLite
// @version      2025.09.30
// @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 v(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]}function P(...a){if(0!==a.length){var b={},c=a,e={dev:!0,group:null,collapsed:!0};if(1<a.length){const h=
a[0],l=a.at(-1),p=h?.constructor===Object,r=l?.constructor===Object;if(r&&!p)b=l,c=a.slice(0,-1);else if(p&&!r)b=h,c=a.slice(1);else if(p&&r){const q=new Set(Object.keys(e));b=Object.keys(h).filter(w=>q.has(w)).length;Object.keys(l).filter(w=>q.has(w)).length>b?(b=l,c=a.slice(0,-1)):(b=h,c=a.slice(1))}}var {dev:d,group:f,collapsed:g}={...e,...b};if(!d||0===c.length)return new Proxy({},{get(){}});var k=h=>{"count"===h?G.count(c[0]):(h=G[h]||G.log,f?(g?console.groupCollapsed(f):console.group(f),h(...c),
console.groupEnd()):h(...c))},m=setTimeout(()=>k("log",c));return new Proxy({},{get(h,l){clearTimeout(m);k(l,c)}})}}async function Q(a,b,c=crypto.randomUUID(),e=!0){if(e||!H.has(c)){var d=document.getElementById(c);d||(d=document.createElement(a),d.id=c,(a=R.head)?a.appendChild(d):S("head").then(f=>{f.appendChild(d)}));d.textContent+=b;H.add(c)}}async function S(a,b=null,c={}){const e=Array.isArray(a)?T.queryMap:T.queryElement,{raf:d=!1,all:f=!1,timeout:g=8,throttle:k=0,debounce:m=50,visibility:h=
!0,subtree:l=!0,childList:p=!0,attributes:r=!0,characterData:q=!1,timeoutResult:w=!1,root:I=document}=c||{};return new Promise((t,n)=>{const C=async function(){let x,u;if(d){let z;const D=()=>{(u=e(a,f))?(cancelAnimationFrame(z),clearTimeout(x),b?.(u),t(u)):z=requestAnimationFrame(D)};z=requestAnimationFrame(D);x=setTimeout(()=>{cancelAnimationFrame(z);w&&(b?.(u),t(u))},1E3*g)}else{const [z,D]=0<k?[J,k]:[K,m],L=new MutationObserver(z(()=>{if(u=e(a,f))L.disconnect(),clearTimeout(x),b?.(u),t(u)},D));
L.observe(I,{subtree:l,childList:p,attributes:r,characterData:q});x=setTimeout(()=>{L.disconnect();w&&(b?.(u),t(u))},1E3*g)}};h&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>C(),{once:!0}):C()})}function W(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,f=0,g=0,k=
0;for(const m of c){c=parseInt(m[1],10);const h=m[2];switch(h.toLowerCase()){case "y":a+=c;break;case "d":d+=c;break;case "h":f+=c;break;case "s":k+=c;break;default:"M"===h?e+=c:"m"===h&&(g+=c)}}b.setFullYear(b.getFullYear()+a);b.setMonth(b.getMonth()+e);b.setDate(b.getDate()+d);b.setHours(b.getHours()+f);b.setMinutes(b.getMinutes()+g);b.setSeconds(b.getSeconds()+k);return Math.floor(b.getTime()/1E3)}function E(a,b,{value:c,error:e,expireStr:d,autoRemove:f=!1}={}){if(null!=c)f=U(c),f={type:f,value:X[f]?.(c)??
c},(d=W(d))&&(f.expire=d),a.setItem(b,JSON.stringify(f));else{d=a.getItem(b);if(null==d)return e;d=JSON.parse(d);if(d.expire&&Date.now()>1E3*d.expire)return a.removeItem(b),e;d=Y[d.type]?.(d.value)??d.value;f&&a.removeItem(b);return d}}function J(a,b){let c=0;return(...e)=>{const d=Date.now();d-c>=b&&(c=d,a(...e))}}function K(a,b){let c=null;return(...e)=>{clearTimeout(c);c=setTimeout(function(){a(...e)},b)}}const U=a=>Object.prototype.toString.call(a).slice(8,-1);[Document.prototype,Element.prototype].forEach(a=>
{a.$q=function(b){return v(this,b,!1)};a.$qa=function(b){return v(this,b,!0)}});const M={$text(a=null){return null===a?this?.textContent?.trim():this.textContent=a?.trim()??""},$copy(a=!0){return this.cloneNode(a)},$iHtml(a=null){return null===a?this.innerHTML:this.innerHTML=a},$oHtml(a=null){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))},$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,M);const V=Object.keys(M)[0];Object.defineProperty(Object.prototype,V,{value:function(a=null){return M[V].call(this,a)},writable:!0,configurable:!0});const R={$q:document.$q.bind(document),
$Q:(a,b)=>v(a,b,!1),$qa:document.$qa.bind(document),$Qa:(a,b)=>v(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},createDomFragment:a=>document.createRange().createContextualFragment(a),get createFragment(){return document.createDocumentFragment()},title:(a=null)=>null===a?document.title:document.title=a,cookie:(a=null)=>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,f,g={},k="beforeend"]="string"===typeof a?[void 0,a,b,c]:[a,b,c,e];if(f){var {class:m,text:h="",rows:l,cols:p,on:r={},style:q={},attr:w={},...I}=g;a=document.createElement(f);a.textContent=h;m&&(a.className=m);void 0!==l&&(a.rowSpan=l);void 0!==p&&(a.colSpan=p);Object.assign(a,
I);"string"===typeof q?a.style.cssText=q:Object.assign(a.style,q);for(const n in w)a.setAttribute(n,w[n]);var t="object"===typeof r&&0<Object.keys(r).length?this._on(a,r):{};Object.assign(a,{on(n,C,x){this.addEventListener(n,C,x);Object.assign(t,{[n]:()=>this.removeEventListener(n,C,x)})},off(n){t[n]?.();delete t[n]},offAll(){Object.keys(t).forEach(n=>{t[n]();delete t[n]})}});return 1===d?.nodeType?d.insertAdjacentElement(k,a):a}}},A=new Map,G={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)},H=new Set,F=new Map,T={queryMap:(a,b)=>{a=a.map(c=>v(document,c,b));return b?a.every(c=>0<c.length)&&a:a.every(Boolean)&&a},queryElement:(a,b)=>{a=v(document,a,b);return(b?0<a.length:a)&&a}},Y={Set:a=>new Set(a),Map:a=>new Map(a),Date:a=>new Date(a)},X={Set:a=>[...a],Map:a=>[...a],Date:a=>a.toISOString()},N={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"},y=new Set,O=a=>void 0===a||null===a?null:a,B=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},_cache:void 0,get platform(){let a;a=void 0!==navigator.userAgentData?.mobile?navigator.userAgentData.mobile?"Mobile":"Desktop":window.matchMedia?.("(max-width: 767px), (pointer: coarse)")?.matches?"Mobile":/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?"Mobile":"Desktop";Object.defineProperty(this,"platform",
{value:a,writable:!1});return a}},R,{addStyle:(a,b,c)=>Q("style",a,b,c),addScript:(a,b,c)=>Q("script",a,b,c),getLocal:(a,b,c)=>E(localStorage,a,{error:b,autoRemove:c}),setLocal:(a,b,c)=>E(localStorage,a,{value:b,expireStr:c}),delLocal:a=>localStorage.removeItem(a),getSession:(a,b,c)=>E(sessionStorage,a,{error:b,autoRemove:c}),setSession:(a,b,c)=>E(sessionStorage,a,{value:b,expireStr:c}),delSession:a=>sessionStorage.removeItem(a),delV:a=>GM_deleteValue(a),allV:()=>O(GM_listValues()),setV:(a,b)=>GM_setValue(a,
b),getV:(a,b)=>O(GM_getValue(a,b)),setJV:(a,b,c=0)=>GM_setValue(a,JSON.stringify(b,null,c)),getJV(a,b){try{return JSON.parse(O(GM_getValue(a,b)))}catch{return b}},eventRecord:A,addRecord:H,observerRecord:F,$type:U,onE:async function(a,b,c,e={},d=null){try{"string"===typeof a&&(a=v(document,a));let f=b.split(/\s*[,|/]\s*/).filter(Boolean);if(0===f.length)throw Error("No event types provided");if(1===f.length)a.addEventListener(b,c,e);else{let g=null;const k=m=>{clearTimeout(g);g=setTimeout(()=>c(m),
15)};f.forEach(m=>a.addEventListener(m,k,e))}d?.(!0)}catch{d?.(!1)}},onEvent:async function(a,b,c,e={}){const {mark:d,...f}=e;"string"===typeof a&&(a=v(document,a));e=d??a;const g=A.get(e);g?.has(b)||(a.addEventListener(b,c,f),g||A.set(e,new Map),A.get(e).set(b,c))},offEvent:async function(a,b,c){"string"===typeof a&&(a=v(document,a));c=c??a;const e=A.get(c)?.get(b);e&&(a.removeEventListener(b,e),A.get(c).delete(b))},onUrlChange:function(a,b=15){function c(l){clearTimeout(d);g||"urlchange"!==l||(g=
!0);d=setTimeout(()=>{g&&e(!1,!0);a({type:l,url:location.href,domain:location.hostname})},Math.max(15,b))}function e(l=!0,p=!1){p&&f||(clearTimeout(d),history.pushState=k,history.replaceState=m,l&&window.removeEventListener("urlchange",h.urlchange),window.removeEventListener("popstate",h.popstate),window.removeEventListener("hashchange",h.hashchange),f=!0)}let d=null,f=!1,g=!1;const k=history.pushState,m=history.replaceState,h={urlchange:()=>c("urlchange"),popstate:()=>c("popstate"),hashchange:()=>
c("hashchange")};window.addEventListener("urlchange",h.urlchange);window.addEventListener("popstate",h.popstate);window.addEventListener("hashchange",h.hashchange);history.pushState=function(){k.apply(this,arguments);c("pushState")};history.replaceState=function(){m.apply(this,arguments);c("replacestate")};return{off:e}},log:P,createLog:function(a={}){return(...b)=>P(...b,a)},$observer:async function(a,b,c={},e=null){const {mark:d="",debounce:f=0,throttle:g=100,subtree:k=!0,childList:m=!0,attributes:h=
!0,characterData:l=!1}=c||{};if(d&&(c=F.get(d))){if(c.target===a)return;c.ob.disconnect();F.delete(d)}const [p,r]=0<f?[K,f]:[J,g];c={subtree:k,childList:m,attributes:h,characterData:l};const q=new MutationObserver(p(()=>{b()},r));q.observe(a,c);d&&F.set(d,{target:a,ob:q});e?.({ob:q,op:c})},waitEl:S,$throttle:J,$debounce:K,outputJson:async function(a,b,c=null){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=null,{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=
null){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,f)=>c[f]??"Error"))("string"===typeof a?a:"{year}-{month}-{date} {hour}:{minute}:{second}")},translMatcher:function(a,b=navigator.language,c="en-US"){return a[N[b]]??a[N[c]]??a[N["en-US"]]},regMenu:function(a,b={}){let {name:c=
"regMenu",index:e=1,reset:d=!1}=b||{};d&&([...y].map(f=>GM_unregisterMenuCommand(f)),y.clear());for(let [f,g]of Object.entries(a))a=`${c}-${e++}`,"function"===typeof g&&(g={func:g}),GM_registerMenuCommand(f,()=>{g.func()},{id:a,title:g.desc,autoClose:g.close,accessKey:g.hotkey}),y.add(a)},unMenu:async function(a){null==a?([...y].map(b=>GM_unregisterMenuCommand(b)),y.clear()):Array.isArray(a)?a.forEach(b=>{y.delete(b)&&GM_unregisterMenuCommand(b)}):y.delete(a)&&GM_unregisterMenuCommand(a)},storeListen:function(a,
b){a.forEach(c=>{if(!B.has(c)){const e=GM_addValueChangeListener(c,function(d,f,g,k){b({key:d,ov:f,nv:g,far:k})});B.set(c,e)}});return{off(c){const e=B.get(c);e&&(GM_removeValueChangeListener(e),B.delete(c))},offAll(){for(const c of B.values())GM_removeValueChangeListener(c);B.clear()}}}})})();