Syntax

Library for simplifying code logic and syntax

От 04.09.2025. Виж последната версия.

Този скрипт не може да бъде инсталиран директно. Това е библиотека за други скриптове и може да бъде използвана с мета-директива // @require https://update.greasyfork.org/scripts/495339/1654307/Syntax.js

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         Syntax
// @version      2025.09.04
// @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(h=>{I.head=h;h.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:h=!1,timeout:f=8,throttle:g=0,debounce:k=50,visibility:l=!0,subtree:p=!0,childList:r=!0,attributes:v=!0,characterData:t=!1,timeoutResult:A=!1,root:y=document}=c||{};return new Promise((m,q)=>{const n=async function(){let x,u;if(e){let z;const F=()=>{(u=d(a,h))?(cancelAnimationFrame(z),
clearTimeout(x),b?.(u),m(u)):z=requestAnimationFrame(F)};z=requestAnimationFrame(F);x=setTimeout(()=>{cancelAnimationFrame(z);A&&(b?.(u),m(u))},1E3*f)}else{const [z,F]=0<g?[J,g]:[K,k],L=new MutationObserver(z(()=>{if(u=d(a,h))L.disconnect(),clearTimeout(x),b?.(u),m(u)},F));L.observe(y,{subtree:p,childList:r,attributes:v,characterData:t});x=setTimeout(()=>{L.disconnect();A&&(b?.(u),m(u))},1E3*f)}};l&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>n(),{once:!0}):
n()})}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"});const b=URL.createObjectURL(a),c=new Worker(b),d=c.terminate;c.terminate=function(){d.call(c);URL.revokeObjectURL(b)};return c}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,h={}]="string"===typeof a?[null,a,b]:[a,
b,c];if(e){var {id:f,title:g,class:k,text:l="",rows:p,cols:r,on:v={},style:t={},attr:A={},...y}=h,m=Object.assign(document.createElement(e),{textContent:l});f&&(m.id=f);g&&(m.title=g);k&&(m.className=k);void 0!==p&&(m.rowSpan=p);void 0!==r&&(m.colSpan=r);Object.assign(m,y);Object.assign(m.style,"string"===typeof t?{cssText:t}:t);Object.entries(A).forEach(([n,x])=>m.setAttribute(n,x));var q={};Array.isArray(v)?v.forEach(n=>Object.assign(q,this._on(m,n))):"object"===typeof v&&Object.assign(q,this._on(m,
v));Object.assign(m,{on(n,x,u){this.addEventListener(n,x,u);Object.assign(q,{[n]:()=>this.removeEventListener(n,x,u)})},off(n){q[n]?.();delete q[n]},offAll(){Object.keys(q).forEach(n=>{q[n]();delete q[n]})}});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 h=b.split(/\s*[,|/]\s*/).filter(Boolean);if(0===h.length)throw Error("No event types provided");if(1===h.length)a.addEventListener(b,c,d);else{let f=null;const g=k=>{clearTimeout(f);
f=setTimeout(()=>c(k),15)};h.forEach(k=>a.addEventListener(k,g,d))}e?.(!0)}catch{e?.(!1)}},onEvent:async function(a,b,c,d={}){const {mark:e,...h}=d;"string"===typeof a&&(a=w(document,a));d=e??a;const f=D.get(d);f?.has(b)||(a.addEventListener(b,c,h),f||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(p){clearTimeout(e);
f||"urlchange"!==p||(f=!0);e=setTimeout(()=>{f&&d(!1,!0);a({type:p,url:location.href,domain:location.hostname})},Math.max(15,b))}function d(p=!0,r=!1){r&&h||(clearTimeout(e),history.pushState=g,history.replaceState=k,p&&window.removeEventListener("urlchange",l.urlchange),window.removeEventListener("popstate",l.popstate),window.removeEventListener("hashchange",l.hashchange),h=!0)}let e=null,h=!1,f=!1;const g=history.pushState,k=history.replaceState,l={urlchange:()=>c("urlchange"),popstate:()=>c("popstate"),
hashchange:()=>c("hashchange")};window.addEventListener("urlchange",l.urlchange);window.addEventListener("popstate",l.popstate);window.addEventListener("hashchange",l.hashchange);history.pushState=function(){g.apply(this,arguments);c("pushState")};history.replaceState=function(){k.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:h=0,throttle:f=100,subtree:g=!0,childList:k=!0,attributes:l=!0,characterData:p=!1}=c||{};if(e&&(c=G.get(e))){if(c.target===a)return;c.ob.disconnect();G.delete(e)}const [r,v]=0<h?[K,h]:[J,f];c={subtree:g,childList:k,attributes:l,characterData:p};const t=new MutationObserver(r(()=>{b()},v));t.observe(a,c);e&&G.set(e,{target:a,ob:t});d?.({ob:t,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,h=(g,k,l)=>{const p=g<=k;for(;p?g<=k:g>=k;p?g++:g--)l.add(g)};let f;for(f of a.split(/\s*[\.,|/]\s*/))if(/^(!|-)?\d+(~\d+|-\d+)?$/.test(f)){a=f.slice(1);const g=/^[!-]/.test(f),k=/[~-]/.test(a),[l,p]=g?[e,a]:[d,f],[r,v]=k?p.split(/-|~/):[p,p];r==v?l.add(+r-1):h(+r-1,+v-1,l)}return[...d].filter(g=>!e.has(g)&&g<c&&0<=g).sort((g,k)=>g-k).map(g=>b[g])},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(){let a=U('importScripts("https://cdn.jsdelivr.net/npm/[email protected]/umd/index.min.js");onmessage = function(e) {const { filesWithOptions } = e.data;const fileNames = Object.keys(filesWithOptions);let totalSize = 0;let processedSize = 0;fileNames.forEach(name => {totalSize += filesWithOptions[name].data.length;});const chunks = [];const zip = new fflate.Zip((err, data, final) => {if (err) {postMessage({ type: "error", error: err.message });return;}chunks.push(data);if (final) {let size = 0;let offset = 0;chunks.forEach(c => size += c.length);const zipped = new Uint8Array(size);chunks.forEach(c => {zipped.set(c, offset);offset += c.length;});postMessage({ type: "done", data: zipped }, [zipped.buffer]);}});(async () => {for (const name of fileNames) {const { data, level } = filesWithOptions[name];const fileStream = new fflate.ZipPassThrough(name, { level });zip.add(fileStream);fileStream.push(data, true);processedSize += data.length;postMessage({ type: "progress", loaded: processedSize, total: totalSize });} zip.end();})().catch(err => {postMessage({ type: "error", error: err.message });});}');
const b=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 .pg jpeg png gif webp bmp tiff tif svg .eic heif raw ico psd mp3 aac flac wav ogg pdf".split(" "));let c={},d=[];return{async destroyWorker(){a&&(a.terminate(),a=null)},async file(e,h){const f=new Promise(async g=>{const k=await h.arrayBuffer();c[e]=new Uint8Array(k);g()});d.push(f);return f},async generateZip(e={},h){await Promise.all(d);return new Promise((f,g)=>{if(0===Object.keys(c).length)return g("Empty Data Error");
const k={};Object.entries(c).forEach(([l,p])=>{var r=l.split(".").pop().toLowerCase();r=b.has(r)?0:e.level||5;k[l]={data:p,level:r}});a.postMessage({filesWithOptions:k},Object.values(k).map(l=>l.data.buffer));a.onmessage=l=>{l=l.data;"progress"===l.type?h?.(l.loaded/l.total*100):"done"===l.type?(h?.(100),c={},d=[],f(new Blob([l.data],{type:"application/zip"}))):"error"===l.type&&(c={},d=[],g(l.error))}})}}},createNnetworkObserver:function(a={}){function b(){var m=Date.now();if(m-A<l)return y;A=m;
if(navigator.connection){const {effectiveType:q,saveData:n}=navigator.connection;y="4g"!==q||n?"3g"===q||"4g"===q&&n?"normal":"poor":"good"}else 5<=t.length&&(m=t.reduce((q,n)=>q+n,0)/t.length,y=m<h?"good":m>f?"poor":"normal");return y}let {MAX_Delay:c=2E3,MIN_CONCURRENCY:d=1,MAX_CONCURRENCY:e=16,Good_Network_THRESHOLD:h=500,Poor_Network_THRESHOLD:f=1500,adaptiveFactors:g={good:{delayFactor:.8,threadFactor:1.2},normal:{delayFactor:1,threadFactor:1},poor:{delayFactor:1.5,threadFactor:.7}},TIME_THRESHOLD:k=
1E3,Network_Check_Interval:l=1E4,EMA_ALPHA:p=.3,ADJUSTMENT_FACTOR:r=.25,History_Size:v=10}=a||{},{responseHistory:t=[],lastNetworkCheck:A=0,networkCondition:y="normal"}={};return function(m,q,n=null,x=0){m=Date.now()-m;t.push(m);t.length>v&&t.shift();k=!k||1>=t.length?m:p*m+(1-p)*k;k=Math.max(20,Math.min(2E3,k));const {delayFactor:u,threadFactor:z}=g[b()];m/=k;q=Math.max(x,Math.min(q*(1+(m-1)*r*u),c));return null!==n?[Math.round(q),Math.round(Math.max(d,Math.min(n*(1-(m-1)*r*z),e)))]:Math.round(q)}},
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,h)=>c[h]??"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(h=>GM_unregisterMenuCommand(h)),C.clear());for(let [h,f]of Object.entries(a))a=`${c}-${d++}`,"function"===typeof f&&(f={func:f}),GM_registerMenuCommand(h,()=>{f.func()},{id:a,title:f.desc,autoClose:f.close,accessKey:f.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,h,f,g){b({key:e,ov:h,nv:f,far:g})});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)}})})();