SyntaxSimplified

Library for simplifying code logic and syntax

2024-04-17 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/487608/1361998/SyntaxSimplified.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         SyntaxSimplified
// @version      2024/04/18
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax
// @namespace    https://greasyfork.org/users/989635
// @match        *://*/*
// @license      MIT
// ==/UserScript==
class Syntax{constructor(){this.Mark={};this.Parser=new DOMParser;this.ListenerRecord=new Map;this.Buffer=document.createDocumentFragment();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.StorageMatch={Type:a=>Object.prototype.toString.call(a).slice(8,-1),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)}}$$(a,{all:b=!1,root:c=document}={}){const e=this.query.Match.test(a)?this.query.Match.test(a.slice(1))?"default":a[0]:"tag";return this.query[e](c,a,b)}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",e=null){return e?`${++a}.${this.ExtensionName(e)}`.padStart(b,c):`${++a}`.padStart(b,c)}WorkerCreation(a){a=new Blob([a],{type:"application/javascript"});return new Worker(URL.createObjectURL(a))}sleep(a){return new Promise(b=>setTimeout(b,a))}async AddStyle(a,b="New-Style"){let c=document.getElementById(b);c||(c=document.createElement("style"),c.id=b,document.head.appendChild(c));c.textContent+=a}async AddScript(a,b="New-Script"){a=document.getElementById(b);a||(a=document.createElement("script"),a.id=b,document.head.appendChild(a))}async AddListener(a,b,c,e={}){const d=this.ListenerRecord.get(a);d&&d?.has(b)||(a.addEventListener(b,c,e),d||this.ListenerRecord.set(a,new Map),this.ListenerRecord.get(a).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 Listen(a,b,c,e={},d=null){try{a.addEventListener(b,c,e),d&&d(!0)}catch{d&&d(!1)}}async Observer(a,b,{mark:c=!1,throttle:e=0,subtree:d=!0,childList:f=!0,characterData:g=!1}={},m=null){if(c){if(this.Mark[c])return;this.Mark[c]=!0}c={subtree:d,childList:f,characterData:g};e=new MutationObserver(this.Throttle(()=>{b()},e));e.observe(a,c);m&&m({ob:e,op:c})}async WaitElem(a,b,{raf:c=!1,all:e=!1,timeout:d=8,throttle:f=50,subtree:g=!0,childList:m=!0,characterData:q=!1,timeoutResult:r=!1,object:p=document.body}={}){let k,h,n;if(c){let l;const t=()=>{h=e?document.querySelectorAll(a):document.querySelector(a);(n=e?0<h.length:h)?(cancelAnimationFrame(l),clearTimeout(k),b(h)):l=requestAnimationFrame(t)};l=requestAnimationFrame(t);k=setTimeout(()=>{cancelAnimationFrame(l);r&&b(h)},1E3*d)}else{const l=new MutationObserver(this.Throttle(()=>{h=e?document.querySelectorAll(a):document.querySelector(a);if(n=e?0<h.length:h)l.disconnect(),clearTimeout(k),b(h)},f));l.observe(p,{subtree:g,childList:m,characterData:q});k=setTimeout(()=>{l.disconnect();r&&b(h)},1E3*d)}}async WaitMap(a,b,{raf:c=!1,timeout:e=8,throttle:d=50,subtree:f=!0,childList:g=!0,characterData:m=!1,timeoutResult:q=!1,object:r=document.body}={}){let p,k;if(c){let h;const n=()=>{k=a.map(l=>document.querySelector(l));k.every(l=>null!==l&&"undefined"!==typeof l)?(cancelAnimationFrame(h),clearTimeout(p),b(k)):h=requestAnimationFrame(n)};h=requestAnimationFrame(n);p=setTimeout(()=>{cancelAnimationFrame(h);q&&b(k)},1E3*e)}else{const h=new MutationObserver(this.Throttle(()=>{k=a.map(n=>document.querySelector(n));k.every(n=>null!==n&&"undefined"!==typeof n)&&(h.disconnect(),clearTimeout(p),b(k))},d));h.observe(r,{subtree:f,childList:g,characterData:m});p=setTimeout(()=>{h.disconnect();q&&b(k)},1E3*e)}}async log(a=null,b="print",{type:c="log",collapsed:e=!0}={}){c="string"===typeof c&&this.print[c]?c:c="log";if(null==a)this.print[c](b);else e?console.groupCollapsed(a):console.group(a),this.print[c](b),console.groupEnd()}Runtime(a=null,b="Elapsed Time:",{style:c="\u001b[1m\u001b[36m%s\u001b[0m",log:e=!0}={}){return a?e?console.log(c,`${b} ${(Date.now()-a)/1E3}s`):Date.now()-a:Date.now()}Debounce(a,b=500){let c=null;return(...e)=>{clearTimeout(c);c=setTimeout(function(){a(...e)},b)}}Throttle(a,b){let c=0;return(...e)=>{const d=Date.now();d-c>=b&&(c=d,a(...e))}}ScopeParsing(a,b){const c=new Set,e=new Set,d=b.length;for(const g of a.split(/\s*,\s*/))if(/^\d+$/.test(g))c.add(Number(g)-1);else if(/^\d+(?:~\d+|-\d+)$/.test(g)){var f=g.split(/-|~/);a=Number(f[0]-1);f=Number(f[1]-1);const m=a<=f;for(;m?a<=f:a>=f;m?a++:a--)c.add(a)}else/(!|-)+\d+/.test(g)&&e.add(Number(g.slice(1)-1));return[...c].filter(g=>!e.has(g)&&g<d&&0<=g).sort((g,m)=>g-m).map(g=>b[g])}Storage(a,{type:b=sessionStorage,value:c=null,error:e}={}){let d;return null!=c?this.StorageMatch[this.StorageMatch.Type(c)](b,a,c):(d=b.getItem(a),void 0!=d?this.StorageMatch[this.StorageMatch.Type(JSON.parse(d))](b,d):e)}store(a,b=null,c=null){const e={verify:d=>void 0!==d?d:!1,de:d=>GM_deleteValue(d),al:()=>e.verify(GM_listValues()),s:(d,f)=>GM_setValue(d,f),g:(d,f)=>e.verify(GM_getValue(d,f)),sj:(d,f)=>GM_setValue(d,JSON.stringify(f,null,4)),gj:(d,f)=>JSON.parse(e.verify(GM_getValue(d,f)))};return e[a](b,c)}async storeListen(a,b){a.forEach(c=>{this.Mark[c]||(this.Mark[c]=!0,GM_addValueChangeListener(c,function(e,d,f,g){b({key:e,ov:d,nv:f,far:g})}))})}async Menu(a,b="Menu",c=1){for(const [e,d]of Object.entries(a))GM_registerMenuCommand(e,()=>{d.func()},{title:d.desc,id:`${b}-${c++}`,autoClose:d.close,accessKey:d.hotkey})}};