-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 15849de
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() ] | ||
} | ||
]); | ||
}); | ||
}); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
] | ||
} |