SyntaxLite

Library for simplifying code logic and syntax (Lite)

Version au 28/05/2025. Voir la dernière version.

Ce script ne doit pas être installé directement. C'est une librairie destinée à être incluse dans d'autres scripts avec la méta-directive // @require https://update.greasyfork.org/scripts/487608/1597491/SyntaxLite.js

Vous devrez installer une extension telle que Tampermonkey, Greasemonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Userscripts pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension de gestionnaire de script utilisateur pour installer ce script.

(J'ai déjà un gestionnaire de scripts utilisateur, laissez-moi l'installer !)

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

(J'ai déjà un gestionnaire de style utilisateur, laissez-moi l'installer!)

// ==UserScript==
// @name         SyntaxLite
// @version      2025/05/28
// @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 r(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 document.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 M(a,b,c,e){let d=document.getElementById(c);if(!d)d=document.createElement(a),d.id=c,document.head.appendChild(d);else if(!e)return;d.textContent+=b}function N(a,b,c,e){let d;return null!=
c?O[D(c)](b,a,c):(d=b.getItem(a),void 0!=d?O[D(JSON.parse(d))](b,d):e)}function E(a,b){let c=0;return(...e)=>{const d=Date.now();d-c>=b&&(c=d,a(...e))}}function F(a,b){let c=null;return(...e)=>{clearTimeout(c);c=setTimeout(function(){a(...e)},b)}}const A={},D=a=>Object.prototype.toString.call(a).slice(8,-1);[Document.prototype,Element.prototype].forEach(a=>{a.$q=function(b){return r(this,b,!1)};a.$qa=function(b){return r(this,b,!0)}});const G={$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,G);const P=Object.keys(G)[0];Object.defineProperty(Object.prototype,P,{value:function(a=null){return G[P].call(this,a)},writable:!0,configurable:!0});const R={$q:document.$q.bind(document),$Q:(a,b)=>r(a,b,!1),$qa:document.$qa.bind(document),$Qa:(a,b)=>r(a,b,!0),html:document.documentElement,head:document.head,body:document.body,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,g={}]="string"===typeof a?[null,a,b]:[a,b,c];if(d){var {id:f,title:n,class:p,text:k="",rows:q,cols:v,on:w={},style:x={},attr:B={},...H}=g,h=Object.assign(document.createElement(d),{textContent:k});f&&(h.id=f);n&&(h.title=n);p&&(h.className=p);void 0!==q&&(h.rowSpan=q);void 0!==v&&(h.colSpan=v);Object.assign(h,H);Object.assign(h.style,
"string"===typeof x?{cssText:x}:x);Object.entries(B).forEach(([l,t])=>h.setAttribute(l,t));var u={};"object"===typeof w?Object.assign(u,this._on(h,w)):Array.isArray(w)&&w.forEach(l=>Object.assign(u,this._on(h,l)));Object.assign(h,{on(l,t,m){this.addEventListener(l,t,m);Object.assign(u,{[l]:()=>this.removeEventListener(l,t,m)})},off(l){u[l]?.();delete u[l]},offAll(){Object.keys(u).forEach(l=>{u[l]();delete u[l]})}});return e instanceof HTMLElement?e.appendChild(h):h}}},y=new Map,Q={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 S=(a,b)=>{a=a.map(c=>r(document,c,b));return b?a.every(c=>0<c.length)&&a:a.every(Boolean)&&a},T=(a,b)=>{a=r(document,a,b);return(b?0<a.length:a)&&a};const O={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)},I={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"},J=new Set,K=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},...R,AddStyle:(a,b,c=!0)=>M("style",a,b,c),AddScript:(a,b,c=!0)=>M("script",a,b,c),Session:(a,{value:b=null,error:c}={})=>N(a,sessionStorage,b,c),Local:(a,{value:b=null,error:c}={})=>N(a,localStorage,b,c),dV:a=>GM_deleteValue(a),lV:()=>K(GM_listValues()),sV:(a,b)=>GM_setValue(a,b),gV:(a,b)=>K(GM_getValue(a,b)),sJV:(a,b,c=0)=>
GM_setValue(a,JSON.stringify(b,null,c)),gJV:(a,b)=>{try{return JSON.parse(K(GM_getValue(a,b)))}catch{return b}},Type:D,EventRecord:y,one:async function(a,b,c,e={},d=null){try{let g=b.split(/\s*[,|/]\s*/).filter(Boolean),f=null,n=1<g.length?15:0;const p=k=>{clearTimeout(f);f=setTimeout(()=>c(k),n)};"string"===typeof a&&(a=r(document,a));g.forEach(k=>a.addEventListener(k,p,e));d&&d(!0)}catch{d&&d(!1)}},onEvent:async function(a,b,c,e={}){const {mark:d,...g}=e;"string"===typeof a&&(a=r(document,a));e=
d??a;const f=y.get(e);f?.has(b)||(a.addEventListener(b,c,g),f||y.set(e,new Map),y.get(e).set(b,c))},offEvent:async function(a,b,c){"string"===typeof a&&(a=r(document,a));c=c??a;const e=y.get(c)?.get(b);e&&(a.removeEventListener(b,e),y.get(c).delete(b))},onUrlChange:function(a,b=15){function c(q){clearTimeout(d);f||"urlchange"!==q||(f=!0);d=setTimeout(()=>{f&&e(!1,!0);a({type:q,url:location.href,domain:location.hostname})},Math.max(15,b))}function e(q=!0,v=!1){v&&g||(clearTimeout(d),history.pushState=
n,history.replaceState=p,q&&window.removeEventListener("urlchange",k.urlchange),window.removeEventListener("popstate",k.popstate),window.removeEventListener("hashchange",k.hashchange),g=!0)}let d=null,g=!1,f=!1;const n=history.pushState,p=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(){n.apply(this,arguments);c("pushState")};history.replaceState=function(){p.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=Q[e]||Q.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:g=0,throttle:f=100,subtree:n=!0,childList:p=!0,attributes:k=!0,characterData:q=!1}=c??{};if(d){if(A[d])return;
A[d]=!0}const [v,w]=0<g?[F,g]:[E,f];c={subtree:n,childList:p,attributes:k,characterData:q};const x=new MutationObserver(v(()=>{b()},w));x.observe(a,c);e&&e({ob:x,op:c})},WaitElem:async function(a,b=null,c={}){const e=Array.isArray(a)?S:T,{raf:d=!1,all:g=!1,timeout:f=8,throttle:n=0,debounce:p=50,visibility:k=!0,subtree:q=!0,childList:v=!0,attributes:w=!0,characterData:x=!1,timeoutResult:B=!1,root:H=document}=c??{};return new Promise((h,u)=>{const l=async function(){let t,m;if(d){let z;const C=()=>
{(m=e(a,g))?(cancelAnimationFrame(z),clearTimeout(t),b&&b(m),h(m)):z=requestAnimationFrame(C)};z=requestAnimationFrame(C);t=setTimeout(()=>{cancelAnimationFrame(z);B&&(b&&b(m),h(m))},1E3*f)}else{const [z,C]=0<n?[E,n]:[F,p],L=new MutationObserver(z(()=>{if(m=e(a,g))L.disconnect(),clearTimeout(t),b&&b(m),h(m)},C));L.observe(H,{subtree:q,childList:v,attributes:w,characterData:x});t=setTimeout(()=>{L.disconnect();B&&(b&&b(m),h(m))},1E3*f)}};k&&"hidden"===document.visibilityState?document.addEventListener("visibilitychange",
()=>l(),{once:!0}):l()})},Throttle:E,Debounce:F,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,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[I[b]]??a[I[c]]??a[I["en-US"]]},Menu:async function(a,b={}){let {name:c="Menu",index:e=1,reset:d=!1}=b??{};d&&([...J].map(g=>GM_unregisterMenuCommand(g)),J.clear());for(let [g,f]of Object.entries(a))a=`${c}-${e++}`,"function"===typeof f&&(f={func:f}),GM_registerMenuCommand(g,()=>{f.func()},{id:a,title:f.desc,autoClose:f.close,accessKey:f.hotkey}),
J.add(a)},StoreListen:async function(a,b){a.forEach(c=>{A[c]||(A[c]=!0,GM_addValueChangeListener(c,function(e,d,g,f){b({key:e,ov:d,nv:g,far:f})}))})}}})();