Skip to content

Instantly share code, notes, and snippets.

@VehpuS
Created November 28, 2017 02:11
Show Gist options
  • Save VehpuS/916bdb9cc5ce287cf29c8708d79380a6 to your computer and use it in GitHub Desktop.
Save VehpuS/916bdb9cc5ce287cf29c8708d79380a6 to your computer and use it in GitHub Desktop.
A function that allows a chrome extension to create a Facebook send message window with a pre-filled message, logging that message to the extension's console.
const sendMessage = (recipientID, link, message) => {
const url = ("http://www.facebook.com/dialog/send?" +
"app_id=" + appId +
"&link=" + encodeURI(link) +
"&to=" + recipientID +
"&display=popup" +
"&redirect_uri=" + encodeURI(link));
chrome.tabs.create({ url }, (tab) => {
const msg_val = 'document.querySelector("#feedform_user_message").value';
chrome.tabs.executeScript(tab.id, {
code: (msg_val + ' = decodeURI("' + encodeURI(message) + '");' + msg_val),
runAt: 'document_end'
}, (results) => console.log("From " + msg_val, results));
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment