From d91eeb74d11fe5fe282ef9086d0710f20431d6c9 Mon Sep 17 00:00:00 2001 From: z0ccc Date: Sat, 23 Jul 2022 16:20:33 -0400 Subject: [PATCH] whitelist add functionality and list --- src/pages/Popup/WhitelistPage.tsx | 40 +++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/pages/Popup/WhitelistPage.tsx b/src/pages/Popup/WhitelistPage.tsx index bed1d62..800b2e7 100644 --- a/src/pages/Popup/WhitelistPage.tsx +++ b/src/pages/Popup/WhitelistPage.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react' -import { Box, Label, Input, Flex } from 'theme-ui' +import { Box, Label, Input, Flex, Button } from 'theme-ui' import LocationInput from './LocationInput' import ConfigurationSelect from './ConfigurationSelect' import IPData from './IPData' @@ -9,21 +9,31 @@ const WhitelistPage = ({ tab }: any) => { const [ip, setIP] = useState(null) const [configuration, setConfiguration] = useState('default') const [currentUrl, setCurrentUrl] = useState('') + const [whitelist, setWhitelist] = useState([]) const getCurrentUrl = async () => { - let queryOptions = { active: true, lastFocusedWindow: true } - // `tab` will either be a `tabs.Tab` instance or `undefined`. - let [tab] = await chrome.tabs.query(queryOptions) + const queryOptions = { active: true, lastFocusedWindow: true } + const [tab] = await chrome.tabs.query(queryOptions) if (tab.url) { - let domain = new URL(tab.url) - setCurrentUrl(domain.hostname.replace('www.', '')) + const domain = new URL(tab.url) + const hostname = domain.hostname.replace('www.', '') + if (hostname.includes('.')) { + setCurrentUrl(hostname) + } } } useEffect(() => { getCurrentUrl() + chrome.storage.sync.get(['whitelist'], (result) => { + result.whitelist && setWhitelist(result.whitelist) + }) }, []) + useEffect(() => { + chrome.storage.sync.set({ whitelist }) + }, [whitelist]) + return ( { > Whitelist - + + + {whitelist.map((element, index) => { + return ( +
+

{element}

+
+ ) + })}
) }