-
Notifications
You must be signed in to change notification settings - Fork 2
/
mm.bg.js
81 lines (67 loc) · 1.89 KB
/
mm.bg.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
//browser starts
//invoke local storage for settings
//this background holds all extension's runtime data
//remember in-page js files don't have access to extension's runtime data
//while popup needs to be init & disposed multiple times -> unstable
//background page is where our app runs
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 defaultSetting = {
state: "activated",
style: {
showHand: "true"
},
scroll: {
reverse: "yes",
slide: "yes",
scale: "1.5"
},
activation: {
mouse: (OSName == "Linux" || OSName == "MacOS") ? "2" : "3",
key: []
}
};
function getLocalSetting() {
//get setting from local Storage
//return as object
//if local storage empty, return default
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) {
//message handler forwarder
if (msg.type == "mm.cs.requestSetting") {
sendRespond(getLocalSetting());
}
});
var manifest = chrome.app.getDetails();
var reloadContentScript = function(tab) {
var scripts = manifest.content_scripts[0].js;
for (var i = 0; i < scripts.length; i++) {
chrome.tabs.executeScript(tab.id, {
file: scripts[i]
});
}
}
var excludedPrefix = [
'https://chrome.google.com/webstore',
'chrome'
];
chrome.windows.getAll({
populate: true
}, function(windows) {
windows.forEach(function(w) {
w.tabs.forEach(function(tab) {
for (i = 0; i < excludedPrefix.length; i++)
if (tab.url.indexOf(excludedPrefix[i]) === 0) return;
reloadContentScript(tab);
});
})
});