From 1acc0d4244b882d789c2122a5eb5e650a85c44ca Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Mon, 22 Nov 2021 20:07:06 +0100 Subject: [PATCH] progress --- manifest.json | 3 +- package.json | 1 + pnpm-lock.yaml | 7 ++ src/background/index.js | 8 +- src/client/index.css | 18 ++++ src/client/index.js | 33 ++++--- src/dashboard/components/DurationInput.svelte | 14 +++ src/dashboard/components/Footer.svelte | 11 ++- src/dashboard/components/RangeChooser.svelte | 16 +++- src/dashboard/components/RulesEditor.svelte | 31 +++--- src/dashboard/components/StorageQuota.svelte | 17 ++++ src/dashboard/pages/Limits.svelte | 3 +- src/dashboard/pages/Options.svelte | 94 +------------------ src/dashboard/views/Settings.svelte | 47 ++++++++++ src/dashboard/views/YourData.svelte | 49 ++++++++++ src/shared/db.js | 43 +++------ src/shared/validation.js | 43 +++++++++ 17 files changed, 275 insertions(+), 163 deletions(-) create mode 100644 src/client/index.css create mode 100644 src/dashboard/components/DurationInput.svelte create mode 100644 src/dashboard/components/StorageQuota.svelte create mode 100644 src/dashboard/views/Settings.svelte create mode 100644 src/dashboard/views/YourData.svelte create mode 100644 src/shared/validation.js diff --git a/manifest.json b/manifest.json index 4bd42fa..a37b663 100644 --- a/manifest.json +++ b/manifest.json @@ -30,7 +30,8 @@ "content_scripts": [ { "matches": [""], - "js": ["./src/client/index.js"] + "js": ["./src/client/index.js"], + "css": ["./src/client/index.css"] } ], "web_accessible_resources": ["./icons/watch.png", "./icons/watch-alt.png", "./src/dashboard/index.html"] diff --git a/package.json b/package.json index 24cbcd5..27ef37e 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "file-saver": "^2.0.5", "joi": "^17.4.2", "lodash": "^4.17.21", + "pretty-bytes": "^5.6.0", "spectre.css": "^0.5.9", "svelte-spa-router": "^3.2.0", "tailwindcss": "^1.9.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ad7a8d..93c3b09 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,7 @@ specifiers: npm-run-all: ^4.1.5 parcel: ^2.0.1 parcel-transformer-svelte: ^1.2.3 + pretty-bytes: ^5.6.0 spectre.css: ^0.5.9 svelte: ^3.44.2 svelte-spa-router: ^3.2.0 @@ -29,6 +30,7 @@ dependencies: file-saver: 2.0.5 joi: 17.4.2 lodash: 4.17.21 + pretty-bytes: 5.6.0 spectre.css: 0.5.9 svelte-spa-router: 3.2.0 tailwindcss: 1.9.6 @@ -5707,6 +5709,11 @@ packages: engines: {node: '>=4'} dev: true + /pretty-bytes/5.6.0: + resolution: {integrity: sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg==} + engines: {node: '>=6'} + dev: false + /pretty-hrtime/1.0.3: resolution: {integrity: sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=} engines: {node: '>= 0.8'} diff --git a/src/background/index.js b/src/background/index.js index 0a3c008..4abc014 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -48,5 +48,11 @@ setInterval(deleteOldLogs, 5 * 60 * 1000) // Delete old logs every 5 minutes setInterval(log, frequency) browser.runtime.onMessage.addListener((message, sender, sendResponse) => { - return getUsageForHost(message).then((percentages) => percentagesToBool(percentages)) + switch (message.type) { + case 'check': + return getUsageForHost(message.host).then((percentages) => percentagesToBool(percentages)) + case 'report': + DB.settings.put({ key: 'lastActivity', value: new Date() }) + break + } }) diff --git a/src/client/index.css b/src/client/index.css new file mode 100644 index 0000000..e27f63a --- /dev/null +++ b/src/client/index.css @@ -0,0 +1,18 @@ +.ora--wrapper { + display: none; + position: fixed; + color: #111; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + background-color: #eee; + z-index: 999999999; +} + +@media (prefers-color-scheme: dark) { + .ora--wrapper { + background-color: #000000; + color: #eee; + } +} diff --git a/src/client/index.js b/src/client/index.js index 5234afc..ecb17e0 100644 --- a/src/client/index.js +++ b/src/client/index.js @@ -1,20 +1,10 @@ import browser from 'webextension-polyfill' let wrapper +let lastReported = 0 function init() { wrapper = window.document.createElement('div') - Object.assign(wrapper.style, { - display: 'none', - position: 'fixed', - color: '#000', - top: '0', - left: '0', - width: '100vw', - height: '100vh', - backgroundColor: '#ffffff', - zIndex: '999999999', - }) wrapper.classList.add('ora--wrapper') wrapper.classList.add('hidden') @@ -35,10 +25,27 @@ function init() { async function check() { if (window.document.hidden) return - const isBlocked = await browser.runtime.sendMessage(window.location.host) + const isBlocked = await browser.runtime.sendMessage({ + type: 'check', + host: window.location.host, + }) wrapper.style.display = isBlocked ? 'initial' : 'none' } init() -setInterval(check, 2000) check() +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) diff --git a/src/dashboard/components/DurationInput.svelte b/src/dashboard/components/DurationInput.svelte new file mode 100644 index 0000000..f58f3a7 --- /dev/null +++ b/src/dashboard/components/DurationInput.svelte @@ -0,0 +1,14 @@ + + +{#if Array.isArray(value)} + + +{/if} diff --git a/src/dashboard/components/Footer.svelte b/src/dashboard/components/Footer.svelte index cb439aa..be93ba2 100644 --- a/src/dashboard/components/Footer.svelte +++ b/src/dashboard/components/Footer.svelte @@ -1,9 +1,10 @@