Syntax

Library for simplifying code logic and syntax

Verzia zo dňa 30.08.2025. Pozri najnovšiu verziu.

Tento skript by nemal byť nainštalovaný priamo. Je to knižnica pre ďalšie skripty, ktorú by mali používať cez meta príkaz // @require https://update.greasyfork.org/scripts/495339/1652115/Syntax.js

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name         Syntax
// @version      2025.08.31
// @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 P(a,b,c=crypto.randomUUID(),d=!0){if(d||!H.has(c)){var e=document.getElementById(c);e||(e=
document.createElement(a),e.id=c,(a=I.head)?a.appendChild(e):Q("head").then(g=>{I.head=g;g.appendChild(e)}));e.textContent+=b;H.add(c)}}async function Q(a,b=null,c={}){const d=Array.isArray(a)?R.queryMap:R.queryElement,{raf:e=!1,all:g=!1,timeout:h=8,throttle:f=0,debounce:l=50,visibility:n=!0,subtree:k=!0,childList:q=!0,attributes:u=!0,characterData:r=!1,timeoutResult:y=!1,root:z=document}=c||{};return new Promise((m,t)=>{const p=async function(){let x,v;if(e){let A;const F=()=>{(v=d(a,g))?(cancelAnimationFrame(A),
clearTimeout(x),b?.(v),m(v)):A=requestAnimationFrame(F)};A=requestAnimationFrame(F);x=setTimeout(()=>{cancelAnimationFrame(A);y&&(b?.(v),m(v))},1E3*h)}else{const [A,F]=0<f?[J,f]:[K,l],L=new MutationObserver(A(()=>{if(v=d(a,g))L.disconnect(),clearTimeout(x),b?.(v),m(v)},F));L.observe(z,{subtree:k,childList:q,attributes:u,characterData:r});x=setTimeout(()=>{L.disconnect();y&&(b?.(v),m(v))},1E3*h)}};n&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>p(),{once:!0}):
p()})}function S(a,b,c,d){let e;return null!=c?T[B(c)](b,a,c):(e=b.getItem(a),void 0!=e?T[B(JSON.parse(e))](b,e):d)}function J(a,b){let c=0;return(...d)=>{const e=Date.now();e-c>=b&&(c=e,a(...d))}}function K(a,b){let c=null;return(...d)=>{clearTimeout(c);c=setTimeout(function(){a(...d)},b)}}function U(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 M={$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,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 I={$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,g={}]="string"===typeof a?[null,a,b]:[a,b,c];if(e){var {id:h,title:f,class:l,text:n="",rows:k,cols:q,on:u={},style:r={},attr:y={},...z}=g,m=Object.assign(document.createElement(e),
{textContent:n});h&&(m.id=h);f&&(m.title=f);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 r?{cssText:r}:r);Object.entries(y).forEach(([p,x])=>m.setAttribute(p,x));var t={};Array.isArray(u)?u.forEach(p=>Object.assign(t,this._on(m,p))):"object"===typeof u&&Object.assign(t,this._on(m,u));Object.assign(m,{on(p,x,v){this.addEventListener(p,x,v);Object.assign(t,{[p]:()=>this.removeEventListener(p,x,v)})},off(p){t[p]?.();
delete t[p]},offAll(){Object.keys(t).forEach(p=>{t[p]();delete t[p]})}});return 1===d?.nodeType?d.appendChild(m):m}}},D=new Map,W={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)},H=new Set,G=new Map,R={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}},T={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)},X={Process:(a,b,c=null)=>{a=a[b.toLowerCase()];
return"Function"===B(a)?a(c):void 0!==a?a:"None"}},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"},C=new Set,O=a=>void 0===a||null===a?null:a,E=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(){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}},I,{addStyle:(a,b,c)=>P("style",a,b,c),addScript:(a,b,c)=>P("script",a,b,c),session:(a,{value:b=null,error:c}={})=>S(a,sessionStorage,b,c),local:(a,{value:b=null,error:c}={})=>S(a,localStorage,b,c),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:D,addRecord:H,observerRecord:G,$type:B,onE:async function(a,b,c,d={},e=null){try{"string"===typeof a&&(a=w(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,d);else{let h=null;const f=l=>{clearTimeout(h);h=setTimeout(()=>c(l),15)};g.forEach(l=>a.addEventListener(l,f,d))}e?.(!0)}catch{e?.(!1)}},onEvent:async function(a,b,c,d={}){const {mark:e,...g}=d;"string"===typeof a&&(a=w(document,
a));d=e??a;const h=D.get(d);h?.has(b)||(a.addEventListener(b,c,g),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&&g||(clearTimeout(e),history.pushState=
f,history.replaceState=l,k&&window.removeEventListener("urlchange",n.urlchange),window.removeEventListener("popstate",n.popstate),window.removeEventListener("hashchange",n.hashchange),g=!0)}let e=null,g=!1,h=!1;const f=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(){f.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=W[d]||W.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:g=0,throttle:h=100,subtree:f=!0,childList:l=!0,attributes:n=!0,characterData:k=!1}=c||{};if(e&&(c=G.get(e))){if(c.target===
a)return;c.ob.disconnect();G.delete(e)}const [q,u]=0<g?[K,g]:[J,h];c={subtree:f,childList:l,attributes:n,characterData:k};const r=new MutationObserver(q(()=>{b()},u));r.observe(a,c);e&&G.set(e,{target:a,ob:r});d?.({ob:r,op:c})},waitEl:Q,$throttle:J,$debounce:K,scopeParse:function(a,b){if("string"!==typeof a||""===a.trim())return b;const c=b.length,d=new Set,e=new Set,g=(f,l,n)=>{const k=f<=l;for(;k?f<=l:f>=l;k?f++:f--)n.add(f)};let h;for(h of a.split(/\s*[\.,|/]\s*/))if(/^(!|-)?\d+(~\d+|-\d+)?$/.test(h)){a=
h.slice(1);const f=/^[!-]/.test(h),l=/[~-]/.test(a),[n,k]=f?[e,a]:[d,h],[q,u]=l?k.split(/-|~/):[k,k];q==u?n.add(+q-1):g(+q-1,+u-1,n)}return[...d].filter(f=>!e.has(f)&&f<c&&0<=f).sort((f,l)=>f-l).map(f=>b[f])},workerCreate:U,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)=>X.Process(a,d)):"Object"===B(b)?Object.entries(b).map(([c,
d])=>X.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 g=0,h=0;Object.entries(c).forEach(([n,k])=>{k=k.length;h+=k;n=("."+n.split(".").pop()).toLowerCase();52428800<k&&e.has(n)?g+=k/104857600:(n=k/26214400,
k/=1048576,10<k&&(n*=1+.1*Math.log10(k/10)),g+=n)});var f=Object.keys(c).length;1<f&&(g+=.01*f);f=h/1048576;100<f&&(g*=1+.05*Math.log10(f/100));var l=50>f?5:500>f?4:3;return{estimatedInMs:1E3*g,progressCurve:n=>100*(1-Math.exp(-l*n))/(1-Math.exp(-l))}}let b=U("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,g){const h=new Promise(async f=>{const l=await g.arrayBuffer();c[e]=new Uint8Array(l);f()});d.push(h);return h},async generateZip(e={},g){await Promise.all(d);const h=performance.now(),f=a(),l=f.estimatedInMs,n=setInterval(()=>{var k=performance.now()-h;k=Math.min(k/l,.99);const q=f.progressCurve(k);g&&g(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);g&&g(100);c={};d=[];const {error:r,data:y}=u.data;r?q(r):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:t,saveData:p}=navigator.connection;z="4g"!==t||p?"3g"===t||"4g"===t&&p?"normal":"poor":"good"}else 5<=r.length&&(m=r.reduce((t,p)=>t+p,0)/r.length,z=m<
g?"good":m>h?"poor":"normal");return z}let {MAX_Delay:c=2E3,MIN_CONCURRENCY:d=1,MAX_CONCURRENCY:e=16,Good_Network_THRESHOLD:g=500,Poor_Network_THRESHOLD:h=1500,adaptiveFactors:f={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:r=[],lastNetworkCheck:y=0,networkCondition:z="normal"}={};return function(m,
t,p=null,x=0){m=Date.now()-m;r.push(m);r.length>u&&r.shift();l=!l||1>=r.length?m:k*m+(1-k)*l;l=Math.max(20,Math.min(2E3,l));const {delayFactor:v,threadFactor:A}=f[b()];m/=l;t=Math.max(x,Math.min(t*(1+(m-1)*q*v),c));return null!==p?[Math.round(t),Math.round(Math.max(d,Math.min(p*(1-(m-1)*q*A),e)))]:Math.round(t)}},outputTXT:async function(a,b,c=null){try{b="string"!==typeof b?`Untitled-${crypto.randomUUID().slice(9,23)}.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?.({State:!0})}catch(d){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?`Untitled-${crypto.randomUUID().slice(9,23)}.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?.({State:!0})}catch(d){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,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[N[b]]??a[N[c]]??a[N["en-US"]]},regMenu:function(a,b={}){let {name:c="regMenu",index:d=1,reset:e=!1}=b||{};e&&([...C].map(g=>GM_unregisterMenuCommand(g)),C.clear());for(let [g,h]of Object.entries(a))a=`${c}-${d++}`,
"function"===typeof h&&(h={func:h}),GM_registerMenuCommand(g,()=>{h.func()},{id:a,title:h.desc,autoClose:h.close,accessKey:h.hotkey}),C.add(a)},unMenu:async function(a){null==a?([...C].map(b=>GM_unregisterMenuCommand(b)),C.clear()):Array.isArray(a)?a.forEach(b=>{C.delete(b)&&GM_unregisterMenuCommand(b)}):C.delete(a)&&GM_unregisterMenuCommand(a)},storeListen:function(a,b){a.forEach(c=>{if(!E.has(c)){const d=GM_addValueChangeListener(c,function(e,g,h,f){b({key:e,ov:g,nv:h,far:f})});E.set(c,d)}});return{off(c){const d=
E.get(c);d&&(GM_removeValueChangeListener(d),E.delete(c))},offAll(){for(const c of E.values())GM_removeValueChangeListener(c);E.clear()}}},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)}})})();