diff --git a/index.html b/index.html index 6e58f73..534d146 100644 --- a/index.html +++ b/index.html @@ -390,7 +390,7 @@

Social Media

Messaging

-

WhatsApp, Telegram

+

WhatsApp, Telegram, Discord

@@ -591,7 +591,7 @@

Ready to Get Started?

container: "#demo-messaging", url: demoUrl, title: demoTitle, - platforms: ["whatsapp", "telegram"], + platforms: ["whatsapp", "telegram" , "discord"], buttonText: "Share", }); diff --git a/src/social-share-button.js b/src/social-share-button.js index 3905128..4d4c595 100644 --- a/src/social-share-button.js +++ b/src/social-share-button.js @@ -172,6 +172,11 @@ class SocialShareButton { color: "#E60023", icon: '', }, + discord: { + name: "Discord", + color: "#5865F2", + icon: '', + }, }; return this.options.platforms @@ -244,7 +249,9 @@ class SocialShareButton { reddit: `https://reddit.com/submit?url=${encodedUrl}&title=${encodedReddit}`, email: `mailto:?subject=${encodedTitle}&body=${encodedEmail}%20${encodedUrl}`, pinterest: `https://pinterest.com/pin/create/button/?url=${encodedUrl}&description=${encodedPinterest}`, + discord: "https://discord.com/channels/@me" }; + return urls[platform] || ""; } @@ -404,6 +411,43 @@ class SocialShareButton { } share(platform) { + if (platform === "discord") { + // Discord has no public web share API unlike other platforms. + // We open Discord DMs and copy the URL to clipboard so the + // user can paste it directly into any channel or DM. + this._emit("social_share_click", "share", { platform }); + navigator.clipboard.writeText(this.options.url).then(() => { + if (this.isDestroyed) return; + const copyBtn = this.modal.querySelector(".social-share-copy-btn"); + if (copyBtn) { + copyBtn.textContent = "Copied!"; + copyBtn.classList.add("copied"); + if (this.feedbackTimeout) clearTimeout(this.feedbackTimeout); + this.feedbackTimeout = setTimeout(() => { + if (this.isDestroyed || !copyBtn) return; + copyBtn.textContent = "Copy"; + copyBtn.classList.remove("copied"); + this.feedbackTimeout = null; + }, 2000); + } + this._emit("social_share_success", "share", { platform }); + if (this.options.onShare) this.options.onShare(platform, this.options.url); + }).catch(() => { + // Fallback if clipboard API is denied or unavailable + if (this.isDestroyed) return; + this._emit("social_share_error", "error", { + platform, + errorMessage: "Clipboard access denied for Discord share", + }); + }); + window.open( + "https://discord.com/channels/@me", + "_blank", + "noopener,noreferrer,width=600,height=600" + ); + return; + } + const shareUrl = this.getShareURL(platform); if (shareUrl) { @@ -427,7 +471,6 @@ class SocialShareButton { }); } } - copyLink() { const input = this.modal.querySelector(".social-share-link-input input"); const copyBtn = this.modal.querySelector(".social-share-copy-btn");