-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhook.js
31 lines (28 loc) · 1.44 KB
/
hook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const HOOK_MODULES = ['UFICentralUpdates', 'UFIFeedbackTargets'];
const UPDATE_FEEDBACK_EVENT = 'update-feedback';
const DEFAULT_SUPPORTED_REACTIONS_COUNT = 6;
const REACTION_TYPE_ID_THANKFUL = 11;
hookFacebookReactions();
// hooks into the React components that are responsible for Facebook Reactions
function hookFacebookReactions() {
if(window.requireLazy) {
window.requireLazy(HOOK_MODULES,
(UFICentralUpdates, UFIFeedbackTargets) => {
// listen for the event that updates the object used by Reactions
UFICentralUpdates.subscribe(UPDATE_FEEDBACK_EVENT, onUpdateFeedback);
// listen when a 'FeedbackTarget' is updated so we can modify its data
function onUpdateFeedback(eventName, feedbackObj) {
var supportedReactions = feedbackObj.feedbacktarget.supportedreactions;
// to prevent an infinite callback loop, only send an update if the Reactions haven't been modified yet
if(supportedReactions.length === DEFAULT_SUPPORTED_REACTIONS_COUNT) {
supportedReactions.push(REACTION_TYPE_ID_THANKFUL); // inject the Thankful Reaction
feedbackObj.feedbacktarget.supportedreactions = supportedReactions; // reassign the supportedreactions
UFICentralUpdates.inform(UPDATE_FEEDBACK_EVENT, feedbackObj); // update the 'FeedbackTarget' ???? PROFIT!!
}
}
}
);
} else {
console.log('Failed to inject Facebook Reactions hook.');
}
}