Syntax

Library for simplifying code logic and syntax

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Syntax
// @version      2025/05/28
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax
// @namespace    https://greasyfork.org/users/989635
// @match        *://*/*
// @license      MPL-2.0
// ==/UserScript==
const Syn=(()=>{function u(a=document,b,c){const d=b[0],e=b.slice(1);if(/[ #.\[:]/.test(e))return c?a.querySelectorAll(b):a.querySelector(b);if(!c&&"#"===d)return document.getElementById(e);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,d){let e=document.getElementById(c);if(!e)e=document.createElement(a),e.id=c,document.head.appendChild(e);else if(!d)return;e.textContent+=b}function N(a,b,c,d){let e;return null!=
c?O[y(c)](b,a,c):(e=b.getItem(a),void 0!=e?O[y(JSON.parse(e))](b,e):d)}function E(a,b){let c=0;return(...d)=>{const e=Date.now();e-c>=b&&(c=e,a(...d))}}function F(a,b){let c=null;return(...d)=>{clearTimeout(c);c=setTimeout(function(){a(...d)},b)}}const B={},S=new DOMParser,y=a=>Object.prototype.toString.call(a).slice(8,-1);[Document.prototype,Element.prototype].forEach(a=>{a.$q=function(b){return u(this,b,!1)};a.$qa=function(b){return u(this,b,!0)}});const G={$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,G);const P=Object.keys(G)[0];Object.defineProperty(Object.prototype,P,{value:function(a=null){return G[P].call(this,a)},writable:!0,configurable:!0});const T={$q:document.$q.bind(document),$Q:(a,b)=>u(a,b,!1),$qa:document.$qa.bind(document),$Qa:(a,b)=>u(a,b,!0),html:document.documentElement,head:document.head,body:document.body,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:l,text:k="",rows:m,cols:r,on:t={},style:x={},attr:C={},...H}=h,n=Object.assign(document.createElement(e),{textContent:k});f&&(n.id=f);g&&(n.title=g);l&&(n.className=l);void 0!==m&&(n.rowSpan=m);void 0!==r&&(n.colSpan=r);Object.assign(n,H);Object.assign(n.style,
"string"===typeof x?{cssText:x}:x);Object.entries(C).forEach(([p,v])=>n.setAttribute(p,v));var w={};"object"===typeof t?Object.assign(w,this._on(n,t)):Array.isArray(t)&&t.forEach(p=>Object.assign(w,this._on(n,p)));Object.assign(n,{on(p,v,q){this.addEventListener(p,v,q);Object.assign(w,{[p]:()=>this.removeEventListener(p,v,q)})},off(p){w[p]?.();delete w[p]},offAll(){Object.keys(w).forEach(p=>{w[p]();delete w[p]})}});return d instanceof HTMLElement?d.appendChild(n):n}}},z=new Map,Q={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)};var U=(a,b)=>{a=a.map(c=>u(document,c,b));return b?a.every(c=>0<c.length)&&a:a.every(Boolean)&&a},V=(a,b)=>{a=u(document,a,b);return(b?0<a.length:a)&&a};const O={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)},R={Process:(a,b,c=null)=>{a=a[b.toLowerCase()];return"Function"===y(a)?a(c):void 0!==a?a:"None"}},I={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"},J=new Set,K=a=>void 0===a||null===a?null:a;return{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},...T,AddStyle:(a,b,c=!0)=>M("style",a,b,c),AddScript:(a,b,c=!0)=>M("script",a,b,c),Session:(a,{value:b=null,error:c}={})=>N(a,sessionStorage,b,c),Local:(a,{value:b=
null,error:c}={})=>N(a,localStorage,b,c),dV:a=>GM_deleteValue(a),lV:()=>K(GM_listValues()),sV:(a,b)=>GM_setValue(a,b),gV:(a,b)=>K(GM_getValue(a,b)),sJV:(a,b,c=0)=>GM_setValue(a,JSON.stringify(b,null,c)),gJV:(a,b)=>{try{return JSON.parse(K(GM_getValue(a,b)))}catch{return b}},Type:y,EventRecord:z,one:async function(a,b,c,d={},e=null){try{let h=b.split(/\s*[,|/]\s*/).filter(Boolean),f=null,g=1<h.length?15:0;const l=k=>{clearTimeout(f);f=setTimeout(()=>c(k),g)};"string"===typeof a&&(a=u(document,a));
h.forEach(k=>a.addEventListener(k,l,d));e&&e(!0)}catch{e&&e(!1)}},onEvent:async function(a,b,c,d={}){const {mark:e,...h}=d;"string"===typeof a&&(a=u(document,a));d=e??a;const f=z.get(d);f?.has(b)||(a.addEventListener(b,c,h),f||z.set(d,new Map),z.get(d).set(b,c))},offEvent:async function(a,b,c){"string"===typeof a&&(a=u(document,a));c=c??a;const d=z.get(c)?.get(b);d&&(a.removeEventListener(b,d),z.get(c).delete(b))},onUrlChange:function(a,b=15){function c(m){clearTimeout(e);f||"urlchange"!==m||(f=!0);
e=setTimeout(()=>{f&&d(!1,!0);a({type:m,url:location.href,domain:location.hostname})},Math.max(15,b))}function d(m=!0,r=!1){r&&h||(clearTimeout(e),history.pushState=g,history.replaceState=l,m&&window.removeEventListener("urlchange",k.urlchange),window.removeEventListener("popstate",k.popstate),window.removeEventListener("hashchange",k.hashchange),h=!0)}let e=null,h=!1,f=!1;const g=history.pushState,l=history.replaceState,k={urlchange:()=>c("urlchange"),popstate:()=>c("popstate"),hashchange:()=>c("hashchange")};
window.addEventListener("urlchange",k.urlchange);window.addEventListener("popstate",k.popstate);window.addEventListener("hashchange",k.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=Q[d]||Q.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:l=!0,attributes:k=!0,characterData:m=!1}=c??{};if(e){if(B[e])return;B[e]=!0}const [r,t]=0<h?[F,h]:[E,f];c={subtree:g,childList:l,attributes:k,characterData:m};const x=new MutationObserver(r(()=>{b()},t));x.observe(a,c);d&&d({ob:x,op:c})},WaitElem:async function(a,b=null,c={}){const d=Array.isArray(a)?U:V,{raf:e=!1,all:h=!1,timeout:f=8,throttle:g=0,debounce:l=50,visibility:k=!0,subtree:m=!0,childList:r=!0,attributes:t=
!0,characterData:x=!1,timeoutResult:C=!1,root:H=document}=c??{};return new Promise((n,w)=>{const p=async function(){let v,q;if(e){let A;const D=()=>{(q=d(a,h))?(cancelAnimationFrame(A),clearTimeout(v),b&&b(q),n(q)):A=requestAnimationFrame(D)};A=requestAnimationFrame(D);v=setTimeout(()=>{cancelAnimationFrame(A);C&&(b&&b(q),n(q))},1E3*f)}else{const [A,D]=0<g?[E,g]:[F,l],L=new MutationObserver(A(()=>{if(q=d(a,h))L.disconnect(),clearTimeout(v),b&&b(q),n(q)},D));L.observe(H,{subtree:m,childList:r,attributes:t,
characterData:x});v=setTimeout(()=>{L.disconnect();C&&(b&&b(q),n(q))},1E3*f)}};k&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>p(),{once:!0}):p()})},Throttle:E,Debounce:F,ScopeParsing:function(a,b){if("string"!==typeof a||""===a.trim())return b;const c=b.length,d=new Set,e=new Set,h=(g,l,k)=>{const m=g<=l;for(;m?g<=l:g>=l;m?g++:g--)k.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),l=
/[~-]/.test(a),[k,m]=g?[e,a]:[d,f],[r,t]=l?m.split(/-|~/):[m,m];r==t?k.add(+r-1):h(+r-1,+t-1,k)}return[...d].filter(g=>!e.has(g)&&g<c&&0<=g).sort((g,l)=>g-l).map(g=>b[g])},FormatTemplate:function(a,b){if("Object"!==y(a))return"Template must be an object";a=Object.fromEntries(Object.entries(a).map(([c,d])=>[c.toLowerCase(),d]));return"String"===y(b)?b.replace(/\{\s*([^}\s]+)\s*\}/g,(c,d)=>R.Process(a,d)):"Object"===y(b)?Object.entries(b).map(([c,d])=>R.Process(a,c,d)):{"Unsupported format":b}},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,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[I[b]]??a[I[c]]??a[I["en-US"]]},Menu:function(a,b={}){let {name:c="Menu",index:d=1,reset:e=!1}=b??{};e&&([...J].map(h=>GM_unregisterMenuCommand(h)),
J.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}),J.add(a)},StoreListen:async function(a,b){a.forEach(c=>{B[c]||(B[c]=!0,GM_addValueChangeListener(c,function(d,e,h,f){b({key:d,ov:e,nv:h,far:f})}))})},WorkerCreation:a=>{a=new Blob([a],{type:"application/javascript"});return new Worker(URL.createObjectURL(a))},Sleep:a=>new Promise(b=>setTimeout(b,a)),DomParse:a=>
S.parseFromString(a,"text/html"),NameFilter:a=>a.replace(/[\/\?<>\\:\*\|":]/g,""),GetFill:a=>Math.max(2,`${a}`.length),ExtensionName:a=>{try{return a.match(/\.([^.]+)$/)[1].toLowerCase()||"webp"}catch{return"webp"}},Mantissa:function(a,b,c="0",d=null){return d?`${++a}`.padStart(b,c)+`.${this.ExtensionName(d)}`:`${++a}`.padStart(b,c)}}})();