-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventPage.js
More file actions
59 lines (56 loc) · 1.85 KB
/
eventPage.js
File metadata and controls
59 lines (56 loc) · 1.85 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
59
chrome.runtime.onInstalled.addListener(function(o){
var sheetID = "https://docs.google.com/spreadsheets/d/1FWp879VjaBzrcZXYKTMpxKba1KXNNXlBI2hSSAigx4s/pub?output=csv";
var sites = [];
$.get(sheetID, function(data){
Papa.parse(sheetID, {
download: true,
step: function(row){
var site = {lvl: row.data[0][0], domain: row.data[0][1]};
sites.push(site);
},
complete: function() {
chrome.storage.sync.set({"listDomains":sites}, function(){
});
chrome.storage.sync.get("listDomains", function(datas){
});
}
});
})
// chrome.runtime.openOptionsPage();
// chrome.tabs.create({url: "http://yoursite.com/"}, function (tab) {
// console.log("New tab launched with http://yoursite.com/");
// });
});
chrome.tabs.onActivated.addListener(function(activeInfos){
var url;
chrome.tabs.query({"active": true}, function(tabs){
var url = "";
if (tabs[0].url)
url = new URL(tabs[0].url).hostname;
updateUrl(url);
});
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab){
if (activeInfos.tabId == tabId){
if (changeInfo.url)
chrome.tabs.query({"active":true}, function (tabs){
updateUrl(new URL(tabs[0].url).hostname);
})
}
});
});
function updateUrl(url){
chrome.storage.sync.get("listDomains", function(datas){
var found = false;
var title = chrome.i18n.getMessage("msgInfo_unknown");
chrome.browserAction.setIcon({path: "icons/unknown.png"});
for (i = 0; i < datas.listDomains.length; ++i) {
var e = datas.listDomains[i];
if (url.search(e.domain) != -1){
found = true;
title = chrome.i18n.getMessage("msgInfo_"+e.lvl);
chrome.browserAction.setIcon({path: 'icons/'+e.lvl+'.png'});
}
}
chrome.browserAction.setTitle({title :title});
});
};