Files
fundor333.com/static/js/share-button.js
Fundor333 b7c5abdcd5 Add share
2025-08-22 23:35:06 +02:00

34 lines
679 B
JavaScript

class ShareButton extends HTMLElement {
static register(tagName) {
if ("customElements" in window && window.navigator.share) {
customElements.define(
tagName || "share-button",
ShareButton
);
}
}
connectedCallback() {
this.button.addEventListener("click", this.share);
}
get button() {
return this.querySelector("button");
}
share = () => {
console.log("Clicked");
const root = this.getRootNode();
window.navigator
.share({
title: root.title,
text: root.title,
url: window.location.href,
})
.then(() => console.log("Page was succesffuly shared"))
.catch((error) => console.log(error));
};
}
ShareButton.register();