-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
77 lines (68 loc) · 2.25 KB
/
background.js
File metadata and controls
77 lines (68 loc) · 2.25 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// can't record a new URL-visit entry within delayTime (in ms)
var delayTime = 5000;
// record user webcam input after inputTime (in ms)
var inputTime = 2500;
var allowFocusChange = true;
chrome.tabs.onUpdated.addListener(function (tabId, tabUpdateInfo, tabState) {
if (allowFocusChange && isValidURL(tabUpdateInfo.url)) {
var category = getCategory(tabUpdateInfo.url);
if (category != 'Other') {
chrome.storage.sync.get({ categories: [] }, function (items) {
var categories;
console.log(items)
if (items == null) {
categories = [];
categories.push({
category: category
});
chrome.storage.sync.set({ categories: categories }, function () {
chrome.storage.local.get('categories', function (test) {
console.log(test.categories)
});
});
} else {
categories = items.categories;
categories.push({ category: category });
chrome.storage.sync.set({ categories: categories }, function () {
chrome.storage.local.get('sentiments', function (test) {
console.log(test.categories)
});
});
}
});
// placeholder for opening secondary capture window
setTimeout(function() {
chrome.windows.create({ url: './secondaryPopup/secondaryPopup.html', type: 'popup', top: 0, left: 0, height: 1, width: 1, focused: false });
concatFocusChange();
}, inputTime);
}
}
});
function concatFocusChange() {
allowFocusChange = false;
setTimeout(function () { allowFocusChange = true }, delayTime);
}
function isValidURL(url) {
return (url != null && !url.startsWith('chrome'));
}
function getCategory(url) {
if (url.includes("facebook")) return 'Social Networking';
if (url.includes("amazon")) return 'Shopping';
if (url.includes("cnn")) return 'News';
if (url.includes("ubc")) return 'Education';
if (url.includes("techcrunch")) return 'Technology';
if (url.includes("nba")) return 'Sports';
if (url.includes("bloomberg")) return 'Finance';
return 'Other'
}
chrome.storage.onChanged.addListener(function (changes, namespace) {
for (key in changes) {
var storageChange = changes[key];
console.log('Storage key "%s" in namespace "%s" changed. ' +
'Old value was "%s", new value is "%s".',
key,
namespace,
storageChange.oldValue,
storageChange.newValue);
}
});