Add share

This commit is contained in:
Fundor333
2025-08-22 23:35:06 +02:00
parent d7bfe0cc23
commit b7c5abdcd5
7 changed files with 75 additions and 26 deletions

View File

@@ -1,29 +1,33 @@
class ShareButton extends HTMLElement {
static register(tagName) {
if ("customElements" in window && window.navigator.share) {
customElements.define(tagName || "share-button", ShareButton);
}
}
static register(tagName) {
if ("customElements" in window && window.navigator.share) {
customElements.define(
tagName || "share-button",
ShareButton
);
}
}
connectedCallback() {
this.button.addEventListener("click", this.share);
}
connectedCallback() {
this.button.addEventListener("click", this.share);
}
get button() {
return this.querySelector("button");
}
get button() {
return this.querySelector("button");
}
share = () => {
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));
};
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();

2
static/js/share-button.min.js vendored Normal file
View File

@@ -0,0 +1,2 @@
// @ts-nocheck
class ShareButton extends HTMLElement{static register(t){"customElements"in window&&window.navigator.share&&customElements.define(t||"share-button",ShareButton)}connectedCallback(){this.button.addEventListener("click",this.share)}get button(){return this.querySelector("button")}share=()=>{console.log("Clicked");const t=this.getRootNode();window.navigator.share({title:t.title,text:t.title,url:window.location.href}).then((()=>console.log("Page was succesffuly shared"))).catch((t=>console.log(t)))}}ShareButton.register();