import {useEffect, useState} from 'react'; import type {FC} from 'react'; import browser, {Tabs} from 'webextension-polyfill'; import {getStorage} from '../utils/storage'; import {TabInfo} from './components/TabInfo/TabInfo'; import {FooterActions} from './components/FooterActions/FooterActions'; import styles from './Popup.module.scss'; function openWebPage(url: string): Promise { return browser.tabs.create({url}); } interface TabData { title: string; url: string; favIconUrl?: string; } const Popup: FC = () => { const [tabInfo, setTabInfo] = useState(null); const [username, setUsername] = useState(''); useEffect(() => { browser.tabs.query({active: true, currentWindow: true}).then((tabs) => { const tab = tabs[0]; if (tab) { setTabInfo({ title: tab.title || 'Unknown', url: tab.url || 'Unknown', favIconUrl: tab.favIconUrl, }); } }); getStorage(['username']).then(({username: storedUsername}) => { setUsername(storedUsername); }); }, []); const handleReloadTab = async (): Promise => { const tabs = await browser.tabs.query({ active: true, currentWindow: true, }); const tab = tabs[0]; if (tab?.id) { await browser.tabs.reload(tab.id); } }; return (

Web Extension Starter

{username &&

Hello, {username}!

}
{tabInfo && (
)} => openWebPage('/Options/options.html') } onGitHub={(): Promise => openWebPage( 'https://github.com/abhijithvijayan/web-extension-starter' ) } onSupport={(): Promise => openWebPage('https://www.buymeacoffee.com/abhijithvijayan') } />
); }; export default Popup;