From 53778546344314bf6f8de3579babbe6f8f03f224 Mon Sep 17 00:00:00 2001 From: z0ccc Date: Sat, 26 Jun 2021 23:42:31 -0400 Subject: [PATCH] Added options code --- public/manifest.json | 2 +- public/options.js | 12 ++++++++++++ src/components/TableWrap.js | 10 +++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 public/options.js diff --git a/public/manifest.json b/public/manifest.json index d521e97..69f0b92 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -3,7 +3,7 @@ "description": "Vytal", "manifest_version": 3, "version": "1.0.0", - "permissions": [], + "permissions": ["storage"], "icons": { "16": "icon_16.png", "32": "icon_32.png", diff --git a/public/options.js b/public/options.js new file mode 100644 index 0000000..004ac64 --- /dev/null +++ b/public/options.js @@ -0,0 +1,12 @@ +chrome.storage.sync.get('sendData', ({ sendData }) => { + document.getElementById('sendData').checked = sendData; +}); + +window.onchange = function change(event) { + if (event.target.matches('#sendData')) { + chrome.storage.sync.get('sendData', ({ sendData }) => { + const value = !sendData; + chrome.storage.sync.set({ sendData: value }); + }); + } +}; diff --git a/src/components/TableWrap.js b/src/components/TableWrap.js index ce1476b..c9d4e53 100644 --- a/src/components/TableWrap.js +++ b/src/components/TableWrap.js @@ -24,7 +24,7 @@ const sortPlugins = (data) => { return list; }; -const sendData = (data) => { +const fetchData = (data) => { fetch('http://localhost:8000/', { method: 'POST', headers: { @@ -48,6 +48,12 @@ const TableWrap = () => { setBatLevel('N/A'); setBatStatus('N/A'); } + + chrome.storage.sync.get('sendData', ({ sendData }) => { + if (!sendData) { + fetchData(software.concat(hardware)); + } + }); }, []); const uaResult = Bowser.parse(navigator.userAgent); @@ -191,8 +197,6 @@ const TableWrap = () => { }, ]; - sendData(software.concat(hardware)); - return (