|
// ==UserScript== |
|
// @name Facebook Hidden Reactions |
|
// @description Adds new hidden reactions |
|
// @match *://*.facebook.com/* |
|
// @version 1.1 |
|
// @grant none |
|
// @run-at document-body |
|
// ==/UserScript== |
|
// |
|
// Original code: https://p0358.net/facebook_reactions.user.js |
|
let hookFacebookReactionsCounter = 0; |
|
function hookFacebookReactions() { |
|
const modulesToHook = ['UFICentralUpdates', 'UFIFeedbackTargets']; |
|
const updateFeedbackEvent = 'update-feedback'; |
|
const defaultReactionsCount = 6; |
|
const newReactions = [{name: "fire", id: 14 } , |
|
{name: "plane", id: 15}]; |
|
if(window.requireLazy) { |
|
window.requireLazy(modulesToHook, |
|
(UFICentralUpdates, UFIFeedbackTargets) => { |
|
// listen for the event that updates the object used by Reactions |
|
UFICentralUpdates.subscribe(updateFeedbackEvent, 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 === defaultReactionsCount) { |
|
for(let reaction of newReactions.reverse()){ |
|
supportedReactions.push(reaction.id); |
|
} |
|
feedbackObj.feedbacktarget.supportedreactions = supportedReactions; // reassign the supportedreactions |
|
UFICentralUpdates.inform(updateFeedbackEvent, feedbackObj); // update the 'FeedbackTarget' ???? PROFIT!! |
|
} |
|
} |
|
} |
|
); |
|
let cssText = ``; |
|
for(let reaction of newReactions){ |
|
// make up css style |
|
cssText += `div[data-reaction='${reaction.id}'] div._4sm1:after { content: ' ${reaction.name}'; }`; |
|
} |
|
//hook style |
|
let hookScript = document.createElement("style"); |
|
hookScript.type = "text/css"; |
|
hookScript.textContent = cssText; |
|
(document.head || document.body || document.documentElement).appendChild(hookScript); |
|
} else { |
|
console.log('Failed to inject Facebook Reactions hook.'); |
|
hookFacebookReactionsCounter++; |
|
if (hookFacebookReactionsCounter < 30) setTimeout(hookFacebookReactions, 50); |
|
} |
|
}; |
|
|
|
hookFacebookReactions(); |