Syntax_min

Library for simplifying code logic and syntax

Este script no debería instalarse directamente. Es una biblioteca que utilizan otros scripts mediante la meta-directiva de inclusión // @require https://update.greatest.deepsurf.us/scripts/495339/1577558/Syntax_min.js

// ==UserScript==
// @name         Syntax
// @version      2025/04/25
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax
// @namespace    https://greatest.deepsurf.us/users/989635
// @match        *://*/*
// @license      MPL-2.0
// ==/UserScript==
const Syn=(()=>{function t(a=document,b,c){const d=b[0],e=b.slice(1);if(/[ #.\[:]/.test(e))return c?a.querySelectorAll(b):a.querySelector(b);if(!c&&"#"===d)return document.getElementById(e);if("."===b[0])return a=a.getElementsByClassName(e),c?[...a]:a[0];a=a.getElementsByTagName(b);return c?[...a]:a[0]}async function K(a,b,c,d){let e=document.getElementById(c);if(!e)e=document.createElement(a),e.id=c,document.head.appendChild(e);else if(!d)return;e.textContent+=b}function L(a,b,c,d){let e;return null!=c?M[u(c)](b,a,c):(e=b.getItem(a),void 0!=e?M[u(JSON.parse(e))](b,e):d)}function D(a,b){let c=0;return(...d)=>{const e=Date.now();e-c>=b&&(c=e,a(...d))}}function E(a,b){let c=null;return(...d)=>{clearTimeout(c);c=setTimeout(function(){a(...d)},b)}}const z={},S=new DOMParser,u=a=>Object.prototype.toString.call(a).slice(8,-1);[Document.prototype,Element.prototype].forEach(a=>{a.$q=function(b){return t(this,b,!1)};a.$qa=function(b){return t(this,b,!0)}});const F={$text(a=null){return null!==a?this.textContent=a?.trim():this.textContent?.trim()},$copy(a=!0){return this.cloneNode(a)},$iHtml(a=null){return null!==a?this.innerHTML=a:this.innerHTML},$oHtml(a=null){return null!==a?this.outerHTML=a:this.outerHTML},$sAttr(a,b){this.setAttribute(a,b)},$dAttr(a){this.removeAttribute(a)},$gAttr(a){return this.getAttribute(a)},$hAttr(a){return this.hasAttribute(a)},$addClass(...a){this.classList.add(...a)},$delClass(...a){this.classList.remove(...a)},$toggleClass(a,b){this.classList.toggle(a,b)},$replaceClass(a,b){this.classList.replace(a,b)},$hasClass(a){return this.classList.contains(a)}};Object.assign(Node.prototype,F);const N=Object.keys(F)[0];Object.defineProperty(Object.prototype,N,{value:function(a=null){return F[N].call(this,a)},writable:!0,configurable:!0});const T={$q:document.$q.bind(document),$qa:document.$qa.bind(document),html:document.documentElement,head:document.head,body:document.body,img:document.images,link:document.links,script:document.scripts,style:document.styleSheets,get url(){return location.href},get origin(){return location.origin},get domain(){return location.hostname},get lang(){return navigator.language},get agen(){return navigator.userAgent},get createFragment(){return document.createDocumentFragment()},title:(a=null)=>null!==a?document.title=a:document.title,cookie:(a=null)=>null!==a?document.cookie=a:document.cookie,createUrl:a=>URL.createObjectURL(a),createElement(a,b,c){const [d,e,h={}]="string"===typeof a?[null,a,b]:[a,b,c];if(e){var {id:f,title:g,class:l,text:k="",rows:m,cols:n,style:q={},attr:v={},...A}=h,p=Object.assign(document.createElement(e),{textContent:k});f&&(p.id=f);g&&(p.title=g);l&&(p.className=l);void 0!==m&&(p.rowSpan=m);void 0!==n&&(p.colSpan=n);Object.assign(p,A);Object.assign(p.style,"string"===typeof q?{cssText:q}:q);Object.entries(v).forEach(([w,O])=>p.setAttribute(w,O));return d instanceof HTMLElement?d.appendChild(p):p}}},y=new Map,P={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)};var U=(a,b)=>{a=a.map(c=>t(document,c,b));return b?a.every(c=>0<c.length)&&a:a.every(Boolean)&&a},V=(a,b)=>{a=t(document,a,b);return(b?0<a.length:a)&&a};const M={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)},Q={Process:(a,b,c=null)=>{a=a[b.toLowerCase()];return"Function"===u(a)?a(c):void 0!==a?a:"None"}},G={ko:"Korea","ko-KR":"Korea",ja:"Japan","ja-JP":"Japan",ru:"Russia","ru-RU":"Russia",en:"English","en-US":"English","en-GB":"English","en-AU":"English","en-CA":"English","en-NZ":"English","en-IE":"English","en-ZA":"English","en-IN":"English",zh:"Simplified","zh-CN":"Simplified","zh-SG":"Simplified","zh-MY":"Simplified","zh-TW":"Traditional","zh-HK":"Traditional","zh-MO":"Traditional"},H=new Set,I=a=>void 0===a||null===a?null:a;return{sX:()=>window.scrollX,sY:()=>window.scrollY,iW:()=>window.innerWidth,iH:()=>window.innerHeight,_Cache:void 0,Platform:function(){this._Cache||(void 0!==navigator.userAgentData?.mobile?this._Cache=navigator.userAgentData.mobile?"Mobile":"Desktop":window.matchMedia?.("(max-width: 767px), (pointer: coarse)")?.matches?this._Cache="Mobile":/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?this._Cache="Mobile":this._Cache="Desktop");return this._Cache},...T,AddStyle:(a,b,c=!0)=>K("style",a,b,c),AddScript:(a,b,c=!0)=>K("script",a,b,c),Session:(a,{value:b=null,error:c}={})=>L(a,sessionStorage,b,c),Local:(a,{value:b=null,error:c}={})=>L(a,localStorage,b,c),dV:a=>GM_deleteValue(a),lV:()=>I(GM_listValues()),sV:(a,b)=>GM_setValue(a,b),gV:(a,b)=>I(GM_getValue(a,b)),sJV:(a,b,c=0)=>GM_setValue(a,JSON.stringify(b,null,c)),gJV:(a,b)=>{try{return JSON.parse(I(GM_getValue(a,b)))}catch{return b}},Type:u,one:async function(a,b,c,d={},e=null){try{let h=b.split(/\s*[,|/]\s*/).filter(Boolean),f=null,g=1<h.length?15:0;const l=k=>{clearTimeout(f);f=setTimeout(()=>c(k),g)};"string"===typeof a&&(a=t(document,a));h.forEach(k=>a.addEventListener(k,l,d));e&&e(!0)}catch{e&&e(!1)}},onEvent:async function(a,b,c,d={}){const {mark:e,...h}=d;"string"===typeof a&&(a=t(document,a));d=e??a;const f=y.get(d);f?.has(b)||(a.addEventListener(b,c,h),f||y.set(d,new Map),y.get(d).set(b,c))},offEvent:async function(a,b,c){"string"===typeof a&&(a=t(document,a));c=c??a;const d=y.get(c)?.get(b);d&&(a.removeEventListener(b,d),y.get(c).delete(b))},onUrlChange:function(a,b=15){function c(m){clearTimeout(e);f||"urlchange"!==m||(f=!0);e=setTimeout(()=>{f&&d(!1,!0);a({type:m,url:location.href,domain:location.hostname})},Math.max(15,b))}function d(m=!0,n=!1){n&&h||(clearTimeout(e),history.pushState=g,history.replaceState=l,m&&window.removeEventListener("urlchange",k.urlchange),window.removeEventListener("popstate",k.popstate),window.removeEventListener("hashchange",k.hashchange),h=!0)}let e=null,h=!1,f=!1;const g=history.pushState,l=history.replaceState,k={urlchange:()=>c("urlchange"),popstate:()=>c("popstate"),hashchange:()=>c("hashchange")};window.addEventListener("urlchange",k.urlchange);window.addEventListener("popstate",k.popstate);window.addEventListener("hashchange",k.hashchange);history.pushState=function(){g.apply(this,arguments);c("pushState")};history.replaceState=function(){l.apply(this,arguments);c("replacestate")};return{off:d}},Log:async function(a=null,b="print",{dev:c=!0,type:d="log",collapsed:e=!0}={}){c&&(c=P[d]||P.log,null==a?c(b):(e?console.groupCollapsed(a):console.group(a),c(b),console.groupEnd()))},Observer:async function(a,b,c={},d=null){const {mark:e="",debounce:h=0,throttle:f=100,subtree:g=!0,childList:l=!0,attributes:k=!0,characterData:m=!1}=c??{};if(e){if(z[e])return;z[e]=!0}const [n,q]=0<h?[E,h]:[D,f];c={subtree:g,childList:l,attributes:k,characterData:m};const v=new MutationObserver(n(()=>{b()},q));v.observe(a,c);d&&d({ob:v,op:c})},WaitElem:async function(a,b=null,c={}){const d=Array.isArray(a)?U:V,{raf:e=!1,all:h=!1,timeout:f=8,throttle:g=0,debounce:l=50,visibility:k=!0,subtree:m=!0,childList:n=!0,attributes:q=!0,characterData:v=!1,timeoutResult:A=!1,root:p=document}=c??{};return new Promise((w,O)=>{const R=async function(){let B,r;if(e){let x;const C=()=>{(r=d(a,h))?(cancelAnimationFrame(x),clearTimeout(B),b&&b(r),w(r)):x=requestAnimationFrame(C)};x=requestAnimationFrame(C);B=setTimeout(()=>{cancelAnimationFrame(x);A&&(b&&b(r),w(r))},1E3*f)}else{const [x,C]=0<g?[D,g]:[E,l],J=new MutationObserver(x(()=>{if(r=d(a,h))J.disconnect(),clearTimeout(B),b&&b(r),w(r)},C));J.observe(p,{subtree:m,childList:n,attributes:q,characterData:v});B=setTimeout(()=>{J.disconnect();A&&(b&&b(r),w(r))},1E3*f)}};k&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>R(),{once:!0}):R()})},Throttle:D,Debounce:E,ScopeParsing:function(a,b){if("string"!==typeof a||""===a.trim())return b;const c=b.length,d=new Set,e=new Set,h=(g,l,k)=>{const m=g<=l;for(;m?g<=l:g>=l;m?g++:g--)k.add(g)};let f;for(f of a.split(/\s*[\.,|/]\s*/))if(/^(!|-)?\d+(~\d+|-\d+)?$/.test(f)){a=f.slice(1);const g=/^[!-]/.test(f),l=/[~-]/.test(a),[k,m]=g?[e,a]:[d,f],[n,q]=l?m.split(/-|~/):[m,m];n==q?k.add(+n-1):h(+n-1,+q-1,k)}return[...d].filter(g=>!e.has(g)&&g<c&&0<=g).sort((g,l)=>g-l).map(g=>b[g])},FormatTemplate:function(a,b){if("Object"!==u(a))return"Template must be an object";a=Object.fromEntries(Object.entries(a).map(([c,d])=>[c.toLowerCase(),d]));return"String"===u(b)?b.replace(/\{\s*([^}\s]+)\s*\}/g,(c,d)=>Q.Process(a,d)):"Object"===u(b)?Object.entries(b).map(([c,d])=>Q.Process(a,c,d)):{"Unsupported format":b}},OutputTXT:async function(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 function(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})}},Runtime:function(a=null,{lable:b="Elapsed Time:",log:c=!0,format:d=!0,style:e="\u001b[1m\u001b[36m%s\u001b[0m"}={}){if(!a)return performance.now();a=d?`${((performance.now()-a)/1E3).toPrecision(3)}s`:performance.now()-a;return c?console.log(e,`${b} ${a}`):a},GetDate:function(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,h)=>c[h]??"Error"))("string"===typeof a?a:"{year}-{month}-{date} {hour}:{minute}:{second}")},TranslMatcher:function(a,b=navigator.language,c="en-US"){return a[G[b]]??a[G[c]]??a[G["en-US"]]},Menu:function(a,b={}){let {name:c="Menu",index:d=1,reset:e=!1}=b??{};e&&([...H].map(h=>GM_unregisterMenuCommand(h)),H.clear());for(let [h,f]of Object.entries(a))a=`${c}-${d++}`,"function"===typeof f&&(f={func:f}),GM_registerMenuCommand(h,()=>{f.func()},{id:a,title:f.desc,autoClose:f.close,accessKey:f.hotkey}),H.add(a)},StoreListen:async function(a,b){a.forEach(c=>{z[c]||(z[c]=!0,GM_addValueChangeListener(c,function(d,e,h,f){b({key:d,ov:e,nv:h,far:f})}))})},WorkerCreation:a=>{a=new Blob([a],{type:"application/javascript"});return new Worker(URL.createObjectURL(a))},Sleep:a=>new Promise(b=>setTimeout(b,a)),DomParse:a=>S.parseFromString(a,"text/html"),NameFilter:a=>a.replace(/[\/\?<>\\:\*\|":]/g,""),GetFill:a=>Math.max(2,`${a}`.length),ExtensionName:a=>{try{return a.match(/\.([^.]+)$/)[1].toLowerCase()||"webp"}catch{return"webp"}},Mantissa:function(a,b,c="0",d=null){return d?`${++a}`.padStart(b,c)+`.${this.ExtensionName(d)}`:`${++a}`.padStart(b,c)}}})();