-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
hypothesis.js
54 lines (47 loc) · 1.91 KB
/
hypothesis.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
var hypothesis;
(async function() {
if (window.document.querySelector('hypothesis-sidebar')) {
var config = await browser.storage.local.get('activeSites');
if (typeof config.activeSites === 'undefined') {
config.activeSites = {};
}
config.activeSites[window.location.href] = true;
await browser.storage.local.set({
activeSites: config.activeSites
});
}
hypothesis = {
enable: async function () {
if (window.document.querySelector('hypothesis-sidebar')) {
window.document.querySelector('hypothesis-sidebar').style.opacity = 1;
window.document.querySelector('hypothesis-adder').style.opacity = 1;
return;
}
// Initial config
var hypothesisConfig = {
openSidebar: false,
showHighlights: true,
appType: 'bookmarklet'
};
var results = await browser.storage.local.get('hypothesisHash');
var d = window.document;
var c = d.createElement('script');
c.setAttribute('type', 'application/javascript');
c.setAttribute('nonce', 'w9s09t');
c.textContent = `window.hypothesisConfig = function () {
return ${JSON.stringify(hypothesisConfig)};
};`;
d.body.appendChild(c);
var s = d.createElement('script');
s.setAttribute('src', 'https://hypothes.is/embed.js');
s.setAttribute('hash', results['hypothesisHash']);
d.body.appendChild(s);
},
disable: function () {
if (window.document.querySelector('hypothesis-sidebar')) {
window.document.querySelector('hypothesis-adder').style.opacity = 0;
window.document.querySelector('hypothesis-sidebar').style.opacity = 0;
}
},
};
})();