FastComments.com

Add Comments With MemberSpace

使用 FastComments,我们可以在与 MemberSpace 结合时设置仅限会员的专属评论。

我们也可以在用户登录的同时(如果需要)允许匿名评论,并且甚至可以根据 用户的会员身份设置自定义徽章!

代码 Internal Link

我们可以通过一小段代码轻松地将FastComments与MemberSpace连接起来:

FastComments MemberSpace Snippet
Copy Copy
1
2<script src="https://cdn.fastcomments.com/js/embed-v2.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5 (function () {
6 const tenantId = 'demo';
7 const ALLOW_ANON = false;
8 const LOGIN_URL = 'https://example.com/login';
9 const PLAN_DISPLAY_LABELS = {
10 'VIP Plan': 'VIP'
11 };
12 let lastInstance;
13
14 function tick() {
15 if (!window.MemberSpace) {
16 return setTimeout(tick, 100);
17 }
18 if (!window.FastCommentsUI) {
19 return setTimeout(tick, 100);
20 }
21 const target = document.getElementById('fastcomments-widget');
22 if (!target) {
23 return setTimeout(tick, 100);
24 }
25 const data = MemberSpace.getMemberInfo();
26 if (data.isLoggedIn && data.memberInfo) {
27 lastInstance = FastCommentsUI(target, {
28 tenantId: tenantId,
29 urlId: window.location.pathname,
30 simpleSSO: {
31 displayLabel: getDisplayLabel(data.memberInfo),
32 username: data.memberInfo.name,
33 email: data.memberInfo.email,
34 avatar: data.memberInfo.profileImageUrl
35 }
36 });
37 } else if (lastInstance) {
38 lastInstance.destroy();
39 lastInstance = FastCommentsUI(target, {
40 tenantId: tenantId,
41 urlId: window.location.pathname,
42 simpleSSO: getAnonSSOConfig()
43 });
44 }
45 }
46
47 function getAnonSSOConfig() {
48 if (ALLOW_ANON) {
49 return undefined;
50 }
51 return {
52 loginURL: LOGIN_URL
53 };
54 }
55
56 function getDisplayLabel(memberInfo) {
57 if (!memberInfo.memberships) {
58 return;
59 }
60 for (const membership of memberInfo.memberships) {
61 const label = PLAN_DISPLAY_LABELS[membership.name];
62 if (label) {
63 return label
64 }
65 }
66 }
67
68 tick();
69 })();
70</script>
71

当用户通过MemberStack登录后访问您的网站或应用程序时,他们将自动登录到FastComments,并且他们的评论 将被标记为Verified

此外,在上面的示例中,如果您有一个名为VIP Plan的订阅计划,我们将在用户名旁边显示VIP徽章。您可以编辑示例以 添加更多计划。如有问题,请联系支持。

允许匿名评论

如果您还想允许匿名评论,请将ALLOW_ANON设置为true,如下所示:

const ALLOW_ANON = true;

另外请记得将https://example.com/login更改为您希望用户点击Login按钮时前往的位置:

这样,未登录会员网站的用户将可以选择输入他们的姓名和电子邮件来发表评论。

自定义 Internal Link

FastComments旨在根据您的网站进行定制。

如果您想添加自定义样式或调整配置,请查看我们的自定义文档了解如何操作。