Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ <h3>Social Media</h3>
</div>
<div class="demo-item">
<h3>Messaging</h3>
<p>WhatsApp, Telegram</p>
<p>WhatsApp, Telegram, Discord</p>
<div id="demo-messaging"></div>
</div>
</div>
Expand Down Expand Up @@ -591,7 +591,7 @@ <h2 style="color: #fff; margin-bottom: 20px">Ready to Get Started?</h2>
container: "#demo-messaging",
url: demoUrl,
title: demoTitle,
platforms: ["whatsapp", "telegram"],
platforms: ["whatsapp", "telegram" , "discord"],
buttonText: "Share",
});

Expand Down
45 changes: 44 additions & 1 deletion src/social-share-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ class SocialShareButton {
color: "#E60023",
icon: '<path d="M12 0C5.372 0 0 5.373 0 12c0 4.99 3.052 9.267 7.386 11.059-.102-.94-.194-2.385.04-3.413.211-.904 1.356-5.752 1.356-5.752s-.346-.693-.346-1.717c0-1.608.932-2.808 2.093-2.808.987 0 1.463.741 1.463 1.63 0 .993-.632 2.476-.958 3.853-.273 1.155.58 2.098 1.718 2.098 2.062 0 3.646-2.174 3.646-5.31 0-2.778-1.997-4.722-4.847-4.722-3.304 0-5.242 2.478-5.242 5.039 0 .997.384 2.066.865 2.647.095.115.109.215.08.331-.088.365-.282 1.155-.321 1.316-.05.212-.165.257-.381.155-1.418-.66-2.305-2.733-2.305-4.397 0-3.579 2.601-6.867 7.497-6.867 3.936 0 6.998 2.805 6.998 6.557 0 3.91-2.466 7.058-5.892 7.058-1.15 0-2.232-.597-2.6-1.302l-.707 2.692c-.255.983-.946 2.215-1.408 2.966A12.002 12.002 0 0024 12C24 5.373 18.627 0 12 0z"/>',
},
discord: {
name: "Discord",
color: "#5865F2",
icon: '<path d="M20.317 4.37a19.791 19.791 0 0 0-4.885-1.515.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 0 0-5.487 0 12.64 12.64 0 0 0-.617-1.25.077.077 0 0 0-.079-.037A19.736 19.736 0 0 0 3.677 4.37a.07.07 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 0 0 .031.057 19.9 19.9 0 0 0 5.993 3.03.078.078 0 0 0 .084-.028 14.09 14.09 0 0 0 1.226-1.994.076.076 0 0 0-.041-.106 13.107 13.107 0 0 1-1.872-.892.077.077 0 0 1-.008-.128 10.2 10.2 0 0 0 .372-.292.074.074 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.01c.12.098.246.198.373.292a.077.077 0 0 1-.006.127 12.299 12.299 0 0 1-1.873.892.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 0 0 .084.028 19.839 19.839 0 0 0 6.002-3.03.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 0 0-.031-.03z"/>',
},
};

return this.options.platforms
Expand Down Expand Up @@ -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] || "";
}
Expand Down Expand Up @@ -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;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

const shareUrl = this.getShareURL(platform);

if (shareUrl) {
Expand All @@ -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");
Expand Down
Loading