-
Notifications
You must be signed in to change notification settings - Fork 10
/
background.js
66 lines (61 loc) · 1.61 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
os = {};
browser = {};
popup = {};
chrome.runtime.onStartup.addListener(function() {
theme();
});
chrome.runtime.onInstalled.addListener(function(details) {
if (details.reason == 'install' || details.reason == 'update') {
theme();
userAgent();
}
});
chrome.runtime.onMessage.addListener(function(message) {
if (message === 'extensions pls') {
chrome.storage.sync.get({'browser': ''}, function(getIt) {
var browser = getIt.browser;
if (browser === 'viv') {
chrome.tabs.create({url: 'vivaldi://extensions/'});
}
else if (browser === 'opr') {
chrome.tabs.create({url: 'opera://extensions/'});
}
else {
chrome.tabs.create({url: 'chrome://extensions/'});
}
});
}
});
function userAgent() {
console.log('SETUP');
const agent = navigator.userAgent;
if (agent.includes('Windows') === true) {
os = 'win';
}
else {
os = 'other';
}
if (agent.includes('Vivaldi') === true) {
browser = 'viv';
}
else if (agent.includes('OPR') === true) {
browser = 'opr';
}
else {
browser = 'chr';
}
chrome.storage.sync.set({
'os': os,
'browser': browser,
}, function() {
console.log(agent);
console.log(os + ' ' + browser);
chrome.runtime.openOptionsPage();
});
};
function theme() {
chrome.storage.sync.get({'popup': 'theme_dark.html'}, function(start) {
popup = start.popup;
chrome.browserAction.setPopup({popup});
});
};