forked from dword-design/accessibility-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
26 lines (23 loc) · 756 Bytes
/
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
import { property } from '@dword-design/functions'
import styleCode from './assets/style.scss'
const toggle = enabled => {
let style = document.querySelector('style.accessibility-view')
if (style) {
style.remove()
}
if (enabled) {
style = document.createElement('style')
style.classList.add('accessibility-view')
style.type = 'text/css'
style.appendChild(document.createTextNode(styleCode))
document.getElementsByTagName('head')[0].appendChild(style)
}
}
browser.storage.onChanged.addListener((changes, area) => {
if (area === 'local' && 'enabled' in changes) {
toggle(changes.enabled.newValue)
}
})
const init = async () =>
toggle(browser.storage.local.get('enabled') |> await |> property('enabled'))
init()