Greasy Fork is available in English.

ClassSyntax_min

Library for simplifying code logic and syntax (Class Type)

بۇ قوليازمىنى بىۋاسىتە قاچىلاشقا بولمايدۇ. بۇ باشقا قوليازمىلارنىڭ ئىشلىتىشى ئۈچۈن تەمىنلەنگەن ئامبار بولۇپ، ئىشلىتىش ئۈچۈن مېتا كۆرسەتمىسىگە قىستۇرىدىغان كود: // @require https://update.greasyfork.org/scripts/487608/1456525/ClassSyntax_min.js

// ==UserScript==
// @name         ClassSyntax
// @version      2024/09/30
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax (Class Type)
// @namespace    https://greasyfork.org/users/989635
// @match        *://*/*
// @license      MIT
// ==/UserScript==
class Syntax{constructor(){this.Mark={};this.Parser=new DOMParser;this.ListenerRecord=new Map;this.Type=a=>Object.prototype.toString.call(a).slice(8,-1);this.Print={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)};this.Query={Match:/[ .#=:]/,"#":(a,b)=>a.getElementById(b.slice(1)),".":(a,b,c)=>{a=a.getElementsByClassName(b.slice(1));return c?[...a]:a[0]},tag:(a,b,c)=>{a=a.getElementsByTagName(b);return c?[...a]:a[0]},"default":(a,b,c)=>c?a.querySelectorAll(b):a.querySelector(b)};this.TemplateMatch={Process:(a,b,c=null)=>{a=a[b.toLowerCase()];return"Function"===this.Type(a)?a(c):void 0!==a?a:"None"}};this.StoreMatch={verify:a=>void 0!==a?a:!1,d:a=>GM_deleteValue(a),a:()=>this.StoreMatch.verify(GM_listValues()),s:(a,b)=>GM_setValue(a,b),g:(a,b)=>this.StoreMatch.verify(GM_getValue(a,b)),sj:(a,b)=>GM_setValue(a,JSON.stringify(b,null,4)),gj:(a,b)=>JSON.parse(this.StoreMatch.verify(GM_getValue(a,b)))};this.StorageMatch={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)};this.Device={sX:()=>window.scrollX,sY:()=>window.scrollY,iW:()=>window.innerWidth,iH:()=>window.innerHeight,_Type:void 0,Url:location.href,Orig:location.origin,Host:location.hostname,Path:location.pathname,Lang:navigator.language,Agen:navigator.userAgent,Type:function(){return this._Type=this._Type?this._Type:this._Type=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(this.Agen)||768>this.iW?"Mobile":"Desktop"}}}$$(a,{all:b=!1,root:c=document}={}){const d=this.Query.Match.test(a)?this.Query.Match.test(a.slice(1))?"default":a[0]:"tag";return this.Query[d](c,a,b)}Sleep(a){return new Promise(b=>setTimeout(b,a))}async Log(a=null,b="print",{dev:c=!0,type:d="log",collapsed:e=!0}={}){c&&(c=this.Print[d]||this.Print.log,null==a?c(b):(e?console.groupCollapsed(a):console.group(a),c(b),console.groupEnd()))}async AddStyle(a,b="New-Style",c=!0){let d=document.getElementById(b);if(!d)d=document.createElement("style"),d.id=b,document.head.appendChild(d);else if(!c)return;d.textContent+=a}async AddScript(a,b="New-Script",c=!0){let d=document.getElementById(b);if(!d)d=document.createElement("script"),d.id=b,document.head.appendChild(d);else if(!c)return;d.textContent+=a}async Listen(a,b,c,d={},e=null){try{a.addEventListener(b,c,d),e&&e(!0)}catch{e&&e(!1)}}async AddListener(a,b,c,d={}){const {mark:e,...m}=d;d=e??a;const h=this.ListenerRecord.get(d);h?.has(b)||(a.addEventListener(b,c,m),h||this.ListenerRecord.set(d,new Map),this.ListenerRecord.get(d).set(b,c))}async RemovListener(a,b){const c=this.ListenerRecord.get(a)?.get(b);c&&(a.removeEventListener(b,c),this.ListenerRecord.get(a).delete(b))}async Observer(a,b,{mark:c=!1,throttle:d=0,subtree:e=!0,childList:m=!0,attributes:h=!0,characterData:f=!1}={},l=null){if(c){if(this.Mark[c])return;this.Mark[c]=!0}c={subtree:e,childList:m,attributes:h,characterData:f};d=new MutationObserver(this.Throttle(()=>{b()},d));d.observe(a,c);l&&l({ob:d,op:c})}async WaitElem(a,b,{raf:c=!1,all:d=!1,timeout:e=8,throttle:m=50,subtree:h=!0,childList:f=!0,attributes:l=!1,characterData:t=!1,timeoutResult:p=!1,object:q=document.body}={}){let k,g,r;if(c){let n;const u=()=>{g=d?document.querySelectorAll(a):document.querySelector(a);(r=d?0<g.length:g)?(cancelAnimationFrame(n),clearTimeout(k),b(g)):n=requestAnimationFrame(u)};n=requestAnimationFrame(u);k=setTimeout(()=>{cancelAnimationFrame(n);p&&b(g)},1E3*e)}else{const n=new MutationObserver(this.Throttle(()=>{g=d?document.querySelectorAll(a):document.querySelector(a);if(r=d?0<g.length:g)n.disconnect(),clearTimeout(k),b(g)},m));n.observe(q,{subtree:h,childList:f,attributes:l,characterData:t});k=setTimeout(()=>{n.disconnect();p&&b(g)},1E3*e)}}async WaitMap(a,b,{raf:c=!1,timeout:d=8,throttle:e=50,subtree:m=!0,childList:h=!0,attributes:f=!1,characterData:l=!1,timeoutResult:t=!1,object:p=document.body}={}){let q,k;if(c){let g;const r=()=>{k=a.map(n=>document.querySelector(n));k.every(n=>null!==n&&"undefined"!==typeof n)?(cancelAnimationFrame(g),clearTimeout(q),b(k)):g=requestAnimationFrame(r)};g=requestAnimationFrame(r);q=setTimeout(()=>{cancelAnimationFrame(g);t&&b(k)},1E3*d)}else{const g=new MutationObserver(this.Throttle(()=>{k=a.map(r=>document.querySelector(r));k.every(r=>null!==r&&"undefined"!==typeof r)&&(g.disconnect(),clearTimeout(q),b(k))},e));g.observe(p,{subtree:m,childList:h,attributes:f,characterData:l});q=setTimeout(()=>{g.disconnect();t&&b(k)},1E3*d)}}Storage(a,{type:b=sessionStorage,value:c=null,error:d}={}){let e;return null!=c?this.StorageMatch[this.Type(c)](b,a,c):(e=b.getItem(a),void 0!=e?this.StorageMatch[this.Type(JSON.parse(e))](b,e):d)}DomParse(a){return this.Parser.parseFromString(a,"text/html")}NameFilter(a){return a.replace(/[\/\?<>\\:\*\|":]/g,"")}GetFill(a){return Math.max(2,`${a}`.length)}ExtensionName(a){try{return a.match(/\.([^.]+)$/)[1].toLowerCase()||"png"}catch{return"png"}}Mantissa(a,b,c="0",d=null){return d?`${++a}`.padStart(b,c)+`.${this.ExtensionName(d)}`:`${++a}`.padStart(b,c)}ScopeParsing(a,b){if("string"!=typeof a||""===a.trim())return b;const c=b.length,d=new Set,e=new Set,m=(f,l,t)=>{const p=f<=l;for(;p?f<=l:f>=l;p?f++:f--)t.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),[t,p]=f?[e,a]:[d,h],[q,k]=l?p.split(/-|~/):[p,p];q==k?t.add(+q-1):m(+q-1,+k-1,t)}return[...d].filter(f=>!e.has(f)&&f<c&&0<=f).sort((f,l)=>f-l).map(f=>b[f])}FormatTemplate(a,b){if("Object"!==this.Type(a))return"Template must be an object";a=Object.fromEntries(Object.entries(a).map(([c,d])=>[c.toLowerCase(),d]));return"String"===this.Type(b)?b.replace(/\{\s*([^}\s]+)\s*\}/g,(c,d)=>this.TemplateMatch.Process(a,d)):"Object"===this.Type(b)?Object.entries(b).map(([c,d])=>this.TemplateMatch.Process(a,c,d)):{"Unsupported format":b}}async OutputJson(a,b,c=null){try{a="string"!==typeof a?JSON.stringify(a,null,4):a;b="string"!==typeof b?"Anonymous":b.replace(".json","");const d=document.createElement("a");d.href=`data:application/json;charset=utf-8,${encodeURIComponent(a)}`;d.download=`${b}.json`;d.click();await new Promise(e=>setTimeout(e,100));d.remove();c&&c({State:!0})}catch(d){c&&c({State:!1,Info:d})}}WorkerCreation(a){a=new Blob([a],{type:"application/javascript"});return new Worker(URL.createObjectURL(a))}Runtime(a=null,{log:b=!0,format:c=!0,label:d="Elapsed Time:",style:e="\u001b[1m\u001b[36m%s\u001b[0m"}={}){if(!a)return performance.now();a=c?`${((performance.now()-a)/1E3).toPrecision(3)}s`:performance.now()-a;return b?console.log(e,`${d} ${a}`):a}GetDate(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,m)=>c[m]??"Error"))("string"===typeof a?a:"{year}-{month}-{date} {hour}:{minute}:{second}")}Throttle(a,b){let c=0;return(...d)=>{const e=Date.now();e-c>=b&&(c=e,a(...d))}}Debounce(a,b=500){let c=null;return(...d)=>{clearTimeout(c);c=setTimeout(function(){a(...d)},b)}}async Menu(a,b="Menu",c=1){for(const [d,e]of Object.entries(a))GM_registerMenuCommand(d,()=>{e.func()},{title:e.desc,id:`${b}-${c++}`,autoClose:e.close,accessKey:e.hotkey})}Store(a,b=null,c=null){return this.StoreMatch[a](b,c)}async StoreListen(a,b){a.forEach(c=>{this.Mark[c]||(this.Mark[c]=!0,GM_addValueChangeListener(c,function(d,e,m,h){b({key:d,ov:e,nv:m,far:h})}))})}};