From fa69e2ec340445e0229e66cc7b757652fc0fbca4 Mon Sep 17 00:00:00 2001 From: z0ccc Date: Sat, 11 Sep 2021 17:49:01 -0400 Subject: [PATCH] Added battery api to other block --- frontend/src/components/OtherBlock.js | 28 +++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/OtherBlock.js b/frontend/src/components/OtherBlock.js index 8cd7553..6c0a049 100644 --- a/frontend/src/components/OtherBlock.js +++ b/frontend/src/components/OtherBlock.js @@ -1,18 +1,13 @@ /* eslint-disable arrow-body-style */ /* eslint-disable no-unused-vars */ import { useState, useEffect } from 'react'; -import Bowser from 'bowser'; import ScanBlock from './ScanBlock'; -import Table from './Table'; -import { - checkNavigatorProperties, - checkWebWorker, - checkScreenProperties, - detectTor, -} from './main'; +import { detectTor } from './main'; const OtherBlock = () => { const [adBlockDetected, setAdBlockDetected] = useState(false); + const [batteryLevel, setBatteryLevel] = useState(); + const [batteryStatus, setBatteryStatus] = useState(); useEffect(() => { fetch('https://www3.doubleclick.net', { @@ -22,6 +17,11 @@ const OtherBlock = () => { }).catch(() => { setAdBlockDetected(true); }); + + navigator.getBattery().then((res) => { + setBatteryLevel(`${Math.round(res.level * 100)}%`); + setBatteryStatus(res.charging ? 'Charging' : 'Not charging'); + }); }, []); return ( @@ -47,6 +47,18 @@ const OtherBlock = () => { {adBlockDetected ? 'True' : 'False'} + + + Battery level + {batteryLevel} + + + + + Battery status + {batteryStatus} + +