-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
37 lines (35 loc) · 1.04 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
/**
* restore option when page is loaded or refreshed.
*/
function setOption(tabId) {
chrome.storage.local.get({
keyMode: "ARROW",
isOn: true
}, (items) => {
const setCode = "window.__spatialNavigation__.setKeyMode('";
if (items.isOn == false) {
chrome.tabs.executeScript(tabId, {
code: setCode.concat("NONE')")
}, (err) => {
const e = chrome.runtime.lastError;
if (e != undefined) {
console.log(tabId, err, e);
}
});
} else {
chrome.tabs.executeScript(tabId, {
code: setCode.concat(items.keyMode, "')")
}, (err) => {
const e = chrome.runtime.lastError;
if (e != undefined) {
console.log(tabId, err, e);
}
});
}
});
}
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status == "complete") {
setOption(tabId);
}
});