-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
81 lines (69 loc) · 2.05 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
75
76
77
78
79
80
81
// background script is invoked on browser starts
//
if (navigator.appVersion.indexOf('Win') != -1) OSName = 'Windows';
if (navigator.appVersion.indexOf('Mac') != -1) OSName = 'MacOS';
if (navigator.appVersion.indexOf('X11') != -1) OSName = 'UNIX';
if (navigator.appVersion.indexOf('Linux') != -1) OSName = 'Linux';
var EXCLUDED_PREFIXES = [
'https://chrome.google.com/webstore',
'chrome'
];
var defaultSetting = {
state: 'activated',
style: {
showHand: 'true'
},
scroll: {
reverse: 'yes',
slide: 'yes',
scale: '1.5'
}
};
if (OSName === 'Windows') {
defaultSetting.activation = { mouse: '3', key: [] };
} else if (OSName === 'MacOS') {
defaultSetting.activation = { mouse: '', key: ['ctrlKey'] };
const setting = getLocalSetting();
if (setting && setting.activation) {
setting.activation = { mouse: '', key: ['ctrlKey'] };
localStorage.setting = JSON.stringify(setting);
}
} else if (OSName === 'Linux' || OSName === 'UNIX') {
defaultSetting.activation = { mouse: '2', key: [] };
const setting = getLocalSetting();
if (setting && setting.activation && setting.activation.mouse === 3) {
setting.activation = { mouse: '2', key: [] };
localStorage.setting = JSON.stringify(setting);
}
}
function getLocalSetting() {
var settingStr = localStorage['setting'];
var setting;
if (!settingStr)
setting = defaultSetting;
else
setting = JSON.parse(settingStr);
return setting;
}
chrome.runtime.onMessage.addListener(function(msg, sender, sendRespond) {
if (msg.type == 'handtool.content.requestSetting') {
sendRespond(getLocalSetting());
}
});
var manifest = chrome.app.getDetails();
function reloadContentScript(tab) {
chrome.tabs.executeScript(tab.id, {
file: "inject.js"
});
}
chrome.windows.getAll({
populate: true
}, function(windows) {
windows.forEach(function(window) {
window.tabs.forEach(function(tab) {
for (i = 0; i < EXCLUDED_PREFIXES.length; i++)
if (tab.url && tab.url.indexOf(EXCLUDED_PREFIXES[i]) === 0) return;
reloadContentScript(tab);
});
})
});