This repository has been archived by the owner on Sep 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbackground.js
74 lines (71 loc) · 1.79 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var urlHost, requestHeader
var getLocation = function(href) {
var l = document.createElement("a")
l.href = href
return l
}
let webExtensionAPI
try {
webExtensionAPI = browser //ffox
} catch {
webExtensionAPI = chrome
}
function onMessage(request, sender, sendResponse) {
console.log("onMessage", { request })
if (request.netlifyPage && request.netlifyPage["x-nf-request-id"] && sender.tab) {
var url = getLocation(sender.url)
var slug = url.hostname
webExtensionAPI.pageAction.show(sender.tab.id)
webExtensionAPI.pageAction.setIcon({
path: "logo16.png",
tabId: sender.tab.id
})
webExtensionAPI.pageAction.setTitle({
title: "It's a Netlify Site!",
tabId: sender.tab.id
})
webExtensionAPI.pageAction.setPopup({
tabId: sender.tab.id,
popup: "popup.html"
})
requestHeader = request.netlifyPage
sendResponse({
// goes to popup.js
hiFrom: "backgroundjs",
slug
})
} else {
// chrome.pageAction.hide(sender.tab.id);
}
if (request.method === "setHost") {
console.log("setHost", { request })
urlHost = request.url
} else if (request.method === "getHost") {
console.log("getHost", { urlHost })
sendResponse({ urlHost, requestHeader })
}
if (request.get_version) {
webExtensionAPI.tabs.query(
{
active: true,
currentWindow: true
},
function(tabs) {
webExtensionAPI.tabs.sendMessage(
tabs[0].id,
{
check: "version"
},
function(response) {
return response
}
)
}
)
}
}
webExtensionAPI.runtime.onMessage.addListener(onMessage)
//Checks if version in use is lower than the current version
function lowerVersion(in_use_version, current_version) {
return false
}