SyntaxLite_min

Library for simplifying code logic and syntax (Lite)

Ce script ne devrait pas être installé directement. C'est une librairie créée pour d'autres scripts. Elle doit être inclus avec la commande // @require https://update.greasyfork.org/scripts/487608/1616382/SyntaxLite_min.js

// ==UserScript==
// @name         SyntaxLite
// @version      2025/06/30
// @author       Canaan HS
// @description  Library for simplifying code logic and syntax (Lite)
// @namespace    https://greasyfork.org/users/989635
// @match        *://*/*
// @license      MPL-2.0
// ==/UserScript==
const Syn=(()=>{function q(a=document,b,c){const e=b[0],d=b.slice(1);if(/[ #.\[:]/.test(d))return c?a.querySelectorAll(b):a.querySelector(b);if(!c&&"#"===e)return a.getElementById(d);if("."===b[0])return a=a.getElementsByClassName(d),c?[...a]:a[0];a=a.getElementsByTagName(b);return c?[...a]:a[0]}async function N(a,b,c,e){let d=document.getElementById(c);if(!d)d=document.createElement(a),d.id=c,(a=D.head)?a.appendChild(d):O("head").then(f=>{D.head=f;f.appendChild(d)});else if(!e)return;d.textContent+=
b}async function O(a,b=null,c={}){const e=Array.isArray(a)?P.queryMap:P.queryElement,{raf:d=!1,all:f=!1,timeout:g=8,throttle:n=0,debounce:l=50,visibility:p=!0,subtree:r=!0,childList:v=!0,attributes:w=!0,characterData:x=!1,timeoutResult:A=!1,root:E=document}=c??{};return new Promise((h,t)=>{const k=async function(){let u,m;if(d){let y;const B=()=>{(m=e(a,f))?(cancelAnimationFrame(y),clearTimeout(u),b&&b(m),h(m)):y=requestAnimationFrame(B)};y=requestAnimationFrame(B);u=setTimeout(()=>{cancelAnimationFrame(y);
A&&(b&&b(m),h(m))},1E3*g)}else{const [y,B]=0<n?[F,n]:[G,l],H=new MutationObserver(y(()=>{if(m=e(a,f))H.disconnect(),clearTimeout(u),b&&b(m),h(m)},B));H.observe(E,{subtree:r,childList:v,attributes:w,characterData:x});u=setTimeout(()=>{H.disconnect();A&&(b&&b(m),h(m))},1E3*g)}};p&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>k(),{once:!0}):k()})}function Q(a,b,c,e){let d;return null!=c?R[I(c)](b,a,c):(d=b.getItem(a),void 0!=d?R[I(JSON.parse(d))](b,d):e)}function F(a,
b){let c=0;return(...e)=>{const d=Date.now();d-c>=b&&(c=d,a(...e))}}function G(a,b){let c=null;return(...e)=>{clearTimeout(c);c=setTimeout(function(){a(...e)},b)}}const C={},I=a=>Object.prototype.toString.call(a).slice(8,-1);[Document.prototype,Element.prototype].forEach(a=>{a.$q=function(b){return q(this,b,!1)};a.$qa=function(b){return q(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 D={$q:document.$q.bind(document),Q:(a,b)=>q(a,b,!1),$qa:document.$qa.bind(document),Qa:(a,b)=>q(a,b,!0),html:document.documentElement,head:document.head??q(document,"head",!1),body:document.body??q(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:e})=>
"string"===typeof b&&"function"===typeof c?(a.addEventListener(b,c,e),{[b]:()=>a.removeEventListener(b,c,e)}):{},createElement(a,b,c){const [e,d,f={}]="string"===typeof a?[null,a,b]:[a,b,c];if(d){var {id:g,title:n,class:l,text:p="",rows:r,cols:v,on:w={},style:x={},attr:A={},...E}=f,h=Object.assign(document.createElement(d),{textContent:p});g&&(h.id=g);n&&(h.title=n);l&&(h.className=l);void 0!==r&&(h.rowSpan=r);void 0!==v&&(h.colSpan=v);Object.assign(h,E);Object.assign(h.style,"string"===typeof x?
{cssText:x}:x);Object.entries(A).forEach(([k,u])=>h.setAttribute(k,u));var t={};"object"===typeof w?Object.assign(t,this._on(h,w)):Array.isArray(w)&&w.forEach(k=>Object.assign(t,this._on(h,k)));Object.assign(h,{on(k,u,m){this.addEventListener(k,u,m);Object.assign(t,{[k]:()=>this.removeEventListener(k,u,m)})},off(k){t[k]?.();delete t[k]},offAll(){Object.keys(t).forEach(k=>{t[k]();delete t[k]})}});return e instanceof HTMLElement?e.appendChild(h):h}}},z=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=>q(document,c,b));return b?a.every(c=>0<c.length)&&a:a.every(Boolean)&&a},queryElement:(a,b)=>{a=q(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)},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 function(...a){const b={};for(const c of a)c&&Object.defineProperties(b,Object.getOwnPropertyDescriptors(c));return b}({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}},D,{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),aV:()=>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:I,EventRecord:z,one:async function(a,b,c,e={},d=null){try{"string"===typeof a&&(a=q(document,a));let f=b.split(/\s*[,|/]\s*/).filter(Boolean);if(0===f.length)throw Error("No event types provided");if(1===f.length)a.addEventListener(b,
c,e);else{let g=null;const n=l=>{clearTimeout(g);g=setTimeout(()=>c(l),15)};f.forEach(l=>a.addEventListener(l,n,e))}d&&d(!0)}catch{d&&d(!1)}},onEvent:async function(a,b,c,e={}){const {mark:d,...f}=e;"string"===typeof a&&(a=q(document,a));e=d??a;const g=z.get(e);g?.has(b)||(a.addEventListener(b,c,f),g||z.set(e,new Map),z.get(e).set(b,c))},offEvent:async function(a,b,c){"string"===typeof a&&(a=q(document,a));c=c??a;const e=z.get(c)?.get(b);e&&(a.removeEventListener(b,e),z.get(c).delete(b))},onUrlChange:function(a,
b=15){function c(r){clearTimeout(d);g||"urlchange"!==r||(g=!0);d=setTimeout(()=>{g&&e(!1,!0);a({type:r,url:location.href,domain:location.hostname})},Math.max(15,b))}function e(r=!0,v=!1){v&&f||(clearTimeout(d),history.pushState=n,history.replaceState=l,r&&window.removeEventListener("urlchange",p.urlchange),window.removeEventListener("popstate",p.popstate),window.removeEventListener("hashchange",p.hashchange),f=!0)}let d=null,f=!1,g=!1;const n=history.pushState,l=history.replaceState,p={urlchange:()=>
c("urlchange"),popstate:()=>c("popstate"),hashchange:()=>c("hashchange")};window.addEventListener("urlchange",p.urlchange);window.addEventListener("popstate",p.popstate);window.addEventListener("hashchange",p.hashchange);history.pushState=function(){n.apply(this,arguments);c("pushState")};history.replaceState=function(){l.apply(this,arguments);c("replacestate")};return{off:e}},Log:async function(a=null,b="print",{dev:c=!0,type:e="log",collapsed:d=!0}={}){c&&(c=T[e]||T.log,null==a?c(b):(d?console.groupCollapsed(a):
console.group(a),c(b),console.groupEnd()))},Observer:async function(a,b,c={},e=null){const {mark:d="",debounce:f=0,throttle:g=100,subtree:n=!0,childList:l=!0,attributes:p=!0,characterData:r=!1}=c??{};if(d){if(C[d])return;C[d]=!0}const [v,w]=0<f?[G,f]:[F,g];c={subtree:n,childList:l,attributes:p,characterData:r};const x=new MutationObserver(v(()=>{b()},w));x.observe(a,c);e&&e({ob:x,op:c})},WaitElem:O,Throttle:F,Debounce:G,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 e=new Blob([a],{type:"application/json"}),d=document.createElement("a");d.href=URL.createObjectURL(e);d.download=b;d.click();URL.revokeObjectURL(d.href);d.remove();c&&c({State:!0})}catch(e){c&&c({State:!1,Info:e})}},Runtime:function(a=null,{lable:b="Elapsed Time:",log:c=!0,format:e=!0,style:d="\u001b[1m\u001b[36m%s\u001b[0m"}={}){if(!a)return performance.now();a=e?`${((performance.now()-a)/1E3).toPrecision(3)}s`:
performance.now()-a;return c?console.log(d,`${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(e=>e.replace(/{([^}]+)}/g,(d,f)=>c[f]??"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:async function(a,b={}){let {name:c="Menu",index:e=1,reset:d=!1}=b??{};d&&([...L].map(f=>GM_unregisterMenuCommand(f)),L.clear());for(let [f,g]of Object.entries(a))a=`${c}-${e++}`,"function"===typeof g&&(g={func:g}),GM_registerMenuCommand(f,()=>{g.func()},{id:a,title:g.desc,autoClose:g.close,accessKey:g.hotkey}),L.add(a)},StoreListen:async function(a,b){a.forEach(c=>{C[c]||(C[c]=!0,GM_addValueChangeListener(c,function(e,d,f,g){b({key:e,ov:d,nv:f,
far:g})}))})}})})();