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.greasyforks.org/scripts/495339/1613824/Syntax_min.js

// ==UserScript==
// @name         Syntax
// @version      2025/06/25
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax
// @namespace    https://greasyforks.org/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 N(a,b,c,d){let e=document.getElementById(c);if(!e)e=document.createElement(a),e.id=c,(a=E.head)?a.appendChild(e):O("head").then(g=>{E.head=g;g.appendChild(e)});else if(!d)return;e.textContent+=
b}async function O(a,b=null,c={}){const d=Array.isArray(a)?P.queryMap:P.queryElement,{raf:e=!1,all:g=!1,timeout:f=8,throttle:h=0,debounce:k=50,visibility:n=!0,subtree:l=!0,childList:r=!0,attributes:u=!0,characterData:x=!1,timeoutResult:B=!1,root:F=document}=c??{};return new Promise((m,v)=>{const p=async function(){let w,q;if(e){let z;const C=()=>{(q=d(a,g))?(cancelAnimationFrame(z),clearTimeout(w),b&&b(q),m(q)):z=requestAnimationFrame(C)};z=requestAnimationFrame(C);w=setTimeout(()=>{cancelAnimationFrame(z);
B&&(b&&b(q),m(q))},1E3*f)}else{const [z,C]=0<h?[G,h]:[H,k],I=new MutationObserver(z(()=>{if(q=d(a,g))I.disconnect(),clearTimeout(w),b&&b(q),m(q)},C));I.observe(F,{subtree:l,childList:r,attributes:u,characterData:x});w=setTimeout(()=>{I.disconnect();B&&(b&&b(q),m(q))},1E3*f)}};n&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>p(),{once:!0}):p()})}function Q(a,b,c,d){let e;return null!=c?R[y(c)](b,a,c):(e=b.getItem(a),void 0!=e?R[y(JSON.parse(e))](b,e):d)}function G(a,
b){let c=0;return(...d)=>{const e=Date.now();e-c>=b&&(c=e,a(...d))}}function H(a,b){let c=null;return(...d)=>{clearTimeout(c);c=setTimeout(function(){a(...d)},b)}}const D={},V=new DOMParser,y=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 J={$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,J);const S=Object.keys(J)[0];Object.defineProperty(Object.prototype,S,{value:function(a=null){return J[S].call(this,a)},writable:!0,configurable:!0});const E={$q:document.$q.bind(document),Q:(a,b)=>t(a,b,!1),$qa:document.$qa.bind(document),Qa:(a,b)=>t(a,b,!0),html:document.documentElement,head:document.head??t(document,"head",!1),body:document.body??t(document,"body",!1),img:document.images,link:document.links,script:document.scripts,style:document.styleSheets,$url:location.href,
get url(){return location.href},$origin:location.origin,get origin(){return location.origin},$domain:location.hostname,get domain(){return location.hostname},$lang:navigator.language,get lang(){return navigator.language},$agen:navigator.userAgent,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),
_on:(a,{type:b,listener:c,add:d})=>"string"===typeof b&&"function"===typeof c?(a.addEventListener(b,c,d),{[b]:()=>a.removeEventListener(b,c,d)}):{},createElement(a,b,c){const [d,e,g={}]="string"===typeof a?[null,a,b]:[a,b,c];if(e){var {id:f,title:h,class:k,text:n="",rows:l,cols:r,on:u={},style:x={},attr:B={},...F}=g,m=Object.assign(document.createElement(e),{textContent:n});f&&(m.id=f);h&&(m.title=h);k&&(m.className=k);void 0!==l&&(m.rowSpan=l);void 0!==r&&(m.colSpan=r);Object.assign(m,F);Object.assign(m.style,
"string"===typeof x?{cssText:x}:x);Object.entries(B).forEach(([p,w])=>m.setAttribute(p,w));var v={};"object"===typeof u?Object.assign(v,this._on(m,u)):Array.isArray(u)&&u.forEach(p=>Object.assign(v,this._on(m,p)));Object.assign(m,{on(p,w,q){this.addEventListener(p,w,q);Object.assign(v,{[p]:()=>this.removeEventListener(p,w,q)})},off(p){v[p]?.();delete v[p]},offAll(){Object.keys(v).forEach(p=>{v[p]();delete v[p]})}});return d instanceof HTMLElement?d.appendChild(m):m}}},A=new Map,T={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)},P={queryMap:(a,b)=>{a=a.map(c=>t(document,c,b));return b?a.every(c=>0<c.length)&&a:a.every(Boolean)&&a},queryElement:(a,b)=>{a=t(document,a,b);return(b?0<a.length:a)&&a}},R={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)},U={Process:(a,b,c=null)=>{a=a[b.toLowerCase()];return"Function"===y(a)?a(c):void 0!==a?a:"None"}},K={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"},L=new Set,M=a=>void 0===a||null===a?null:a;return{get sX(){return window.scrollX},get sY(){return window.scrollY},get iW(){return window.innerWidth},get iH(){return window.innerHeight},_Cache:void 0,get Platform(){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},...E,AddStyle:(a,b,c=!0)=>N("style",a,b,c),AddScript:(a,b,c=!0)=>N("script",a,b,c),Session:(a,{value:b=null,error:c}={})=>Q(a,sessionStorage,b,c),Local:(a,{value:b=
null,error:c}={})=>Q(a,localStorage,b,c),dV:a=>GM_deleteValue(a),lV:()=>M(GM_listValues()),sV:(a,b)=>GM_setValue(a,b),gV:(a,b)=>M(GM_getValue(a,b)),sJV:(a,b,c=0)=>GM_setValue(a,JSON.stringify(b,null,c)),gJV:(a,b)=>{try{return JSON.parse(M(GM_getValue(a,b)))}catch{return b}},Type:y,EventRecord:A,one:async function(a,b,c,d={},e=null){try{"string"===typeof a&&(a=t(document,a));let g=b.split(/\s*[,|/]\s*/).filter(Boolean);if(0===g.length)throw Error("No event types provided");if(1===g.length)a.addEventListener(b,
c,d);else{let f=null;const h=k=>{clearTimeout(f);f=setTimeout(()=>c(k),15)};g.forEach(k=>a.addEventListener(k,h,d))}e&&e(!0)}catch{e&&e(!1)}},onEvent:async function(a,b,c,d={}){const {mark:e,...g}=d;"string"===typeof a&&(a=t(document,a));d=e??a;const f=A.get(d);f?.has(b)||(a.addEventListener(b,c,g),f||A.set(d,new Map),A.get(d).set(b,c))},offEvent:async function(a,b,c){"string"===typeof a&&(a=t(document,a));c=c??a;const d=A.get(c)?.get(b);d&&(a.removeEventListener(b,d),A.get(c).delete(b))},onUrlChange:function(a,
b=15){function c(l){clearTimeout(e);f||"urlchange"!==l||(f=!0);e=setTimeout(()=>{f&&d(!1,!0);a({type:l,url:location.href,domain:location.hostname})},Math.max(15,b))}function d(l=!0,r=!1){r&&g||(clearTimeout(e),history.pushState=h,history.replaceState=k,l&&window.removeEventListener("urlchange",n.urlchange),window.removeEventListener("popstate",n.popstate),window.removeEventListener("hashchange",n.hashchange),g=!0)}let e=null,g=!1,f=!1;const h=history.pushState,k=history.replaceState,n={urlchange:()=>
c("urlchange"),popstate:()=>c("popstate"),hashchange:()=>c("hashchange")};window.addEventListener("urlchange",n.urlchange);window.addEventListener("popstate",n.popstate);window.addEventListener("hashchange",n.hashchange);history.pushState=function(){h.apply(this,arguments);c("pushState")};history.replaceState=function(){k.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=T[d]||T.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:g=0,throttle:f=100,subtree:h=!0,childList:k=!0,attributes:n=!0,characterData:l=!1}=c??{};if(e){if(D[e])return;D[e]=!0}const [r,u]=0<g?[H,g]:[G,f];c={subtree:h,childList:k,attributes:n,characterData:l};const x=new MutationObserver(r(()=>{b()},u));x.observe(a,c);d&&d({ob:x,op:c})},WaitElem:O,Throttle:G,Debounce:H,ScopeParsing:function(a,b){if("string"!==typeof a||""===a.trim())return b;const c=
b.length,d=new Set,e=new Set,g=(h,k,n)=>{const l=h<=k;for(;l?h<=k:h>=k;l?h++:h--)n.add(h)};let f;for(f of a.split(/\s*[\.,|/]\s*/))if(/^(!|-)?\d+(~\d+|-\d+)?$/.test(f)){a=f.slice(1);const h=/^[!-]/.test(f),k=/[~-]/.test(a),[n,l]=h?[e,a]:[d,f],[r,u]=k?l.split(/-|~/):[l,l];r==u?n.add(+r-1):g(+r-1,+u-1,n)}return[...d].filter(h=>!e.has(h)&&h<c&&0<=h).sort((h,k)=>h-k).map(h=>b[h])},FormatTemplate:function(a,b){if("Object"!==y(a))return"Template must be an object";a=Object.fromEntries(Object.entries(a).map(([c,
d])=>[c.toLowerCase(),d]));return"String"===y(b)?b.replace(/\{\s*([^}\s]+)\s*\}/g,(c,d)=>U.Process(a,d)):"Object"===y(b)?Object.entries(b).map(([c,d])=>U.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,g)=>c[g]??"Error"))("string"===typeof a?a:"{year}-{month}-{date} {hour}:{minute}:{second}")},
TranslMatcher:function(a,b=navigator.language,c="en-US"){return a[K[b]]??a[K[c]]??a[K["en-US"]]},Menu:function(a,b={}){let {name:c="Menu",index:d=1,reset:e=!1}=b??{};e&&([...L].map(g=>GM_unregisterMenuCommand(g)),L.clear());for(let [g,f]of Object.entries(a))a=`${c}-${d++}`,"function"===typeof f&&(f={func:f}),GM_registerMenuCommand(g,()=>{f.func()},{id:a,title:f.desc,autoClose:f.close,accessKey:f.hotkey}),L.add(a)},StoreListen:async function(a,b){a.forEach(c=>{D[c]||(D[c]=!0,GM_addValueChangeListener(c,
function(d,e,g,f){b({key:d,ov:e,nv:g,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=>V.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)}}})();
长期地址
遇到问题?请前往 GitHub 提 Issues。