ObjectSyntax

Library for simplifying code logic and syntax (Object Type)

ของเมื่อวันที่ 11-03-2025 ดู เวอร์ชันล่าสุด

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greasyfork.org/scripts/495339/1551581/ObjectSyntax.js

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         ObjectSyntax
// @version      2025/03/11
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax (Object Type)
// @namespace    https://greasyfork.org/users/989635
// @match        *://*/*
// @license      MPL-2.0
// ==/UserScript==
const Syn=(()=>{let t={},G=new DOMParser,r=new Map,p=a=>Object.prototype.toString.call(a).slice(8,-1),A={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)},y={Match:a=>/[ .#=:]/.test(a),"#":(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)};var H=a=>{a=a.map(b=>document.querySelector(b));return a.every(Boolean)&&a},I=(a,b)=>{a=b?document.querySelectorAll(a):document.querySelector(a);return(b?0<a.length:a)&&a};let B={Process:(a,b,c=null)=>{a=a[b.toLowerCase()];return"Function"===p(a)?a(c):void 0!==a?a:"None"}},u={verify:a=>void 0!==a&&a,d:a=>GM_deleteValue(a),a:()=>u.verify(GM_listValues()),s:(a,b)=>GM_setValue(a,b),g:(a,b)=>u.verify(GM_getValue(a,b)),sj:(a,b)=>GM_setValue(a,JSON.stringify(b,null,4)),gj:(a,b)=>JSON.parse(u.verify(GM_getValue(a,b)))},C={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)};return{Type:p,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=/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}={})=>{var d=y.Match(a)?y.Match(a.slice(1))?"default":a[0]:"tag";return y[d](c,a,b)},Sleep:a=>new Promise(b=>setTimeout(b,a)),Log:async(a=null,b="print",{dev:c=!0,type:d="log",collapsed:e=!0}={})=>{c&&(c=A[d]||A.log,null==a?c(b):(e?console.groupCollapsed(a):console.group(a),c(b),console.groupEnd()))},AddStyle:async(a,b="New-Style",c=!0)=>{let d=document.getElementById(b);if(d){if(!c)return}else(d=document.createElement("style")).id=b,document.head.appendChild(d);d.textContent+=a},AddScript:async(a,b="New-Script",c=!0)=>{let d=document.getElementById(b);if(d){if(!c)return}else(d=document.createElement("script")).id=b,document.head.appendChild(d);d.textContent+=a},Listen:async(a,b,c,d={},e=null)=>{try{a.addEventListener(b,c,d),e&&e(!0)}catch{e&&e(!1)}},AddListener:async(a,b,c,d={})=>{let {mark:e,...k}=d;d=e??a;var f=r.get(d);f?.has(b)||(a.addEventListener(b,c,k),f||r.set(d,new Map),r.get(d).set(b,c))},RemovListener:(a,b)=>{var c=r.get(a)?.get(b);c&&(a.removeEventListener(b,c),r.get(a).delete(b))},Observer:async function(a,b,{mark:c=!1,throttle:d=0,subtree:e=!0,childList:k=!0,attributes:f=!0,characterData:h=!1}={},l=null){if(c){if(t[c])return;t[c]=!0}c={subtree:e,childList:k,attributes:f,characterData:h};e=new MutationObserver(this.Throttle(()=>{b()},d));e.observe(a,c);l&&l({ob:e,op:c})},WaitElem:async function(a,b=null,c={}){let d=this,e=a instanceof Array?H:I,{raf:k=!1,all:f=!1,timeout:h=8,throttle:l=50,subtree:g=!0,childList:q=!0,attributes:z=!0,characterData:v=!1,timeoutResult:D=!1,root:J=document}=c??{};return new Promise((w,K)=>{async function E(){let x,m;if(k){let n,F=()=>{(m=e(a,f))?(cancelAnimationFrame(n),clearTimeout(x),b&&b(m),w(m)):n=requestAnimationFrame(F)};n=requestAnimationFrame(F);x=setTimeout(()=>{cancelAnimationFrame(n);D&&(b&&b(m),w(m))},1E3*h)}else{let n=new MutationObserver(d.Throttle(()=>{(m=e(a,f))&&(n.disconnect(),clearTimeout(x),b&&b(m),w(m))},l));n.observe(J,{subtree:g,childList:q,attributes:z,characterData:v});x=setTimeout(()=>{n.disconnect();D&&(b&&b(m),w(m))},1E3*h)}}"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>E(),{once:!0}):E()})},Storage(a,{type:b=sessionStorage,value:c=null,error:d}={}){return null!=c?C[p(c)](b,a,c):null!=(c=b.getItem(a))?C[p(JSON.parse(c))](b,c):d},DomParse:a=>G.parseFromString(a,"text/html"),NameFilter:a=>a.replace(/[\/\?<>\\:\*\|":]/g,""),GetFill:a=>Math.max(2,(""+a).length),ExtensionName:a=>{try{return a.match(/\.([^.]+)$/)[1].toLowerCase()||"png"}catch{return"png"}},Mantissa:function(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;let c=b.length,d=new Set,e=new Set;var k,f,h;let l;for(l of a.split(/\s*[\.,|/]\s*/))/^(!|-)?\d+(~\d+|-\d+)?$/.test(l)&&(h=l.slice(1),k=/^[!-]/.test(l),f=/[~-]/.test(h),[k,h]=k?[e,h]:[d,l],[f,h]=f?h.split(/-|~/):[h,h],f==h?k.add(+f-1):((g,q,z)=>{for(var v=g<=q;v?g<=q:g>=q;v?g++:g--)z.add(g)})(+f-1,+h-1,k));return[...d].filter(g=>!e.has(g)&&g<c&&0<=g).sort((g,q)=>g-q).map(g=>b[g])},FormatTemplate:(a,b)=>"Object"!==p(a)?"Template must be an object":(a=Object.fromEntries(Object.entries(a).map(([c,d])=>[c.toLowerCase(),d])),"String"===p(b)?b.replace(/\{\s*([^}\s]+)\s*\}/g,(c,d)=>B.Process(a,d)):"Object"===p(b)?Object.entries(b).map(([c,d])=>B.Process(a,c,d)):{"Unsupported format":b}),OutputJson:async(a,b,c=null)=>{try{a="string"!=typeof a?JSON.stringify(a,null,4):a;b="string"!=typeof b?"Anonymous":b.replace(".json","");var 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(e){c&&c({State:!1,Info:e})}},WorkerCreation:a=>{a=new Blob([a],{type:"application/javascript"});return new Worker(URL.createObjectURL(a))},Runtime:(a=null,{log:b=!0,format:c=!0,lable:d="Elapsed Time:",style:e="\u001b[1m\u001b[36m%s\u001b[0m"}={})=>a?(c=c?((performance.now()-a)/1E3).toPrecision(3)+"s":performance.now()-a,b?console.log(e,d+" "+c):c):performance.now(),GetDate:(a=null)=>{var b=new Date;let 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("string"==typeof a?a:"{year}-{month}-{date} {hour}:{minute}:{second}").replace(/{([^}]+)}/g,(d,e)=>c[e]??"Error")},Throttle:(a,b)=>{let c=0;return(...d)=>{var 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)}},Menu:async(a,b="Menu",c=1)=>{for(let [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)=>u[a](b,c),StoreListen:async(a,b)=>{a.forEach(c=>{t[c]||(t[c]=!0,GM_addValueChangeListener(c,function(d,e,k,f){b({key:d,ov:e,nv:k,far:f})}))})}}})();