-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
50 lines (45 loc) · 1.51 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// background.js
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'loading') {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "tab-update"});
});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "url-message" ) {
var url = request.url;
var check = "https://www.youtube.com/watch?v=";
var pos = url.indexOf(check);
if(pos == 0) {
chrome.browserAction.setIcon({
path: "iconGreen.png"});
}
else {
chrome.browserAction.setIcon({
path: "icon.png"});
}
}});
}
});
// 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"});
});
});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "download-url" ) {
var apiCall = "http://www.youtubeinmp3.com/fetch/?format=JSON&video="
var complete = apiCall + request.url;
//alert(complete);
$.getJSON(complete, function(json) {
//alert(json.link);
chrome.tabs.create({"url": json.link});
});
}
}
);