diff --git a/ROADMAP.md b/ROADMAP.md index 0d16a64..b4e51d4 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,11 +2,10 @@ ## Current -- d3 graph +- Max time for website -> block. ## Backlog -- Max time for website -> block - Dark mode support - Options - Dashboard diff --git a/manifest.json b/manifest.json index 69e32f2..f213101 100644 --- a/manifest.json +++ b/manifest.json @@ -29,7 +29,7 @@ "content_scripts": [ { "matches": [""], - "js": [] + "js": ["./src/client/index.js"] } ], "web_accessible_resources": ["./icons/stopwatch.svg", "./icons/stopwatch-inv.svg"] diff --git a/package.json b/package.json index a77da5b..80b3379 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,9 @@ "name": "ora", "private": true, "scripts": { + "clean": "rm -rf dist .cache", "dev": "parcel watch --no-hmr manifest.json src/dashboard/index.html", - "build": "parcel build --no-content-hash --no-source-maps manifest.json src/dashboard/index.html", - "launch": "web-ext run -s dist" + "build": "parcel build --no-content-hash --no-source-maps manifest.json src/dashboard/index.html" }, "browserslist": [ "last 2 chrome versions", diff --git a/src/background/index.js b/src/background/index.js index 967cc3c..e094312 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,7 +1,8 @@ import browser from 'webextension-polyfill' import { dashboard } from '../shared/utils' -import { insertLog, normalizeTimestamp } from '../shared/db' +import { insertLog, normalizeTimestamp, Limits } from '../shared/db' +import { getUsageForHost, percentagesToBool } from '../shared/lib' browser.browserAction.onClicked.addListener(() => browser.tabs.create({ url: dashboard, active: true })) @@ -37,3 +38,8 @@ async function getAllTabs() { setInterval(() => { getAllTabs() }, frequency) + +browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => { + // await Limits. + return getUsageForHost(message).then((percentages) => percentagesToBool(percentages)) +}) diff --git a/src/client/index.js b/src/client/index.js new file mode 100644 index 0000000..0b0b91f --- /dev/null +++ b/src/client/index.js @@ -0,0 +1,44 @@ +import browser from 'webextension-polyfill' + +let wrapper + +function init() { + wrapper = window.document.createElement('div') + Object.assign(wrapper.style, { + display: 'none', + position: 'fixed', + top: '0', + left: '0', + width: '100vw', + height: '100vh', + backgroundColor: '#ffffff', + zIndex: '999999999', + }) + wrapper.classList.add('ora--wrapper') + wrapper.classList.add('hidden') + + const inner = window.document.createElement('div') + Object.assign(inner.style, { + fontFamily: `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif`, + margin: '3em auto', + width: '100%', + maxWidth: '20em', + }) + inner.innerHTML = ` +

Overtime ⏱

+

You have no time left on this website 🥺

+ ` + wrapper.appendChild(inner) + window.document.body.appendChild(wrapper) +} + +async function check() { + if (window.document.hidden) return + console.log('Checking') + const isBlocked = await browser.runtime.sendMessage(window.location.host) + wrapper.style.display = isBlocked ? 'initial' : 'none' +} + +init() +setInterval(check, 5000) +check() diff --git a/src/dashboard/App.svelte b/src/dashboard/App.svelte index bb31f96..fd1fe41 100644 --- a/src/dashboard/App.svelte +++ b/src/dashboard/App.svelte @@ -1,17 +1,10 @@