Class_Syntax.min

Library for simplifying code logic and syntax (Class Type)

目前为 2024-05-18 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/487608/1378683/Class_Syntaxmin.js

// ==UserScript==
// @name         Class_Syntax.min
// @version      2024/05/18
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax (Class Type)
// @namespace    https://gf.qytechs.cn/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,c)=>a.getElementById(c.slice(1)),".":(a,c,b)=>{a=a.getElementsByClassName(c.slice(1));return b?[...a]:a[0]},tag:(a,c,b)=>{a=a.getElementsByTagName(c);return b?[...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)};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:()=>this.Device._Type=this.Device._Type?this.Device._Type:this.Device._Type=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(this.Device.Agen)||768>this.Device.iW?"Mobile":"Desktop"}}$$(a,{all:c=!1,root:b=document}={}){const e=this.Query.Match.test(a)?this.Query.Match.test(a.slice(1))?"default":a[0]:"tag";return this.Query[e](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",e=null){return e?`${++a}`.padStart(c,b)+`.${this.ExtensionName(e)}`:`${++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.textContent+=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.textContent+=a}async AddListener(a,c,b,e={}){const d=this.ListenerRecord.get(a);d&&d?.has(c)||(a.addEventListener(c,b,e),d||this.ListenerRecord.set(a,new Map),this.ListenerRecord.get(a).set(c,b))}async RemovListener(a,c){const b=this.ListenerRecord.get(a)?.get(c);b&&(a.removeEventListener(c,b),this.ListenerRecord.get(a).delete(c))}async Listen(a,c,b,e={},d=null){try{a.addEventListener(c,b,e),d&&d(!0)}catch{d&&d(!1)}}async Observer(a,c,{mark:b=!1,throttle:e=0,subtree:d=!0,childList:f=!0,attributes:g=!0,characterData:m=!1}={},p=null){if(b){if(this.Mark[b])return;this.Mark[b]=!0}b={subtree:d,childList:f,attributes:g,characterData:m};e=new MutationObserver(this.Throttle(()=>{c()},e));e.observe(a,b);p&&p({ob:e,op:b})}async WaitElem(a,c,{raf:b=!1,all:e=!1,timeout:d=8,throttle:f=50,subtree:g=!0,childList:m=!0,attributes:p=!1,characterData:r=!1,timeoutResult:t=!1,object:q=document.body}={}){let k,h,n;if(b){let l;const u=()=>{h=e?document.querySelectorAll(a):document.querySelector(a);(n=e?0<h.length:h)?(cancelAnimationFrame(l),clearTimeout(k),c(h)):l=requestAnimationFrame(u)};l=requestAnimationFrame(u);k=setTimeout(()=>{cancelAnimationFrame(l);t&&c(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),c(h)},f));l.observe(q,{subtree:g,childList:m,attributes:p,characterData:r});k=setTimeout(()=>{l.disconnect();t&&c(h)},1E3*d)}}async WaitMap(a,c,{raf:b=!1,timeout:e=8,throttle:d=50,subtree:f=!0,childList:g=!0,attributes:m=!1,characterData:p=!1,timeoutResult:r=!1,object:t=document.body}={}){let q,k;if(b){let h;const n=()=>{k=a.map(l=>document.querySelector(l));k.every(l=>null!==l&&"undefined"!==typeof l)?(cancelAnimationFrame(h),clearTimeout(q),c(k)):h=requestAnimationFrame(n)};h=requestAnimationFrame(n);q=setTimeout(()=>{cancelAnimationFrame(h);r&&c(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(q),c(k))},d));h.observe(t,{subtree:f,childList:g,attributes:m,characterData:p});q=setTimeout(()=>{h.disconnect();r&&c(k)},1E3*e)}}async Log(a=null,c="print",{type:b="log",collapsed:e=!0}={}){b="string"===typeof b&&this.Print[b]?b:b="log";if(null==a)this.Print[b](c);else e?console.groupCollapsed(a):console.group(a),this.Print[b](c),console.groupEnd()}Runtime(a=null,c="Elapsed Time:",{style:b="\u001b[1m\u001b[36m%s\u001b[0m",log:e=!0}={}){return a?e?console.log(b,`${c} ${(Date.now()-a)/1E3}s`):Date.now()-a:Date.now()}Debounce(a,c=500){let b=null;return(...e)=>{clearTimeout(b);b=setTimeout(function(){a(...e)},c)}}Throttle(a,c){let b=0;return(...e)=>{const d=Date.now();d-b>=c&&(b=d,a(...e))}}ScopeParsing(a,c){const b=new Set,e=new Set,d=c.length;for(const g of a.split(/\s*[,\./]\s*/))if(/^\d+$/.test(g))b.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--)b.add(a)}else/(!|-)+\d+/.test(g)&&e.add(Number(g.slice(1)-1));return[...b].filter(g=>!e.has(g)&&g<d&&0<=g).sort((g,m)=>g-m).map(g=>c[g])}Storage(a,{type:c=sessionStorage,value:b=null,error:e}={}){let d;return null!=b?this.StorageMatch[this.StorageMatch.Type(b)](c,a,b):(d=c.getItem(a),void 0!=d?this.StorageMatch[this.StorageMatch.Type(JSON.parse(d))](c,d):e)}Store(a,c=null,b=null){const e={verify:d=>void 0!==d?d:!1,d:d=>GM_deleteValue(d),a:()=>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](c,b)}async StoreListen(a,c){a.forEach(b=>{this.Mark[b]||(this.Mark[b]=!0,GM_addValueChangeListener(b,function(e,d,f,g){c({key:e,ov:d,nv:f,far:g})}))})}async Menu(a,c="Menu",b=1){for(const [e,d]of Object.entries(a))GM_registerMenuCommand(e,()=>{d.func()},{title:d.desc,id:`${c}-${b++}`,autoClose:d.close,accessKey:d.hotkey})}};

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址