-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
64 lines (54 loc) · 2.39 KB
/
content.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
const script = document.createElement('script');
script.src = chrome.runtime.getURL('buttercup.js');
document.documentElement.prepend(script);
// set default config if not set
chrome.storage.sync.get(['buttercup_translate'], function (result) {
if (result.buttercup_translate === undefined) {
chrome.storage.sync.set({ buttercup_translate: false });
}
});
chrome.storage.sync.get(['buttercup_enabled'], function (result) {
if (result.buttercup_enabled === undefined) {
chrome.storage.sync.set({ buttercup_enabled: true });
}
});
chrome.storage.sync.get(['buttercup_cache'], function (result) {
if (result.buttercup_cache === undefined) {
chrome.storage.sync.set({ buttercup_cache: true });
}
});
chrome.storage.sync.get(['buttercup_download_srt'], function (result) {
if (result.buttercup_download_srt === undefined) {
chrome.storage.sync.set({ buttercup_download_srt: false });
}
});
// Listen for the custom event
document.addEventListener('requestButtercupTranslate', function () {
chrome.storage.sync.get(['buttercup_translate'], function (result) {
const translate = result.buttercup_translate;
// Send the value back to the page
document.dispatchEvent(new CustomEvent('responseButtercupTranslate', { detail: translate }));
});
});
document.addEventListener('requestButtercupEnabled', function () {
chrome.storage.sync.get(['buttercup_enabled'], function (result) {
const enabled = result.buttercup_enabled;
// Send the value back to the page
document.dispatchEvent(new CustomEvent('responseButtercupEnabled', { detail: enabled }));
});
});
document.addEventListener('requestButtercupCache', function () {
chrome.storage.sync.get(['buttercup_cache'], function (result) {
const cache = result.buttercup_cache;
// Send the value back to the page
document.dispatchEvent(new CustomEvent('responseButtercupCache', { detail: cache }));
});
});
document.addEventListener('requestButtercupDownloadSrt', function () {
chrome.storage.sync.get(['buttercup_download_srt'], function (result) {
const download = result.buttercup_download_srt;
// Send the value back to the page
document.dispatchEvent(new CustomEvent('responseButtercupDownloadSrt', { detail: download }));
});
});
document.dispatchEvent(new CustomEvent('buttercupSettingsChanged'));