-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
30 lines (26 loc) · 951 Bytes
/
Copy pathcontent.js
File metadata and controls
30 lines (26 loc) · 951 Bytes
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
//check whether the user has activated the extension
chrome.storage.sync.get('state', async (data) => {
let noThemeActive = document.body.classList.contains('skin-vector-legacy');
if (noThemeActive && data.state === 'on') {
await inject();
//trigger a resize event so that wikipedia's js recalculates the top menu
window.dispatchEvent(new Event('resize'));
}
});
//inject CSS
async function inject() {
try {
//get the content of the CSS file
let path = chrome.runtime.getURL('styles/style.css');
let result = await fetch(path);
let css = await result.text();
//insert the CSS into the HTML document head
document.querySelector('head').insertAdjacentHTML('beforeend', '<style>' + css + '</style>');
} catch (error) {
console.warn(error);
}
}
//correct scroll behavior when jumping to anchors
window.addEventListener('hashchange', () => {
window.scrollBy(0, -document.querySelector("#firstHeading").offsetHeight)
});