FastComments.com

ืคื™ืชื•ื— ื”ืจื—ื‘ื•ืช

ื”ืงืฉืจ

FastComments ืžืกืคืงืช ืืช ื”ื™ื›ื•ืœืช ืœื”ืจื—ื™ื‘ ืืช ื”ืคื•ื ืงืฆื™ื•ื ืœื™ื•ืช ื”ืœื™ื‘ื” ืฉืœื ื• ื‘ืืžืฆืขื•ืช ืกืงืจื™ืคื˜ื™ื ืฉืื ื• ืงื•ืจืื™ื ืœื”ื ื”ืจื—ื‘ื•ืช.

ื”-Extension ื™ื›ื•ืœ ืœื”ื•ืกื™ืฃ ืกื™ืžื•ืŸ ื ื•ืกืฃ ืœื•ื•ื™ื“ื’'ื˜ ื”ืชื’ื•ื‘ื•ืช, ืœื”ื•ืกื™ืฃ ืžืื–ื™ื ื™ ืื™ืจื•ืขื™ื, ื•ืœื”ืจื™ืฅ ืงื•ื“ ื›ืœืฉื”ื•.

ื›ืืŸ ืชืžืฆืื• ื“ื•ื’ืžืื•ืช ืœื”ืจื—ื‘ื•ืช ืฉืœื ื• ื‘ืกื‘ื™ื‘ืช ื”ื™ื™ืฆื•ืจ, ื•ื›ืŸ ืชื™ืขื•ื“ ื›ื™ืฆื“ ืœื›ืชื•ื‘ ื”ืจื—ื‘ื•ืช.


ืžื—ื–ื•ืจ ื—ื™ื™ ื”ื”ืจื—ื‘ื” Internal Link


ื”ืกืงืจื™ืคื˜ ืฉืœ ื›ืœ ืชื•ืกืฃ ื ื˜ืขืŸ ื•ืžื•ืคืขืœ ืœืคื ื™ ืฉื”ื•ื•ื™ื“ื’'ื˜ ืฉืœ ื”ืชื’ื•ื‘ื•ืช ืžืชื—ื™ืœ ืœื”ื‘ื™ื ืืช ืงื‘ื•ืฆืช ื”ืชื’ื•ื‘ื•ืช ื”ืจืืฉื•ื ื” ื•ืœื”ืฆื™ื’ ืืช ืžืžืฉืง ื”ืžืฉืชืžืฉ.

ื‘ืขืช ื˜ืขื™ื ื” ืจืืฉื•ื ื™ืช, ื”ื ืชื•ื ื™ื ื”ื‘ืื™ื ื™ืชื•ื•ืกืคื• ืœืื•ื‘ื™ื™ืงื˜ ื”ืชื•ืกืฃ:

  • config - ื”ืคื ื™ื” ืœืื•ื‘ื™ื™ืงื˜ config.
  • translations - ื”ืคื ื™ื” ืœืื•ื‘ื™ื™ืงื˜ translations.
  • commentsById - ื”ืคื ื™ื” ืœื›ืœ ื”ืชื’ื•ื‘ื•ืช ืœืคื™ id.
  • root - ื”ืคื ื™ื” ืœืฆื•ืžืช ื”-DOM ื”ืฉื•ืจืฉื™ืช.

ืชื•ืกืคื™ื ืฆืจื™ื›ื™ื ืœื“ืจื•ืก ืืช ื”ืคื•ื ืงืฆื™ื•ืช ื”ืจืฆื•ื™ื•ืช, ืฉื”ื•ื•ื™ื“ื’'ื˜ ืฉืœ ื”ืชื’ื•ื‘ื•ืช ื™ืคืขื™ืœ ื‘ื–ืžื ื™ื ื”ืžืชืื™ืžื™ื.


ื”ื’ื“ืจืช ื”ืจื—ื‘ื” Internal Link


ื”ื”ืจื—ื‘ื” ื”ืงื˜ื ื” ื‘ื™ื•ืชืจ ื”ืืคืฉืจื™ืช ืชื”ื™ื”:

ืชื•ืกืฃ ืคืฉื•ื˜
Copy CopyRun External Link
1
2(function () {
3 const extension = FastCommentsUI.extensions.find((extension) => {
4 return extension.id === 'my-extension';
5 });
6})();
7

ืœืฆื•ืจืš ื”ื“ื•ื’ืžื”, ืฉืžื•ืจ ืงื•ื‘ืฅ ื–ื” ื›-my-extension.js, ื•ื”ืคื•ืš ืื•ืชื• ืœื–ืžื™ืŸ ื‘-https://example.com/my-extension.min.js.

ืชื•ืกืฃ ื–ื” ืื™ื ื• ืขื•ืฉื” ื“ื‘ืจ; ื‘ืขืช ื˜ืขื™ื ื” ื‘ืœื‘ื“ ื”ื•ื ืžืื—ื–ืจ ืืช ืื•ื‘ื™ื™ืงื˜ ื”-Extension ืฉื ื•ืฆืจ ืขืœ ื™ื“ื™ ืกืคืจื™ื™ืช ื”ื”ืขืจื•ืช ื”ืžืจื›ื–ื™ืช.

ืื•ื‘ื™ื™ืงื˜ ื”-Extension ื”ื•ื ืกื™ื ื’ืœื˜ื•ืŸ ื•ืื™ื ื• ืžืฉื•ืชืฃ ืขื ืชื•ืกืคื™ื ืื—ืจื™ื.

ื‘ื”ืžืฉืš, ื›ื“ื™ ืœื˜ืขื•ืŸ ืืช ื”ืชื•ืกืฃ ืฉืœื ื•, ืขืœื™ื ื• ืœื”ื•ื“ื™ืข ืขืœ ื›ืš ืœื•ื•ื™ื“ื’'ื˜ ื”ื”ืขืจื•ืช. ืœื“ื•ื’ืžื”:

Using a Custom Extension
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "extensions": [
8 {
9 "id": "my-extension",
10 "path": "https://example.com/my-extension.min.js"
11 }
12 ]
13}];
14</script>
15

ืœื“ื•ื’ืžื•ืช ืคื•ื ืงืฆื™ื•ื ืœื™ื•ืช, ืจืื” ืืช ื”ืกืขื™ืฃ ื”ื‘ื.


ืื•ื‘ื™ื™ืงื˜ ื”ื”ืจื—ื‘ื” Internal Link

ืื•ื‘ื™ื™ืงื˜ ื”ืชื•ืกืฃ ืžื•ืจื›ื‘ ืžื”ื”ื’ื“ืจื” ื”ื‘ืื”:

JSDoc ืฉืœ ืื•ื‘ื™ื™ืงื˜ ื”ืชื•ืกืฃ
Copy CopyRun External Link
1
2/**
3 * The FastCommentsUI extension object. Used for lazy-loading certain components. For example, the review system is not
4 * used by all customers, so we only load that extension when we want it.
5 *
6 * @typedef {Object} FastCommentsUIExtension
7 * @property {string} id
8 * @property {Element} scriptNode
9 * @property {Element} root - ืฆื•ืžืช ื”-DOM ื”ืฉื•ืจืฉ ืฉืœ ื”ื•ื•ื™ื“ื’'ื˜.
10 * @property {string} [css]
11 * @property {Object} config - ืื•ื‘ื™ื™ืงื˜ ื”ืชืฆื•ืจื” ืฉืœ FastComments.
12 * @property {Object} commentsById - ืžืฆื‘ื™ืข ืœืื•ื‘ื™ื™ืงื˜ ืฉืžื›ื™ืœ ืืช ื›ืœ ื”ืชื’ื•ื‘ื•ืช ืœืคื™ id, ืฉืžืชืขื“ื›ืŸ ื‘ืื•ืคืŸ ืฉื•ื˜ืฃ.
13 * @property {Object} translations - ื”ืคื ื™ื” ืœื›ืœ ื”ืชืจื’ื•ืžื™ื.
14 * @property {Function} reRenderComment - ื”ืคื ื™ื” ืœืคื•ื ืงืฆื™ื” ืฉื ื™ืชืŸ ืœืงืจื•ื ืœื” ื›ื“ื™ ืœืจื ื“ืจ ืžื—ื“ืฉ ืชื’ื•ื‘ื”.
15 * @property {Function} removeCommentAndReRender - ื”ืคื ื™ื” ืœืคื•ื ืงืฆื™ื” ืฉื ื™ืชืŸ ืœืงืจื•ื ืœื” ื›ื“ื™ ืœื”ืกื™ืจ ืชื’ื•ื‘ื” ืžื”ื–ื™ื›ืจื•ืŸ ื•ืœืจื ื“ืจ ืžื—ื“ืฉ ืืช ื”ื—ืœืง ื”ืžืชืื™ื ื‘-DOM.
16 * @property {Function} newBroadcastId - ื”ืคื ื™ื” ืœืคื•ื ืงืฆื™ื” ืฉื ื™ืชืŸ ืœืงืจื•ื ืœื” ื›ื“ื™ ืœื™ืฆื•ืจ ืžื–ื”ื” ืฉื™ื“ื•ืจ ื—ื“ืฉ ื•ืœื”ื•ืกื™ืฃ ืื•ืชื• ืœืจืฉื™ืžื” ืžืงื•ืžื™ืช ืฉืœ ืžื–ื”ื™ ืฉื™ื“ื•ืจ ืฉื™ืฉ ืœื”ืชืขืœื ืžื”ื.
17 * @property {FastCommentsUIExtensionSetupEventHandlers} [setupEventHandlers]
18 * @property {FastCommentsUIExtensionPrepareCommentForSavingCallback} [prepareCommentForSaving]
19 * @property {FastCommentsUIExtensionNewCommentCallback} [newComment]
20 * @property {FastCommentsUIExtensionReplyAreaFilter} [replyAreaFilter] - ืžืกื ืŸ HTML ืœืื–ื•ืจ ื”ืชื’ื•ื‘ื•ืช.
21 * @property {FastCommentsUIExtensionWidgetFilter} [widgetFilter] - ืžืกื ืŸ HTML ืœื›ืœ ื”ื•ื•ื™ื“ื’'ื˜ ื‘ืขืช ืจื™ื ื“ื•ืจ.
22 * @property {FastCommentsUIExtensionCommentTopFilter} [commentFilter] - ืžืกื ืŸ HTML ืœื›ืœ ืชื’ื•ื‘ื” ืœืคื ื™ ืจื™ื ื“ื•ืจ.
23 * @property {FastCommentsUIExtensionReplyAreaFilter} [commentMenuFilter] - ืžืกื ืŸ HTML ืœืชืคืจื™ื˜ ืฉืœ ื›ืœ ืชื’ื•ื‘ื” ืœืคื ื™ ืจื™ื ื“ื•ืจ.
24 * @property {FastCommentsUIExtensionMenuFilter} [menuFilter] - ืžืกื ืŸ HTML ืœื›ืœ ื”ื•ื•ื™ื“ื’'ื˜ ื‘ืขืช ืจื™ื ื“ื•ืจ.
25 * @property {FastCommentsUIExtensionReplyAreaTop} [replyAreaTop] - (LEGACY) ืžื—ื–ื™ืจ HTML ืœื”ื•ืกืคื” ืœืจืืฉ ืื–ื•ืจ ื”ืชื’ื•ื‘ื”.
26 * @property {FastCommentsUIExtensionWidgetTopCallback} [widgetTop] - (LEGACY) ืžื—ื–ื™ืจ HTML ืœื”ื•ืกืคื” ืœืจืืฉ ื”ื•ื•ื™ื“ื’'ื˜.
27 * @property {FastCommentsUIExtensionCommentTopCallback} [commentTop] - (LEGACY) ืžื—ื–ื™ืจ HTML ืœื”ื•ืกืคื” ืœืจืืฉ ืืœืžื ื˜ ื”ืชื’ื•ื‘ื”.
28 * @property {FastCommentsUIExtensionCommentBottomCallback} [commentBottom] - (LEGACY) ืžื—ื–ื™ืจ HTML ืœื”ื•ืกืคื” ืœืชื—ืชื™ืช ืืœืžื ื˜ ื”ืชื’ื•ื‘ื”.
29 * @property {FastCommentsUIExtensionMenuBottomCallback} [menuBottom] - (LEGACY) ืžื—ื–ื™ืจ HTML ืœื”ื•ืกืคื” ืœืชื—ืชื™ืช ืืœืžื ื˜ ื”ืชืคืจื™ื˜ ืœื›ืœ ืชื’ื•ื‘ื”.
30 * @property {FastCommentsUIExtensionRenderCallback} [onRender]
31 * @property {FastCommentsUIExtensionConnectionStatusCallback} [onLiveConnectionStatusUpdate]
32 * @property {FastCommentsUIExtensionInitialRenderCallback} [onInitialRenderComplete]
33 * @property {FastCommentsUIExtensionPresenceUpdateCallback} [onPresenceUpdate]
34 */
35
36/**
37 * @callback FastCommentsUIExtensionSetupEventHandlers
38 * @param {Element} element - ื”ืืœืžื ื˜ ื”ืฉื•ืจืฉ.
39 * @param {Object.<string, Function>} clickListeners - ืžื˜ืคืœื™ ืื™ืจื•ืขื™ื ืœืœื—ื™ืฆื•ืช, ืœืคื™ ืฉื ืžื—ืœืงื”, ืฉื ื™ืชืŸ ืœืฉื ื•ืช ืขืœ-ื™ื“ื™ ื”ืคื ื™ื”.
40 * @returns void
41 */
42
43/**
44 * @callback FastCommentsUIExtensionWidgetTopCallback
45 * @param {Object} moduleData
46 * @returns {string}
47 */
48
49/**
50 * @callback FastCommentsUIExtensionWidgetFilter
51 * @param {Object} moduleData
52 * @param {Object} html
53 * @returns {string}
54 */
55
56/**
57 * @callback FastCommentsUIExtensionCommentTopCallback
58 * @param {Object} comment
59 * @returns {string}
60 */
61
62/**
63 * @callback FastCommentsUIExtensionCommentTopFilter
64 * @param {Object} comment
65 * @param {string} html
66 * @returns {string}
67 */
68
69/**
70 * @callback FastCommentsUIExtensionCommentBottomCallback
71 * @param {Object} comment
72 * @returns {string}
73 */
74
75/**
76 * @callback FastCommentsUIExtensionMenuBottomCallback
77 * @param {Object} comment
78 * @returns {string}
79 */
80
81/**
82 * @callback FastCommentsUIExtensionMenuFilter
83 * @param {Object} comment
84 * @param {string} html
85 * @returns {string}
86 */
87
88/**
89 * @callback FastCommentsUIExtensionRenderCallback
90 * @returns {string}
91 */
92
93/**
94 * @callback FastCommentsUIExtensionConnectionStatusCallback
95 * @param {boolean} isConnected
96 * @returns {void}
97 */
98
99/**
100 * @callback FastCommentsUIExtensionInitialRenderCallback
101 * @returns {void}
102 */
103
104/**
105 * @callback FastCommentsUIExtensionReplyAreaTop
106 * @param {Object|null} currentUser
107 * @param {boolean} isSaving
108 * @param {boolean} isReplyOpen
109 * @param {string|null} parentId
110 * @returns {string}
111 */
112
113/**
114 * @callback FastCommentsUIExtensionReplyAreaFilter
115 * @param {Object|null} currentUser
116 * @param {boolean} isSaving
117 * @param {boolean} isReplyOpen
118 * @param {string|null} parentId
119 * @param {string|null} html
120 * @returns {string}
121 */
122
123/**
124 * @callback FastCommentsUIExtensionPrepareCommentForSavingCallback
125 * @param {Object} comment
126 * @param {string} parentId
127 */
128
129/**
130 * @callback FastCommentsUIExtensionNewCommentCallback
131 * @param {Object} comment
132 */
133
134/**
135 * @callback FastCommentsUIExtensionPresenceUpdateCallback
136 * @param {Object} update
137 */
138

ืžืžืฉืง API ืฉืœ ื”ื”ืจื—ื‘ื” Internal Link

ื”ืื™ื ื˜ืจืืงืฆื™ื” ืขื ื”-Extension ืคืฉื•ื˜ื”, ืžืื—ืจ ืฉืื ื• ืžื’ื“ื™ืจื™ื ื”ืคื ื™ื•ืช ืœืคื•ื ืงืฆื™ื•ืช ืฉืื ื—ื ื• ืจื•ืฆื™ื ืฉื™ื•ืคืขืœื•.

ื›ื“ื™ ืœื”ืžืฉื™ืš ืžื”ื“ื•ื’ืžื” ื”ืงื•ื“ืžืช, ื ื ื™ื— ืฉืื ื• ืจื•ืฆื™ื ืœื”ื•ืกื™ืฃ HTML ืœืจืืฉ ื›ืœ ืชื’ื•ื‘ื”:

ืชื•ืกืฃ ืคืฉื•ื˜ - ื”ืžืฉืš
Copy CopyRun External Link
1
2(function () {
3 const extension = FastCommentsUI.extensions.find((extension) => {
4 return extension.id === 'my-extension';
5 });
6
7 extension.commentFilter = function(comment, html) {
8 return `<h3>The user's name is ${comment.commenterName}!</h3>` + html;
9 }
10})();
11

ื›ืืฉืจ ืชื—ื–ื™ืจ HTML ื›ื–ื”, ื”ื•ื ื™ืชืžื–ื’ ื‘ืžืžืฉืง ื”ืžืฉืชืžืฉ ื‘ืืžืฆืขื•ืช ืืœื’ื•ืจื™ืชื dom-diffing.

ื”ืคืขืœืช ื”ืฆื’ื” ืžื—ื“ืฉ ืฉืœ ืชื’ื•ื‘ื” ื‘ืื•ืคืŸ ื™ื“ื ื™

ืืคืฉืจ ืœื”ืžืชื™ืŸ ืœื˜ืขื™ื ืช ื”ื“ืฃ ื”ื”ืชื—ืœืชื™ืช ื•ืœื”ืฆื™ื’ ืชื’ื•ื‘ื” ืžื—ื“ืฉ ื‘ืื•ืคืŸ ื™ื“ื ื™ ืขืœ-ื™ื“ื™ ืงืจื™ืื” ืœ-reRenderComment:

ื”ืฆื’ื” ืžื—ื“ืฉ ืฉืœ ืชื’ื•ื‘ื”
Copy CopyRun External Link
1
2(function () {
3 const extension = FastCommentsUI.extensions.find((extension) => {
4 return extension.id === 'my-extension';
5 });
6
7 let renderCount = 0;
8
9 extension.commentFilter = function(comment, html) {
10 renderCount++;
11 return `<h3>The render count is ${renderCount}!</h3>` + html;
12 }
13
14 extension.onInitialRenderComplete = function() {
15 setInterval(function() {
16 extension.reRenderComment(extension.commentsById[Object.keys(extension.commentsById)[0]], function renderDone() {
17 console.log('Comment re-render done.');
18 });
19 }, 2000); // ืื™ืŸ ืฆื•ืจืš ื‘-timeout, ื–ื• ืจืง ื“ื•ื’ืžื”.
20 }
21})();
22