-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontentscript.js
72 lines (67 loc) · 1.82 KB
/
contentscript.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
;
(function () {
const settings = {
rewindSec: 1,
seekForwardSec: 5,
keyObjects: JSON.stringify({
rewind: {
key: ",",
code: "Comma",
shiftKey: false,
ctrlKey: false,
altKey: false,
metaKey: false
},
forward: {
key: ".",
code: "Period",
shiftKey: false,
ctrlKey: false,
altKey: false,
metaKey: false
}
})
}
function onError(error) {
console.warn(browser.i18n.getMessage("debugCouldNotLoadSettings", browser.i18n.getMessage("extensionName")), error);
inject();
}
window.addEventListener("message", (event) => {
if (event.origin === window.origin) {
if (event.data.type === 'getI18nMessage') {
try {
if (typeof event.data.key !== 'string') {
throw new Error("key must be a string");
}
event.ports[0].postMessage({ result: browser.i18n.getMessage(event.data.key, ...event.data.params) });
} catch (e) {
if (!event.ports[0]) return;
event.ports[0].postMessage({ error: e });
}
}
}
}, false)
function onGot(item) {
if (item.rewindSec > 0) {
settings.rewindSec = item.rewindSec;
}
if (item.seekForwardSec > 0) {
settings.seekForwardSec = item.seekForwardSec;
}
if (item.keyObjects) {
settings.keyObjects = JSON.stringify(item.keyObjects);
}
inject()
}
let getting = browser.storage.sync.get();
getting.then(onGot, onError);
// Inject the script to the page:
function inject() {
var s = document.createElement('script');
s.src = chrome.runtime.getURL('netflix-rewind-1-sec.js?') + new URLSearchParams(settings);
s.onload = function () {
this.remove();
};
(document.head || document.documentElement).appendChild(s);
}
})()