Skip to content

Commit

Permalink
Set up extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Josephine-Chen committed Feb 18, 2017
1 parent 53067fa commit 98e6f43
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
17 changes: 17 additions & 0 deletions extension/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
// Send a message to the active tab
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "clicked_browser_action"});
});
});

// This block is new!
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "open_new_tab" ) {
chrome.tabs.create({"url": request.url});
}
}
);
12 changes: 12 additions & 0 deletions extension/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "clicked_browser_action" ) {
var firstHref = $("a[href^='http']").eq(0).attr("href");

//This is site url
console.log(firstHref);
var focusProURL = 'https://focuspro.herokuapp.com/';
chrome.runtime.sendMessage({"message": "open_new_tab", "url": focusProURL});
}
}
);
Binary file added extension/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions extension/jquery-3.1.1.min.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//Tutorial: https://robots.thoughtbot.com/how-to-make-a-chrome-extension
{
"manifest_version": 2,
"name": "FocusPro Extension",
"version": "0.1",
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["jquery-3.1.1.min.js", "content.js"]
}
],
"browser_action": {
"default_icon": "icon.png"
}
}

0 comments on commit 98e6f43

Please sign in to comment.