Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
devesh95 committed Sep 19, 2015
0 parents commit 15849de
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# hack-the-north submission

Creates interactive and embedded content for Facebook messenger on the web.
21 changes: 21 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// when the extension is installed...
chrome.runtime.onInstalled.addListener(function() {

// replace all existing rules...
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {

// with these new rules:
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostSuffix: '.facebook.com', pathPrefix: 'messages/' }
})
],

actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});

4 changes: 4 additions & 0 deletions content_scripts/jquery.min.js

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions content_scripts/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
var generateForm = function(message) {
var form = '';
var queries = message.split('?');
for (var i = 1; i < queries.length; i++) {
var KVPair = queries[i];
var key = KVPair.split('=')[0];
var value = KVPair.split('=')[1];
if (key === 'input') {
form += '<span><form action="https://www.google.com"><input type="text" placeholder="Enter text here"><input type="submit" value="Submit"></form>';
} else {
form += '<span><p>' + key + ': ' + value + '</p></span>';
}
}
return form;
};

var renderForm = function() {
$('.webMessengerMessageGroup').each(function(index, messageGroup) {
$(messageGroup).find('p').each(function(index, element) {
var actualMessage = $(element).text();
renderElement(actualMessage, element);
});
});
};

var renderElement = function(actualMessage, element) {
if (actualMessage.indexOf('!!FBForm') > -1) {
var form = generateForm(actualMessage);
$(element).parent().parent().empty().append(form);
}
if (actualMessage.indexOf('/giphy') > -1) {
var search_term_string = actualMessage.substring(7).replace(/ /g, '+');
var searchURL = 'https://api.giphy.com/v1/gifs/search?q=' + search_term_string + '&api_key=dc6zaTOxFJmzC';
$.get(searchURL, function(data) {
if (!data.data[0]) {
$(element).parent().parent().empty().append('<span><h1>Sorry, we couldn\'t find a match on Giphy for that.</h1></span>').hide().fadeIn();
}
var embed_url = data.data[0].embed_url;
$(element).parent().parent().empty().append('<span><iframe src="' + embed_url + '"></iframe></span>').hide().fadeIn();
});
}
};

$(document).on('click', renderForm);
$(document).on('keyup', function(e) {
if (e.keyCode === 13) {
setTimeout(function() {
renderForm();
}, 200);
}
});
// $('.uiTextareaNoResize uiTextareaAutogrow _1rv').on('keyup', function(e) {
// if (e.keyCode === 13) {
// setTimeout(function() {
// renderForm();
// }, 200);
// }
// });

// window.onload = window.onpageshow = function () {
// console.log('Running script on a Facebook messages page.');
// loadBox();
// };
27 changes: 27 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"manifest_version": 2,
"name": "Hack The North submission",
"description": "Supercharges facebook messenger",
"version": "1.0",
"background": {
"scripts": [ "background.js" ],
"persistent": false
},
"permissions": [
"declarativeContent",
"activeTab"
],
"content_scripts": [
{
"matches": [
"http://www.facebook.com/messages/*",
"https://www.facebook.com/messages/*"
],
"css": [],
"js": [
"content_scripts/jquery.min.js",
"content_scripts/main.js"
]
}
]
}

0 comments on commit 15849de

Please sign in to comment.