SyntaxSimplified

Library for simplifying code logic and syntax

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         SyntaxSimplified
// @version      2024/04/12
// @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.ListenerRecord={};this.Parser=new DOMParser;this.Buffer=document.createDocumentFragment();this.print={log:a=>console.log(a),warn:a=>console.warn(a),error:a=>console.error(a),count:a=>console.count(a)};this.query={Match:/[ .#=:]/,"#":(a,c)=>a.getElementById(c.slice(1)),".":(a,c,b)=>{a=a.getElementsByClassName(c.slice(1));return b?Array.from(a):a[0]},tag:(a,c,b)=>{a=a.getElementsByTagName(c);return b?Array.from(a):a[0]},"default":(a,c,b)=>b?a.querySelectorAll(c):a.querySelector(c)};this.StorageMatch={Type:a=>Object.prototype.toString.call(a).slice(8,-1),String:(a,c,b)=>null!=b?(a.setItem(c,JSON.stringify(b)),!0):JSON.parse(c),Number:(a,c,b)=>null!=b?(a.setItem(c,JSON.stringify(b)),!0):Number(c),Array:(a,c,b)=>null!=b?(a.setItem(c,JSON.stringify(b)),!0):(c=JSON.parse(c),Array.isArray(c[0])?new Map(c):c),Object:(a,c,b)=>null!=b?(a.setItem(c,JSON.stringify(b)),!0):JSON.parse(c),Boolean:(a,c,b)=>null!=b?(a.setItem(c,JSON.stringify(b)),!0):JSON.parse(c),Date:(a,c,b)=>null!=b?(a.setItem(c,JSON.stringify(b)),!0):new Date(c),Map:(a,c,b)=>(a.setItem(c,JSON.stringify([...b])),!0)}}$$(a,{all:c=!1,root:b=document}={}){const d=this.query.Match.test(a)?this.query.Match.test(a.slice(1))?"default":a[0]:"tag";return this.query[d](b,a,c)}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,c,b="0",d=null){return d?`${++a}.${this.ExtensionName(d)}`.padStart(c,b):`${++a}`.padStart(c,b)}WorkerCreation(a){a=new Blob([a],{type:"application/javascript"});return new Worker(URL.createObjectURL(a))}sleep(a){return new Promise(c=>setTimeout(c,a))}async AddStyle(a,c="New-Style"){let b=document.getElementById(c);b||(b=document.createElement("style"),b.id=c,document.head.appendChild(b));b.appendChild(document.createTextNode(a))}async AddScript(a,c="New-Script"){let b=document.getElementById(c);b||(b=document.createElement("script"),b.id=c,document.head.appendChild(b));b.appendChild(document.createTextNode(a))}async AddListener(a,c,b,d={}){this.ListenerRecord[a]?.[c]||(a.addEventListener(c,b,d),this.ListenerRecord[a]||(this.ListenerRecord[a]={}),this.ListenerRecord[a][c]=b)}async RemovListener(a,c){const b=this.ListenerRecord[a]?.[c];b&&(a.removeEventListener(c,b),delete this.ListenerRecord[a][c])}async Listen(a,c,b,d={},f=null){try{a.addEventListener(c,b,d),f&&f(!0)}catch{f&&f(!1)}}async Observer(a,c,{mark:b=!1,subtree:d=!0,childList:f=!0,characterData:e=!1}={},g=null){if(b){if(this.Mark[b])return;this.Mark[b]=!0}b={subtree:d,childList:f,characterData:e};d=new MutationObserver(()=>{c()});d.observe(a,b);g&&g({ob:d,op:b})}async WaitElem(a,c,b,d,{object:f=document.body,reject:e=!1,throttle:g=0}={}){let k,h,l;const m=new MutationObserver(this.Throttle(()=>{h=c?document.querySelectorAll(a):document.querySelector(a);if(l=c?0<h.length&&Array.from(h).every(n=>null!==n&&"undefined"!==typeof n):h)m.disconnect(),clearTimeout(k),d(h)},g));m.observe(f,{childList:!0,subtree:!0});k=setTimeout(()=>{m.disconnect();e&&d(h)},1E3*b)}async WaitMap(a,c,b,{object:d=document.body,reject:f=!1,throttle:e=0}={}){let g,k;const h=new MutationObserver(this.Throttle(()=>{k=a.map(l=>document.querySelector(l));k.every(l=>null!==l&&"undefined"!==typeof l)&&(h.disconnect(),clearTimeout(g),b(k))},e));h.observe(d,{childList:!0,subtree:!0});g=setTimeout(()=>{h.disconnect();f&&b(k)},1E3*c)}async log(a=null,c="print",b="log"){b="string"===typeof b&&this.print[b]?b:b="log";if(null==a)this.print[b](c);else console.groupCollapsed(a),this.print[b](c),console.groupEnd()}Runtime(a=null,c="Elapsed Time:",{style:b="\u001b[1m\u001b[36m%s\u001b[0m",log:d=!0}={}){return a?d?console.log(b,`${c} ${(Date.now()-a)/1E3}s`):Date.now()-a:Date.now()}Debounce(a,c=500){let b=null;return(...d)=>{clearTimeout(b);b=setTimeout(function(){a(...d)},c)}}Throttle(a,c){let b=0;return(...d)=>{const f=Date.now();f-b>=c&&(b=f,a(...d))}}ScopeParsing(a,c){const b=new Set,d=new Set,f=c.length;for(const e of a.split(/\s*,\s*/))if(/^\d+$/.test(e))b.add(Number(e)-1);else if(/^\d+(?:~\d+|-\d+)$/.test(e)){c=e.split(/-|~/);a=Number(c[0]-1);c=Number(c[1]-1);const g=a<=c;for(;g?a<=c:a>=c;g?a++:a--)b.add(a)}else/(!|-)+\d+/.test(e)&&d.add(Number(e.slice(1)-1));return[...b].filter(e=>!d.has(e)&&e<f&&0<=e).sort((e,g)=>e-g).map(e=>obj[e])}Storage(a,{type:c=sessionStorage,value:b=null,error:d}={}){let f;return null!=b?this.StorageMatch[this.StorageMatch.Type(b)](c,a,b):(f=c.getItem(a),void 0!=f?this.StorageMatch[this.StorageMatch.Type(JSON.parse(f))](c,f):d)}store(a,c=null,b=null,d=null){const f={verify:e=>void 0!==e?e:d,de:e=>GM_deleteValue(e),al:()=>f.verify(GM_listValues()),s:(e,g)=>GM_setValue(e,g),g:e=>f.verify(GM_getValue(e,null)),sj:(e,g)=>GM_setValue(e,JSON.stringify(g,null,4)),gj:e=>JSON.parse(f.verify(GM_getValue(e,null)))};return f[a](c,b)}async storeListen(a,c){a.forEach(b=>{this.Mark[b]||(this.Mark[b]=!0,GM_addValueChangeListener(b,function(d,f,e,g){c({key:d,ov:f,nv:e,far:g})}))})}async Menu(a,c="Menu",b=1){for(const [d,f]of Object.entries(a))GM_registerMenuCommand(d,()=>{f.func()},{title:f.desc,id:`${c}-${b++}`,autoClose:f.close,accessKey:f.hotkey})}};