"use strict"; ((async()=>{ // This serves 2 purposes. The variables within won't be in global scope, and we can use await. const uri_handler = "i9fw8ys62vhb831n://"; // CHANGE THIS! The name of the uri handler is randomised, we use it like a password or access token. if(!document.baseURI.startsWith("file:")) throw new Error("This file is only meant to be used locally!"); class ACMD extends HTMLElement { #exec; #cwd; static observedAttributes = ["exec","cwd"]; constructor(){ super(); this.addEventListener("click", ()=>{ if(!this.#exec) return; if(!document.baseURI.startsWith("file:")) throw new Error("This file is only meant to be used locally!"); let cwd = this.#cwd ?? '.'; if(cwd && cwd.startsWith("~/")){ cwd = cwd.slice(2); }else{ cwd = new URL(cwd+"/.", document.baseURI).pathname; } const uri = uri_handler + encodeURIComponent(cwd) + ':' + encodeURIComponent(this.#exec); if(uri) open(uri, "_self", "noopener,noreferrer"); }); } attributeChangedCallback(name, oldValue, newValue){ switch(name){ case 'exec': this.#exec = newValue; break; case 'cwd' : this.#cwd = newValue; break; } } }; customElements.define("a-cmd", ACMD); const style = new CSSStyleSheet(); style.replace(` a-cmd[exec] { cursor: pointer; text-decoration: underline; color: blue; } `); document.adoptedStyleSheets.push(style); })());