Syntax

Library for simplifying code logic and syntax

Versione datata 22/08/2025. Vedi la nuova versione l'ultima versione.

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/495339/1647210/Syntax.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Syntax
// @version      2025.08.23
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax
// @namespace    https://greasyfork.org/users/989635
// @match        *://*/*
// @license      MPL-2.0
// ==/UserScript==
const Lib=(()=>{function w(a=document,b,c){if(1!==a?.nodeType&&9!==a?.nodeType)return c?[]:void 0;const d=b[0],e=b.slice(1);if(/[ .#:[\]>+~*,()^$=]/.test(e))return c?a.querySelectorAll(b):a.querySelector(b);if(!c&&"#"===d)return 9===a.nodeType?a.getElementById(e):a.querySelector(b);if("."===b[0])return a=a.getElementsByClassName(e),c?[...a]:a[0];a=a.getElementsByTagName(b);return c?[...a]:a[0]}async function M(a,b,c=crypto.randomUUID(),d=!0){if(d||!N.has(c)){var e=document.getElementById(c);e||(e=
document.createElement(a),e.id=c,(a=F.head)?a.appendChild(e):O("head").then(f=>{F.head=f;f.appendChild(e)}));e.textContent+=b;N.add(c)}}async function O(a,b=null,c={}){const d=Array.isArray(a)?P.queryMap:P.queryElement,{raf:e=!1,all:f=!1,timeout:h=8,throttle:g=0,debounce:l=50,visibility:n=!0,subtree:k=!0,childList:q=!0,attributes:u=!0,characterData:t=!1,timeoutResult:y=!1,root:z=document}=c||{};return new Promise((m,r)=>{const p=async function(){let x,v;if(e){let A;const E=()=>{(v=d(a,f))?(cancelAnimationFrame(A),
clearTimeout(x),b&&b(v),m(v)):A=requestAnimationFrame(E)};A=requestAnimationFrame(E);x=setTimeout(()=>{cancelAnimationFrame(A);y&&(b&&b(v),m(v))},1E3*h)}else{const [A,E]=0<g?[G,g]:[H,l],I=new MutationObserver(A(()=>{if(v=d(a,f))I.disconnect(),clearTimeout(x),b&&b(v),m(v)},E));I.observe(z,{subtree:k,childList:q,attributes:u,characterData:t});x=setTimeout(()=>{I.disconnect();y&&(b&&b(v),m(v))},1E3*h)}};n&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>p(),{once:!0}):
p()})}function Q(a,b,c,d){let e;return null!=c?R[B(c)](b,a,c):(e=b.getItem(a),void 0!=e?R[B(JSON.parse(e))](b,e):d)}function G(a,b){let c=0;return(...d)=>{const e=Date.now();e-c>=b&&(c=e,a(...d))}}function H(a,b){let c=null;return(...d)=>{clearTimeout(c);c=setTimeout(function(){a(...d)},b)}}function S(a){a=new Blob([a],{type:"application/javascript"});return new Worker(URL.createObjectURL(a))}const Y=new DOMParser,B=a=>Object.prototype.toString.call(a).slice(8,-1);[Document.prototype,Element.prototype].forEach(a=>
{a.$q=function(b){return w(this,b,!1)};a.$qa=function(b){return w(this,b,!0)}});const J={$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,J);const T=Object.keys(J)[0];Object.defineProperty(Object.prototype,T,{value:function(a=null){return J[T].call(this,a)},writable:!0,configurable:!0});const F={$q:document.$q.bind(document),$Q:(a,b)=>w(a,b,!1),$qa:document.$qa.bind(document),$Qa:(a,b)=>w(a,b,!0),html:document.documentElement,
head:document.head??w(document,"head",!1),body:document.body??w(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:d})=>"string"===typeof b&&"function"===typeof c?(a.addEventListener(b,c,d),{[b]:()=>a.removeEventListener(b,c,d)}):{},createElement(a,b,c){const [d,e,f={}]="string"===typeof a?[null,a,b]:[a,b,c];if(e){var {id:h,title:g,class:l,text:n="",rows:k,cols:q,on:u={},style:t={},attr:y={},...z}=f,m=Object.assign(document.createElement(e),
{textContent:n});h&&(m.id=h);g&&(m.title=g);l&&(m.className=l);void 0!==k&&(m.rowSpan=k);void 0!==q&&(m.colSpan=q);Object.assign(m,z);Object.assign(m.style,"string"===typeof t?{cssText:t}:t);Object.entries(y).forEach(([p,x])=>m.setAttribute(p,x));var r={};Array.isArray(u)?u.forEach(p=>Object.assign(r,this._on(m,p))):"object"===typeof u&&Object.assign(r,this._on(m,u));Object.assign(m,{on(p,x,v){this.addEventListener(p,x,v);Object.assign(r,{[p]:()=>this.removeEventListener(p,x,v)})},off(p){r[p]?.();
delete r[p]},offAll(){Object.keys(r).forEach(p=>{r[p]();delete r[p]})}});return 1===d?.nodeType?d.appendChild(m):m}}},D=new Map,U={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)},N=new Set,V=new Set,P={queryMap:(a,b)=>{a=a.map(c=>w(document,c,b));return b?a.every(c=>0<c.length)&&a:a.every(Boolean)&&a},queryElement:(a,b)=>{a=w(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)},W={Process:(a,b,c=null)=>{a=a[b.toLowerCase()];
return"Function"===B(a)?a(c):void 0!==a?a:"None"}},K={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"},C=new Set,L=a=>void 0===a||null===a?null:a,X=new Set;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}},F,{addStyle:(a,b,c)=>M("style",a,b,c),addScript:(a,b,c)=>M("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:()=>L(GM_listValues()),setV:(a,b)=>GM_setValue(a,b),getV:(a,b)=>L(GM_getValue(a,b)),setJV:(a,b,c=0)=>GM_setValue(a,JSON.stringify(b,null,c)),getJV(a,b){try{return JSON.parse(L(GM_getValue(a,b)))}catch{return b}},
$type:B,eventRecord:D,onE:async function(a,b,c,d={},e=null){try{"string"===typeof a&&(a=w(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,d);else{let h=null;const g=l=>{clearTimeout(h);h=setTimeout(()=>c(l),15)};f.forEach(l=>a.addEventListener(l,g,d))}e&&e(!0)}catch{e&&e(!1)}},onEvent:async function(a,b,c,d={}){const {mark:e,...f}=d;"string"===typeof a&&(a=w(document,a));d=e??a;const h=D.get(d);
h?.has(b)||(a.addEventListener(b,c,f),h||D.set(d,new Map),D.get(d).set(b,c))},offEvent:async function(a,b,c){"string"===typeof a&&(a=w(document,a));c=c??a;const d=D.get(c)?.get(b);d&&(a.removeEventListener(b,d),D.get(c).delete(b))},onUrlChange:function(a,b=15){function c(k){clearTimeout(e);h||"urlchange"!==k||(h=!0);e=setTimeout(()=>{h&&d(!1,!0);a({type:k,url:location.href,domain:location.hostname})},Math.max(15,b))}function d(k=!0,q=!1){q&&f||(clearTimeout(e),history.pushState=g,history.replaceState=
l,k&&window.removeEventListener("urlchange",n.urlchange),window.removeEventListener("popstate",n.popstate),window.removeEventListener("hashchange",n.hashchange),f=!0)}let e=null,f=!1,h=!1;const g=history.pushState,l=history.replaceState,n={urlchange:()=>c("urlchange"),popstate:()=>c("popstate"),hashchange:()=>c("hashchange")};window.addEventListener("urlchange",n.urlchange);window.addEventListener("popstate",n.popstate);window.addEventListener("hashchange",n.hashchange);history.pushState=function(){g.apply(this,
arguments);c("pushState")};history.replaceState=function(){l.apply(this,arguments);c("replacestate")};return{off:d}},log:async function(a=null,b="print",{dev:c=!0,type:d="log",collapsed:e=!0}={}){c&&(c=U[d]||U.log,null==a?c(b):(e?console.groupCollapsed(a):console.group(a),c(b),console.groupEnd()))},$observer:async function(a,b,c={},d=null){const {mark:e="",debounce:f=0,throttle:h=100,subtree:g=!0,childList:l=!0,attributes:n=!0,characterData:k=!1}=c||{};if(e){if(V.has(e))return;V.add(e)}const [q,u]=
0<f?[H,f]:[G,h];c={subtree:g,childList:l,attributes:n,characterData:k};const t=new MutationObserver(q(()=>{b()},u));t.observe(a,c);d&&d({ob:t,op:c})},waitEl:O,$throttle:G,$debounce:H,scopeParse:function(a,b){if("string"!==typeof a||""===a.trim())return b;const c=b.length,d=new Set,e=new Set,f=(g,l,n)=>{const k=g<=l;for(;k?g<=l:g>=l;k?g++:g--)n.add(g)};let h;for(h of a.split(/\s*[\.,|/]\s*/))if(/^(!|-)?\d+(~\d+|-\d+)?$/.test(h)){a=h.slice(1);const g=/^[!-]/.test(h),l=/[~-]/.test(a),[n,k]=g?[e,a]:[d,
h],[q,u]=l?k.split(/-|~/):[k,k];q==u?n.add(+q-1):f(+q-1,+u-1,n)}return[...d].filter(g=>!e.has(g)&&g<c&&0<=g).sort((g,l)=>g-l).map(g=>b[g])},workerCreate:S,formatTemplate:function(a,b){if("Object"!==B(a))return"Template must be an object";a=Object.fromEntries(Object.entries(a).map(([c,d])=>[c.toLowerCase(),d]));return"String"===B(b)?b.replace(/\{\s*([^}\s]+)\s*\}/g,(c,d)=>W.Process(a,d)):"Object"===B(b)?Object.entries(b).map(([c,d])=>W.Process(a,c,d)):{"Unsupported format":b}},createCompressor:function(){function a(){const e=
new Set(".mp4 .mov .avi .mkv .flv .wmv .webm .mpg .mpeg .m4v .ogv .3gp .asf .ts .vob .rm .rmvb .m2ts .f4v .mts .zip .rar .7z .gz .bz2 .jpg .jpeg .png .gif .webp .bmp .tiff .tif .svg .heic .heif .raw .ico .psd .mp3 .aac .flac .wav .ogg .pdf".split(" "));let f=0,h=0;Object.entries(c).forEach(([n,k])=>{k=k.length;h+=k;n=("."+n.split(".").pop()).toLowerCase();52428800<k&&e.has(n)?f+=k/104857600:(n=k/26214400,k/=1048576,10<k&&(n*=1+.1*Math.log10(k/10)),f+=n)});var g=Object.keys(c).length;1<g&&(f+=.01*
g);g=h/1048576;100<g&&(f*=1+.05*Math.log10(g/100));var l=50>g?5:500>g?4:3;return{estimatedInMs:1E3*f,progressCurve:n=>100*(1-Math.exp(-l*n))/(1-Math.exp(-l))}}let b=S("importScripts('https://cdn.jsdelivr.net/npm/[email protected]/umd/index.min.js');onmessage = function(e) {    const { files, level } = e.data;    try {        const zipped = fflate.zipSync(files, { level });        postMessage({ data: zipped }, [zipped.buffer]);    } catch (err) {        postMessage({ error: err.message });    }}"),
c={},d=[];return{async destroyWorker(){b&&(b.terminate(),b=null)},async file(e,f){const h=new Promise(async g=>{const l=await f.arrayBuffer();c[e]=new Uint8Array(l);g()});d.push(h);return h},async generateZip(e={},f){await Promise.all(d);const h=performance.now(),g=a(),l=g.estimatedInMs,n=setInterval(()=>{var k=performance.now()-h;k=Math.min(k/l,.99);const q=g.progressCurve(k);f&&f(q);.99<=k&&clearInterval(n)},30);return new Promise((k,q)=>{if(0===Object.keys(c).length)return q("Empty Data Error");
b.postMessage({files:c,level:e.level||5},Object.values(c).map(u=>u.buffer));b.onmessage=u=>{clearInterval(n);f&&f(100);c={};d=[];const {error:t,data:y}=u.data;t?q(t):k(new Blob([y],{type:"application/zip"}))}})}}},createNnetworkObserver:function(a={}){function b(){var m=Date.now();if(m-y<n)return z;y=m;if(navigator.connection){const {effectiveType:r,saveData:p}=navigator.connection;z="4g"!==r||p?"3g"===r||"4g"===r&&p?"normal":"poor":"good"}else 5<=t.length&&(m=t.reduce((r,p)=>r+p,0)/t.length,z=m<
f?"good":m>h?"poor":"normal");return z}let {MAX_Delay:c=2E3,MIN_CONCURRENCY:d=1,MAX_CONCURRENCY:e=16,Good_Network_THRESHOLD:f=500,Poor_Network_THRESHOLD:h=1500,adaptiveFactors:g={good:{delayFactor:.8,threadFactor:1.2},normal:{delayFactor:1,threadFactor:1},poor:{delayFactor:1.5,threadFactor:.7}},TIME_THRESHOLD:l=1E3,Network_Check_Interval:n=1E4,EMA_ALPHA:k=.3,ADJUSTMENT_FACTOR:q=.25,History_Size:u=10}=a||{},{responseHistory:t=[],lastNetworkCheck:y=0,networkCondition:z="normal"}={};return function(m,
r,p=null,x=0){m=Date.now()-m;t.push(m);t.length>u&&t.shift();l=!l||1>=t.length?m:k*m+(1-k)*l;l=Math.max(20,Math.min(2E3,l));const {delayFactor:v,threadFactor:A}=g[b()];m/=l;r=Math.max(x,Math.min(r*(1+(m-1)*q*v),c));return null!==p?[Math.round(r),Math.round(Math.max(d,Math.min(p*(1-(m-1)*q*A),e)))]:Math.round(r)}},outputTXT:async function(a,b,c=null){try{b="string"!==typeof b?"Anonymous.txt":b.endsWith(".txt")?b:`${b}.txt`;const d=new Blob([a],{type:"text/plain"}),e=document.createElement("a");e.href=
URL.createObjectURL(d);e.download=b;e.click();URL.revokeObjectURL(e.href);e.remove();c&&c({State:!0})}catch(d){c&&c({State:!1,Info:d})}},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 d=new Blob([a],{type:"application/json"}),e=document.createElement("a");e.href=URL.createObjectURL(d);e.download=b;e.click();URL.revokeObjectURL(e.href);e.remove();c&&c({State:!0})}catch(d){c&&c({State:!1,
Info:d})}},runTime:function(a=null,{lable:b="Elapsed Time:",log:c=!0,format:d=!0,style:e="\u001b[1m\u001b[36m%s\u001b[0m"}={}){if(!a)return performance.now();a=d?`${((performance.now()-a)/1E3).toPrecision(3)}s`:performance.now()-a;return c?console.log(e,`${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(d=>d.replace(/{([^}]+)}/g,(e,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[K[b]]??a[K[c]]??a[K["en-US"]]},regMenu:function(a,b={}){let {name:c="regMenu",index:d=1,reset:e=!1}=b||{};e&&([...C].map(f=>GM_unregisterMenuCommand(f)),C.clear());for(let [f,h]of Object.entries(a))a=`${c}-${d++}`,"function"===typeof h&&(h={func:h}),GM_registerMenuCommand(f,()=>{h.func()},{id:a,title:h.desc,
autoClose:h.close,accessKey:h.hotkey}),C.add(a)},unMenu:async function(a){"all"===a.toLowerCase()?([...C].map(b=>GM_unregisterMenuCommand(b)),C.clear()):C.has(a)&&(GM_unregisterMenuCommand(a),C.delete(a))},storeListen:async function(a,b){a.forEach(c=>{X.has(c)||(X.add(c),GM_addValueChangeListener(c,function(d,e,f,h){b({key:d,ov:e,nv:f,far:h})}))})},sleep:a=>new Promise(b=>setTimeout(b,a)),domParse:a=>Y.parseFromString(a,"text/html"),nameFilter:a=>a.replace(/[\/\?<>\\:\*\|":]/g,"").trim(),getFill:a=>
Math.max(2,`${a}`.length),suffixName(a,b="webp"){try{if(!a)return b;const c=new URL(a,location.href);a=/\.([^.]+)$/;return(c.pathname.match(a)?.[1]||c.search.match(a)?.[1])?.toLowerCase().trim()||b}catch{return b}},mantissa(a,b,c="0",d=null){return d?`${++a}`.padStart(b,c)+`.${this.suffixName(d)}`:`${++a}`.padStart(b,c)}})})();