GrammarSimplified

Simple syntax simplification function

Verzia zo dňa 19.02.2024. Pozri najnovšiu verziu.

Tento skript by nemal byť nainštalovaný priamo. Je to knižnica pre ďalšie skripty, ktorú by mali používať cez meta príkaz // @require https://update.greatest.deepsurf.us/scripts/487608/1330066/GrammarSimplified.js

// ==UserScript==
// @name         GrammarSimplified
// @version      2024/02/20
// @author       HentaiSaru
// @description  Simple syntax simplification function
// @namespace    https://greatest.deepsurf.us/users/989635
// @match        *://*/*
// ==/UserScript==
class API{constructor(){this.ListenerRecord=new Map;this.Parser=new DOMParser;this.GM={__verify:a=>void 0!==a?a:null,set:function(a,c){GM_setValue(a,c)},get:function(a,c){return this.__verify(GM_getValue(a,c))},setjs:function(a,c){GM_setValue(a,JSON.stringify(c,null,4))},getjs:function(a,c){return JSON.parse(this.__verify(GM_getValue(a,c)))}};this.Template={log:a=>console.log(a),warn:a=>console.warn(a),error:a=>console.error(a),count:a=>console.count(a)}}$$(a,c=!1,b=document){const d=a.slice(1);switch([" ",".","#","="].some(e=>d.includes(e))?" ":a[0]){case "#":return b.getElementById(d);case " ":return c?b.querySelectorAll(a):b.querySelector(a);case ".":a=b.getElementsByClassName(d);break;default:a=b.getElementsByTagName(a)}return c?Array.from(a):a[0]}DomParse(a){return this.Parser.parseFromString(a,"text/html")}IllegalCharacters(a){return a.replace(/[\/\?<>\\:\*\|":]/g,"")}ExtensionName(a){try{return a.match(/\.([^.]+)$/)[1].toLowerCase()||"png"}catch{return"png"}}WorkerCreation(a){a=new Blob([a],{type:"application/javascript"});return new Worker(URL.createObjectURL(a))}async AddStyle(a,c="New-Style"){let b=document.getElementById(c);b||(b=document.createElement("style"),b.id=c,document.head.appendChild(b));b.appendChild(document.createTextNode(a))}async AddScript(a,c="New-Script"){let b=document.getElementById(c);b||(b=document.createElement("script"),b.id=c,document.head.appendChild(b));b.appendChild(document.createTextNode(a))}async AddListener(a,c,b,d={}){this.ListenerRecord.has(a)&&this.ListenerRecord.get(a).has(c)||(a.addEventListener(c,b,d),this.ListenerRecord.has(a)||this.ListenerRecord.set(a,new Map),this.ListenerRecord.get(a).set(c,b))}async RemovListener(a,c){if(this.ListenerRecord.has(a)&&this.ListenerRecord.get(a).has(c)){const b=this.ListenerRecord.get(a).get(c);a.removeEventListener(c,b);this.ListenerRecord.get(a).delete(c)}}async Listen(a,c,b,d={},e){try{a.addEventListener(c,b,d),e(!0)}catch{e(!1)}}async WaitElem(a,c,b,d){let e,f,g;const h=new MutationObserver(()=>{f=c?document.querySelectorAll(a):document.querySelector(a);if(g=c?0<f.length:f)h.disconnect(),clearTimeout(e),d(f)});h.observe(document.body,{childList:!0,subtree:!0});e=setTimeout(()=>{h.disconnect()},1E3*b)}async WaitMap(a,c,b){let d,e;const f=new MutationObserver(()=>{e=a.map(g=>document.querySelector(g));e.every(g=>g)&&(f.disconnect(),clearTimeout(d),b(e))});f.observe(document.body,{childList:!0,subtree:!0});d=setTimeout(()=>{f.disconnect()},1E3*c)}async log(a=null,c="print",b="log"){b="string"===typeof b&&this.Template[b]?b:b="log";if(null==a)this.Template[b](c);else console.groupCollapsed(a),this.Template[b](c),console.groupEnd()}store(a,c,b=null){switch(a[0]){case "g":return this.GM[a](c,b);case "s":return null!==b?this.GM[a](c,b):null;default:return Error("wrong type of operation")}}async Menu(a){for(const [c,b]of Object.entries(a))GM_registerMenuCommand(c,()=>{b()})}};