forked from netlify/netlify-browser-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
59 lines (58 loc) · 1.29 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
51
52
53
54
55
56
57
58
59
var getLocation = function(href) {
var l = document.createElement('a');
l.href = href;
return l;
};
function onMessage(request, sender, sendResponse) {
// console.log('backgroundjs', {
// request,
// sender,
// sendResponse
// });
if (request.netlifyPage) {
var url = getLocation(sender.url);
var slug = url.hostname;
chrome.pageAction.show(sender.tab.id);
chrome.pageAction.setIcon({
path: 'logo16.png',
tabId: sender.tab.id
});
chrome.pageAction.setTitle({
title: 'Netlify Site!',
tabId: sender.tab.id
});
chrome.pageAction.setPopup({
tabId: sender.tab.id,
popup: 'popup.html'
});
sendResponse({
// goes to poup
hiFrom: 'backgroundjs',
slug
});
}
if (request.get_version) {
chrome.tabs.query(
{
active: true,
currentWindow: true
},
function(tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{
check: 'version'
},
function(response) {
return response;
}
);
}
);
}
}
chrome.extension.onMessage.addListener(onMessage);
//Checks if version in use is lower than the current version
function lowerVersion(in_use_version, current_version) {
return false;
}