SyntaxLite

Library for simplifying code logic and syntax (Lite)

Fra og med 05.08.2025. Se den nyeste version.

Dette script bør ikke installeres direkte. Det er et bibliotek, som andre scripts kan inkludere med metadirektivet // @require https://update.greatest.deepsurf.us/scripts/487608/1636326/SyntaxLite.js

// ==UserScript==
// @name         SyntaxLite
// @version      2025/08/06
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax (Lite)
// @namespace    https://greatest.deepsurf.us/users/989635
// @match        *://*/*
// @license      MPL-2.0
// ==/UserScript==
const Lib=(()=>{function q(a=document,b,c){const e=b[0],d=b.slice(1);if(/[ #.\[:]/.test(d))return c?a.querySelectorAll(b):a.querySelector(b);if(!c&&"#"===e)return a.getElementById(d);if("."===b[0])return a=a.getElementsByClassName(d),c?[...a]:a[0];a=a.getElementsByTagName(b);return c?[...a]:a[0]}async function N(a,b,c,e){let d=document.getElementById(c);if(!d)d=document.createElement(a),d.id=c,(a=E.head)?a.appendChild(d):O("head").then(f=>{E.head=f;f.appendChild(d)});else if(!e)return;d.textContent+=
b}async function O(a,b=null,c={}){const e=Array.isArray(a)?P.queryMap:P.queryElement,{raf:d=!1,all:f=!1,timeout:g=8,throttle:n=0,debounce:l=50,visibility:p=!0,subtree:r=!0,childList:v=!0,attributes:w=!0,characterData:x=!1,timeoutResult:B=!1,root:F=document}=c||{};return new Promise((h,t)=>{const k=async function(){let u,m;if(d){let z;const C=()=>{(m=e(a,f))?(cancelAnimationFrame(z),clearTimeout(u),b&&b(m),h(m)):z=requestAnimationFrame(C)};z=requestAnimationFrame(C);u=setTimeout(()=>{cancelAnimationFrame(z);
B&&(b&&b(m),h(m))},1E3*g)}else{const [z,C]=0<n?[G,n]:[H,l],I=new MutationObserver(z(()=>{if(m=e(a,f))I.disconnect(),clearTimeout(u),b&&b(m),h(m)},C));I.observe(F,{subtree:r,childList:v,attributes:w,characterData:x});u=setTimeout(()=>{I.disconnect();B&&(b&&b(m),h(m))},1E3*g)}};p&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>k(),{once:!0}):k()})}function Q(a,b,c,e){let d;return null!=c?R[J(c)](b,a,c):(d=b.getItem(a),void 0!=d?R[J(JSON.parse(d))](b,d):e)}function G(a,
b){let c=0;return(...e)=>{const d=Date.now();d-c>=b&&(c=d,a(...e))}}function H(a,b){let c=null;return(...e)=>{clearTimeout(c);c=setTimeout(function(){a(...e)},b)}}const D={},J=a=>Object.prototype.toString.call(a).slice(8,-1);[Document.prototype,Element.prototype].forEach(a=>{a.$q=function(b){return q(this,b,!1)};a.$qa=function(b){return q(this,b,!0)}});const K={$text(a=null){return null!==a?this.textContent=a?.trim():this.textContent?.trim()},$copy(a=!0){return this.cloneNode(a)},$iHtml(a=null){return null!==
a?this.innerHTML=a:this.innerHTML},$oHtml(a=null){return null!==a?this.outerHTML=a:this.outerHTML},$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,
K);const S=Object.keys(K)[0];Object.defineProperty(Object.prototype,S,{value:function(a=null){return K[S].call(this,a)},writable:!0,configurable:!0});const E={$q:document.$q.bind(document),$Q:(a,b)=>q(a,b,!1),$qa:document.$qa.bind(document),$Qa:(a,b)=>q(a,b,!0),html:document.documentElement,head:document.head??q(document,"head",!1),body:document.body??q(document,"body",!1),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},get createFragment(){return document.createDocumentFragment()},title:(a=null)=>null!==a?document.title=a:document.title,cookie:(a=null)=>null!==a?document.cookie=a:document.cookie,createUrl:a=>URL.createObjectURL(a),_on:(a,{type:b,listener:c,add:e})=>
"string"===typeof b&&"function"===typeof c?(a.addEventListener(b,c,e),{[b]:()=>a.removeEventListener(b,c,e)}):{},createElement(a,b,c){const [e,d,f={}]="string"===typeof a?[null,a,b]:[a,b,c];if(d){var {id:g,title:n,class:l,text:p="",rows:r,cols:v,on:w={},style:x={},attr:B={},...F}=f,h=Object.assign(document.createElement(d),{textContent:p});g&&(h.id=g);n&&(h.title=n);l&&(h.className=l);void 0!==r&&(h.rowSpan=r);void 0!==v&&(h.colSpan=v);Object.assign(h,F);Object.assign(h.style,"string"===typeof x?
{cssText:x}:x);Object.entries(B).forEach(([k,u])=>h.setAttribute(k,u));var t={};"object"===typeof w?Object.assign(t,this._on(h,w)):Array.isArray(w)&&w.forEach(k=>Object.assign(t,this._on(h,k)));Object.assign(h,{on(k,u,m){this.addEventListener(k,u,m);Object.assign(t,{[k]:()=>this.removeEventListener(k,u,m)})},off(k){t[k]?.();delete t[k]},offAll(){Object.keys(t).forEach(k=>{t[k]();delete t[k]})}});return e instanceof HTMLElement?e.appendChild(h):h}}},A=new Map,T={log:a=>console.log(a),warn:a=>console.warn(a),
trace:a=>console.trace(a),error:a=>console.error(a),count:a=>console.count(a)},P={queryMap:(a,b)=>{a=a.map(c=>q(document,c,b));return b?a.every(c=>0<c.length)&&a:a.every(Boolean)&&a},queryElement:(a,b)=>{a=q(document,a,b);return(b?0<a.length:a)&&a}},R={String:(a,b,c)=>null!=c?(a.setItem(b,JSON.stringify(c)),!0):JSON.parse(b),Number:(a,b,c)=>null!=c?(a.setItem(b,JSON.stringify(c)),!0):Number(b),Array:(a,b,c)=>null!=c?(a.setItem(b,JSON.stringify(c)),!0):(b=JSON.parse(b),Array.isArray(b[0])?new Map(b):
b),Object:(a,b,c)=>null!=c?(a.setItem(b,JSON.stringify(c)),!0):JSON.parse(b),Boolean:(a,b,c)=>null!=c?(a.setItem(b,JSON.stringify(c)),!0):JSON.parse(b),Date:(a,b,c)=>null!=c?(a.setItem(b,JSON.stringify(c)),!0):new Date(b),Map:(a,b,c)=>(a.setItem(b,JSON.stringify([...c])),!0)},L={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,M=a=>void 0===a||null===a?null:a;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(){this._cache||
(void 0!==navigator.userAgentData?.mobile?this._cache=navigator.userAgentData.mobile?"Mobile":"Desktop":window.matchMedia?.("(max-width: 767px), (pointer: coarse)")?.matches?this._cache="Mobile":/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?this._cache="Mobile":this._cache="Desktop");return this._cache}},E,{addStyle:(a,b,c=!0)=>N("style",a,b,c),addScript:(a,b,c=!0)=>N("script",a,b,c),session:(a,{value:b=null,error:c}={})=>Q(a,sessionStorage,b,c),local:(a,
{value:b=null,error:c}={})=>Q(a,localStorage,b,c),delV:a=>GM_deleteValue(a),allV:()=>M(GM_listValues()),setV:(a,b)=>GM_setValue(a,b),getV:(a,b)=>M(GM_getValue(a,b)),setJV:(a,b,c=0)=>GM_setValue(a,JSON.stringify(b,null,c)),getJV(a,b){try{return JSON.parse(M(GM_getValue(a,b)))}catch{return b}},$type:J,eventRecord:A,onE:async function(a,b,c,e={},d=null){try{"string"===typeof a&&(a=q(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 n=l=>{clearTimeout(g);g=setTimeout(()=>c(l),15)};f.forEach(l=>a.addEventListener(l,n,e))}d&&d(!0)}catch{d&&d(!1)}},onEvent:async function(a,b,c,e={}){const {mark:d,...f}=e;"string"===typeof a&&(a=q(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=q(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(r){clearTimeout(d);g||"urlchange"!==r||(g=!0);d=setTimeout(()=>{g&&e(!1,!0);a({type:r,url:location.href,domain:location.hostname})},Math.max(15,b))}function e(r=!0,v=!1){v&&f||(clearTimeout(d),history.pushState=n,history.replaceState=l,r&&window.removeEventListener("urlchange",p.urlchange),window.removeEventListener("popstate",p.popstate),window.removeEventListener("hashchange",p.hashchange),f=!0)}let d=null,f=!1,g=!1;const n=history.pushState,
l=history.replaceState,p={urlchange:()=>c("urlchange"),popstate:()=>c("popstate"),hashchange:()=>c("hashchange")};window.addEventListener("urlchange",p.urlchange);window.addEventListener("popstate",p.popstate);window.addEventListener("hashchange",p.hashchange);history.pushState=function(){n.apply(this,arguments);c("pushState")};history.replaceState=function(){l.apply(this,arguments);c("replacestate")};return{off:e}},log:async function(a=null,b="print",{dev:c=!0,type:e="log",collapsed:d=!0}={}){c&&
(c=T[e]||T.log,null==a?c(b):(d?console.groupCollapsed(a):console.group(a),c(b),console.groupEnd()))},$observer:async function(a,b,c={},e=null){const {mark:d="",debounce:f=0,throttle:g=100,subtree:n=!0,childList:l=!0,attributes:p=!0,characterData:r=!1}=c||{};if(d){if(D[d])return;D[d]=!0}const [v,w]=0<f?[H,f]:[G,g];c={subtree:n,childList:l,attributes:p,characterData:r};const x=new MutationObserver(v(()=>{b()},w));x.observe(a,c);e&&e({ob:x,op:c})},waitEl:O,$throttle:G,$debounce:H,outputJson:async function(a,
b,c=null){try{a="string"!==typeof a?JSON.stringify(a,null,4):a;b="string"!==typeof b?"Anonymous.json":b.endsWith(".json")?b:`${b}.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&&c({State:!0})}catch(e){c&&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[L[b]]??a[L[c]]??a[L["en-US"]]},regMenu:async function(a,b={}){let {name:c="Menu",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){"all"===a.toLowerCase()?([...y].map(b=>GM_unregisterMenuCommand(b)),
y.clear()):y.has(a)&&(GM_unregisterMenuCommand(a),y.delete(a))},storeListen:async function(a,b){a.forEach(c=>{D[c]||(D[c]=!0,GM_addValueChangeListener(c,function(e,d,f,g){b({key:e,ov:d,nv:f,far:g})}))})}})})();