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/1652116/SyntaxLite_min.js

// ==UserScript==
// @name         SyntaxLite
// @version      2025.08.31
// @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 Lib=(()=>{function q(a=document,b,c){if(1!==a?.nodeType&&9!==a?.nodeType)return c?[]:void 0;const e=b[0],d=b.slice(1);if(/[ .#:[\]>+~*,()^$=]/.test(d))return c?a.querySelectorAll(b):a.querySelector(b);if(!c&&"#"===e)return 9===a.nodeType?a.getElementById(d):a.querySelector(b);if("."===b[0])return a=a.getElementsByClassName(d),c?[...a]:a[0];a=a.getElementsByTagName(b);return c?[...a]:a[0]}async function P(a,b,c=crypto.randomUUID(),e=!0){if(e||!F.has(c)){var d=document.getElementById(c);d||(d=
document.createElement(a),d.id=c,(a=G.head)?a.appendChild(d):Q("head").then(f=>{G.head=f;f.appendChild(d)}));d.textContent+=b;F.add(c)}}async function Q(a,b=null,c={}){const e=Array.isArray(a)?R.queryMap:R.queryElement,{raf:d=!1,all:f=!1,timeout:g=8,throttle:l=0,debounce:m=50,visibility:p=!0,subtree:r=!0,childList:w=!0,attributes:x=!0,characterData:t=!1,timeoutResult:C=!1,root:H=document}=c||{};return new Promise((h,u)=>{const k=async function(){let v,n;if(d){let z;const D=()=>{(n=e(a,f))?(cancelAnimationFrame(z),
clearTimeout(v),b?.(n),h(n)):z=requestAnimationFrame(D)};z=requestAnimationFrame(D);v=setTimeout(()=>{cancelAnimationFrame(z);C&&(b?.(n),h(n))},1E3*g)}else{const [z,D]=0<l?[I,l]:[J,m],K=new MutationObserver(z(()=>{if(n=e(a,f))K.disconnect(),clearTimeout(v),b?.(n),h(n)},D));K.observe(H,{subtree:r,childList:w,attributes:x,characterData:t});v=setTimeout(()=>{K.disconnect();C&&(b?.(n),h(n))},1E3*g)}};p&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",()=>k(),{once:!0}):
k()})}function S(a,b,c,e){let d;return null!=c?T[L(c)](b,a,c):(d=b.getItem(a),void 0!=d?T[L(JSON.parse(d))](b,d):e)}function I(a,b){let c=0;return(...e)=>{const d=Date.now();d-c>=b&&(c=d,a(...e))}}function J(a,b){let c=null;return(...e)=>{clearTimeout(c);c=setTimeout(function(){a(...e)},b)}}const L=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 M={$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,M);const U=Object.keys(M)[0];Object.defineProperty(Object.prototype,U,{value:function(a=null){return M[U].call(this,a)},writable:!0,configurable:!0});const G={$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:l,class:m,text:p="",rows:r,cols:w,on:x={},style:t={},attr:C={},...H}=f,h=Object.assign(document.createElement(d),{textContent:p});g&&(h.id=g);l&&
(h.title=l);m&&(h.className=m);void 0!==r&&(h.rowSpan=r);void 0!==w&&(h.colSpan=w);Object.assign(h,H);Object.assign(h.style,"string"===typeof t?{cssText:t}:t);Object.entries(C).forEach(([k,v])=>h.setAttribute(k,v));var u={};Array.isArray(x)?x.forEach(k=>Object.assign(u,this._on(h,k))):"object"===typeof x&&Object.assign(u,this._on(h,x));Object.assign(h,{on(k,v,n){this.addEventListener(k,v,n);Object.assign(u,{[k]:()=>this.removeEventListener(k,v,n)})},off(k){u[k]?.();delete u[k]},offAll(){Object.keys(u).forEach(k=>
{u[k]();delete u[k]})}});return 1===e?.nodeType?e.appendChild(h):h}}},A=new Map,V={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)},F=new Set,E=new Map,R={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}},T={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)},N={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"},y=new Set,O=a=>void 0===a||null===a?null:a,B=new Map;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}},G,{addStyle:(a,
b,c)=>P("style",a,b,c),addScript:(a,b,c)=>P("script",a,b,c),session:(a,{value:b=null,error:c}={})=>S(a,sessionStorage,b,c),local:(a,{value:b=null,error:c}={})=>S(a,localStorage,b,c),delV:a=>GM_deleteValue(a),allV:()=>O(GM_listValues()),setV:(a,b)=>GM_setValue(a,b),getV:(a,b)=>O(GM_getValue(a,b)),setJV:(a,b,c=0)=>GM_setValue(a,JSON.stringify(b,null,c)),getJV(a,b){try{return JSON.parse(O(GM_getValue(a,b)))}catch{return b}},eventRecord:A,addRecord:F,observerRecord:E,$type:L,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 l=m=>{clearTimeout(g);g=setTimeout(()=>c(m),15)};f.forEach(m=>a.addEventListener(m,l,e))}d?.(!0)}catch{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=A.get(e);g?.has(b)||(a.addEventListener(b,c,f),g||A.set(e,
new Map),A.get(e).set(b,c))},offEvent:async function(a,b,c){"string"===typeof a&&(a=q(document,a));c=c??a;const e=A.get(c)?.get(b);e&&(a.removeEventListener(b,e),A.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,w=!1){w&&f||(clearTimeout(d),history.pushState=l,history.replaceState=m,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 l=history.pushState,m=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(){l.apply(this,arguments);c("pushState")};history.replaceState=
function(){m.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=V[e]||V.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:l=!0,childList:m=!0,attributes:p=!0,characterData:r=!1}=c||{};if(d&&(c=E.get(d))){if(c.target===a)return;c.ob.disconnect();E.delete(d)}const [w,x]=0<f?[J,
f]:[I,g];c={subtree:l,childList:m,attributes:p,characterData:r};const t=new MutationObserver(w(()=>{b()},x));t.observe(a,c);d&&E.set(d,{target:a,ob:t});e?.({ob:t,op:c})},waitEl:Q,$throttle:I,$debounce:J,outputJson:async function(a,b,c=null){try{a="string"!==typeof a?JSON.stringify(a,null,4):a;b="string"!==typeof b?`Untitled-${crypto.randomUUID().slice(9,23)}.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?.({State:!0})}catch(e){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[N[b]]??a[N[c]]??a[N["en-US"]]},regMenu:function(a,b={}){let {name:c="regMenu",index:e=1,reset:d=!1}=b||{};d&&([...y].map(f=>GM_unregisterMenuCommand(f)),y.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}),y.add(a)},unMenu:async function(a){null==a?([...y].map(b=>GM_unregisterMenuCommand(b)),y.clear()):Array.isArray(a)?a.forEach(b=>{y.delete(b)&&GM_unregisterMenuCommand(b)}):y.delete(a)&&GM_unregisterMenuCommand(a)},storeListen:function(a,b){a.forEach(c=>{if(!B.has(c)){const e=GM_addValueChangeListener(c,function(d,f,g,l){b({key:d,
ov:f,nv:g,far:l})});B.set(c,e)}});return{off(c){const e=B.get(c);e&&(GM_removeValueChangeListener(e),B.delete(c))},offAll(){for(const c of B.values())GM_removeValueChangeListener(c);B.clear()}}}})})();