ora/src/client/index.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-09-20 22:24:57 +02:00
import browser from 'webextension-polyfill'
let wrapper
2021-11-22 20:07:06 +01:00
let lastReported = 0
2020-09-20 22:24:57 +02:00
function init() {
wrapper = window.document.createElement('div')
wrapper.classList.add('ora--wrapper')
wrapper.classList.add('hidden')
const inner = window.document.createElement('div')
inner.innerHTML = `
<h1>Overtime </h1>
<p>You have no time left on this website 🥺</p>
`
wrapper.appendChild(inner)
window.document.body.appendChild(wrapper)
}
async function check() {
if (window.document.hidden) return
2021-11-22 20:07:06 +01:00
const isBlocked = await browser.runtime.sendMessage({
type: 'check',
host: window.location.host,
})
2020-09-20 22:24:57 +02:00
wrapper.style.display = isBlocked ? 'initial' : 'none'
}
init()
check()
2021-11-22 20:07:06 +01:00
setInterval(check, 2000)
function logActivity() {
const now = Date.now()
// Limit reports to once every second
if (now - lastReported < 1000) return
lastReported = now
browser.runtime.sendMessage({
type: 'report',
})
}
window.document.addEventListener('mousemove', logActivity, false)
window.document.addEventListener('keydown', logActivity, false)
window.document.addEventListener('scroll', logActivity, false)