-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathinject.js
31 lines (28 loc) · 1.03 KB
/
inject.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
// Injects the main script. This is necessary in order to bind a
// keyhandler.
function inject(scriptName) {
const scriptEl = document.createElement('script');
scriptEl.setAttribute('src', chrome.runtime.getURL(scriptName));
// In testing doesn't seem to be necessary, but may lead to more
// predictable execution order.
scriptEl.setAttribute('defer', 'defer');
document.getElementsByTagName('body')[0].appendChild(scriptEl);
}
// Set current options as an attribute on the body so that they are
// accessible to the injected scripts.
try {
todoistShortcutsLoadOptions((options) => {
document.body.setAttribute(
'data-todoist-shortcuts-options', JSON.stringify(options));
}, (e) => {
console.warning('Failed to load settings:', e);
});
} finally {
// Inject the scripts
inject('mousetrap.js');
inject('todoist-shortcuts.js');
// Set options URL so that help modal can link to it.
document.body.setAttribute(
'data-todoist-shortcuts-options-url',
chrome.runtime.getURL('options-page.html'));
}