ora/src/client/blocked.js

18 lines
446 B
JavaScript
Raw Normal View History

2021-11-23 14:12:38 +01:00
import browser from 'webextension-polyfill'
import { readable } from 'svelte/store'
async function check(set) {
if (window.document.hidden) return
const isBlocked = await browser.runtime.sendMessage({
type: 'check',
host: window.location.host,
})
set(isBlocked)
}
export const blocked = new readable(false, (set) => {
check(set)
const interval = setInterval(() => check(set), 1000)
return () => clearInterval(interval)
})