forked from jedediah/wetbanana
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbackground.js
More file actions
80 lines (71 loc) · 2.17 KB
/
Copy pathbackground.js
File metadata and controls
80 lines (71 loc) · 2.17 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
78
79
80
defaultOptions = { "button": 2,
"key_shift": false,
"key_ctrl": false,
"key_alt": false,
"key_meta": false,
"scaling": 1,
"speed": 6000,
"friction": 10,
"cursor": true,
"notext": false,
"nolinks": false,
"nobuttons": false,
"nolabels": false,
"noimages": false,
"noembeds": false,
"grab_and_drag": false,
"debug": false,
"blacklist": "",
"browser_enabled": true,
}
for (var k in defaultOptions)
if (typeof localStorage[k] == 'undefined')
localStorage[k] = defaultOptions[k]
function loadOptions() {
var o = {}
for (var k in defaultOptions) o[k] = localStorage[k]
return o
}
clients = {}
chrome.extension.onConnect.addListener(function(port) {
port.postMessage({ saveOptions: localStorage })
var id = port.sender.tab.id + ":" + port.sender.frameId
console.log("connect: "+id)
clients[id] = port
port.onDisconnect.addListener(function() {
console.log("disconnect: "+id)
delete clients[id]
})
})
function saveOptions(o) {
for (var k in o) {
localStorage[k] = o[k]
}
for (var id in clients) {
clients[id].postMessage({ saveOptions: localStorage })
}
}
chrome.browserAction.onClicked.addListener(function(tab) {
if (localStorage['browser_enabled'] == "true") {
localStorage['browser_enabled'] = "false"
chrome.browserAction.setIcon({path:"icon16dis.png"})
}
else {
localStorage['browser_enabled'] = "true"
chrome.browserAction.setIcon({path:"icon16.png"})
}
saveOptions({o:'browser_enabled'})
})
// Inject content script into all existing tabs (doesn't work)
// This functionality requires
// "permissions": ["tabs"]
// in manifest.json
/*
chrome.windows.getAll({populate:true}, function(wins) {
wins.forEach(function(win) {
win.tabs.forEach(function(tab) {
chrome.tabs.executeScript(tab.id,{file:"content.js",allFrames:true});
})
})
})
*/