ObjectSyntax

Library for simplifying code logic and syntax (Object Type)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ObjectSyntax
// @version      2025/03/24
// @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=(()=>{const u={},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)},z={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};const B={Process:(a,b,c=null)=>{a=a[b.toLowerCase()];return"Function"===p(a)?a(c):void 0!==a?a:"None"}},v={verify:a=>void 0!==a?a:!1,d:a=>GM_deleteValue(a),a:()=>v.verify(GM_listValues()),s:(a,b)=>GM_setValue(a,b),g:(a,b)=>v.verify(GM_getValue(a,b)),sj:(a,b)=>GM_setValue(a,JSON.stringify(b,null,4)),gj:(a,b)=>JSON.parse(v.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: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=z.Match(a)?z.Match(a.slice(1))?"default":a[0]:"tag";return z[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)d=document.createElement("style"),d.id=b,document.head.appendChild(d);else if(!c)return;d.textContent+=a},AddScript:async(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},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={})=>{const {mark:e,...k}=d;d=e??a;const g=r.get(d);g?.has(b)||(a.addEventListener(b,c,k),g||r.set(d,new Map),r.get(d).set(b,c))},RemovListener:(a,b)=>{const 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:g=!0,characterData:f=!1}={},h=null){if(c){if(u[c])return;u[c]=!0}c={subtree:e,childList:k,attributes:g,characterData:f};d=new MutationObserver(this.Throttle(()=>{b()},d));d.observe(a,c);h&&h({ob:d,op:c})},WaitElem:async function(a,b=null,c={}){const d=this,e=a instanceof Array?H:I,{raf:k=!1,all:g=!1,timeout:f=8,throttle:h=50,subtree:q=!0,childList:m=!0,attributes:t=!0,characterData:w=!1,timeoutResult:D=!1,root:J=document}=c??{};return new Promise((x,K)=>{const F=async function(){let y,l;if(k){let n;const E=()=>{(l=e(a,g))?(cancelAnimationFrame(n),clearTimeout(y),b&&b(l),x(l)):n=requestAnimationFrame(E)};n=requestAnimationFrame(E);y=setTimeout(()=>{cancelAnimationFrame(n);D&&(b&&b(l),x(l))},1E3*f)}else{const n=new MutationObserver(d.Throttle(()=>{if(l=e(a,g))n.disconnect(),clearTimeout(y),b&&b(l),x(l)},h));n.observe(J,{subtree:q,childList:m,attributes:t,characterData:w});y=setTimeout(()=>{n.disconnect();D&&(b&&b(l),x(l))},1E3*f)}};"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>F(),{once:!0}):F()})},Storage(a,{type:b=sessionStorage,value:c=null,error:d}={}){let e;return null!=c?C[p(c)](b,a,c):(e=b.getItem(a),void 0!=e?C[p(JSON.parse(e))](b,e):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;const c=b.length,d=new Set,e=new Set,k=(f,h,q)=>{const m=f<=h;for(;m?f<=h:f>=h;m?f++:f--)q.add(f)};let g;for(g of a.split(/\s*[\.,|/]\s*/))if(/^(!|-)?\d+(~\d+|-\d+)?$/.test(g)){a=g.slice(1);const f=/^[!-]/.test(g),h=/[~-]/.test(a),[q,m]=f?[e,a]:[d,g],[t,w]=h?m.split(/-|~/):[m,m];t==w?q.add(+t-1):k(+t-1,+w-1,q)}return[...d].filter(f=>!e.has(f)&&f<c&&0<=f).sort((f,h)=>f-h).map(f=>b[f])},FormatTemplate:(a,b)=>{if("Object"!==p(a))return"Template must be an object";a=Object.fromEntries(Object.entries(a).map(([c,d])=>[c.toLowerCase(),d]));return"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}},OutputTXT:async(a,b,c=null)=>{try{b="string"!==typeof b?"Anonymous.txt":b.endsWith(".txt")?b:`${b}.txt`;const d=new Blob([a],{type:"text/plain"}),e=document.createElement("a");e.href=URL.createObjectURL(d);e.download=b;e.click();URL.revokeObjectURL(e.href);e.remove();c&&c({State:!0})}catch(d){c&&c({State:!1,Info:d})}},OutputJson:async(a,b,c=null)=>{try{a="string"!==typeof a?JSON.stringify(a,null,4):a;b="string"!==typeof b?"Anonymous.json":b.endsWith(".json")?b:`${b}.json`;const d=new Blob([a],{type:"application/json"}),e=document.createElement("a");e.href=URL.createObjectURL(d);e.download=b;e.click();URL.revokeObjectURL(e.href);e.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,lable: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,k)=>c[k]??"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)}},Menu:async(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)=>v[a](b,c),StoreListen:async(a,b)=>{a.forEach(c=>{u[c]||(u[c]=!0,GM_addValueChangeListener(c,function(d,e,k,g){b({key:d,ov:e,nv:k,far:g})}))})}}})();