Skip to content

Instantly share code, notes, and snippets.

@HKGx
Last active July 31, 2018 19:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HKGx/9d3f38e751c692096f8a57c89d62919f to your computer and use it in GitHub Desktop.
Save HKGx/9d3f38e751c692096f8a57c89d62919f to your computer and use it in GitHub Desktop.
fixed some ids lul
// ==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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment