forked from alexis-jaksone/new-tab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
58 lines (54 loc) · 1.47 KB
/
background.js
File metadata and controls
58 lines (54 loc) · 1.47 KB
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
'use strict';
// Runtime
chrome.runtime.onMessage.addListener((request, sender, response) => {
if (request.method === 'get-title') {
const req = new XMLHttpRequest();
req.open('GET', request.url);
req.responseType = 'document';
req.onload = () => {
const title = req.responseXML.title;
if (title) {
response(title);
}
else {
response();
}
};
req.onerror = () => response();
req.send();
return true;
}
});
// Context Menu
chrome.contextMenus.create({
id: 'remove-link',
contexts: ['link'],
title: 'Remove this link',
documentUrlPatterns: [
chrome.runtime.getURL('data/override/index.html')
]
});
chrome.contextMenus.onClicked.addListener(() => {
chrome.runtime.sendMessage({
method: 'remove-link'
});
});
// FAQs & Feedback
chrome.storage.local.get({
'version': null,
'faqs': navigator.userAgent.toLowerCase().indexOf('Firefox') === -1
}, prefs => {
const version = chrome.runtime.getManifest().version;
if (prefs.version ? (prefs.faqs && prefs.version !== version) : true) {
chrome.storage.local.set({version}, () => {
chrome.tabs.create({
url: 'http://add0n.com/new-tab.html?version=' + version +
'&type=' + (prefs.version ? ('upgrade&p=' + prefs.version) : 'install')
});
});
}
});
{
const {name, version} = chrome.runtime.getManifest();
chrome.runtime.setUninstallURL('http://add0n.com/feedback.html?name=' + name + '&version=' + version);
}