diff --git a/src/SEQTA.ts b/src/SEQTA.ts index 09ae6aff..cfdba229 100644 --- a/src/SEQTA.ts +++ b/src/SEQTA.ts @@ -19,6 +19,7 @@ import { enableCurrentTheme } from '@/seqta/ui/themes/enableCurrent' import loading, { AppendLoadingSymbol } from '@/seqta/ui/Loading' import { SettingsResizer } from '@/seqta/ui/SettingsResizer' import { updateAllColors } from '@/seqta/ui/colors/Manager' +import pageState from '@/pageState.js?url' // JSON content import MenuitemSVGKey from '@/seqta/content/MenuItemSVGKey.json' @@ -74,7 +75,7 @@ async function init() { await initializeSettingsState(); if (settingsState.onoff) { - browser.runtime.sendMessage({ type: 'injectMainScript' }) + injectMainScript(); enableCurrentTheme() if (typeof settingsState.assessmentsAverage == 'undefined') { @@ -406,10 +407,13 @@ export function OpenWhatsNewPopup() { }) } +function injectMainScript() { + const mainScript = document.createElement('script') + mainScript.src = browser.runtime.getURL(pageState) + document.head.appendChild(mainScript) +} + export function hideSideBar() { - - - const sidebar = document.getElementById('menu') // The sidebar element to be closed const main = document.getElementById('main') // The main content element that must be resized to fill the page diff --git a/src/background.ts b/src/background.ts index 18b445a4..8fe1c907 100644 --- a/src/background.ts +++ b/src/background.ts @@ -13,22 +13,8 @@ function reloadSeqtaPages() { result.then(open, console.error) } -async function injectPageState(tabId: number) { - try { - await browser.scripting.executeScript({ - target: { tabId }, - files: ["pageState.js"], - // @ts-ignore - world: "MAIN", - }); - console.info(`[background] Injected pageState.js into tab ${tabId}`); - } catch (err) { - console.error(`[background] Failed to inject pageState.js into tab ${tabId}:`, err); - } -} - // Main message listener -browser.runtime.onMessage.addListener((request: any, sender: any, sendResponse: (response?: any) => void) => { +browser.runtime.onMessage.addListener((request: any, _: any, sendResponse: (response?: any) => void) => { switch (request.type) { case 'reloadTabs': @@ -75,14 +61,6 @@ browser.runtime.onMessage.addListener((request: any, sender: any, sendResponse: GetNews(sendResponse, url); return true; - - - case 'injectMainScript': { - const senderTab = sender.tab ? sender.tab.id : undefined; - - injectPageState(senderTab!) - return; - } default: console.log('Unknown request type'); diff --git a/src/manifests/manifest.json b/src/manifests/manifest.json index d7612deb..3c34412c 100644 --- a/src/manifests/manifest.json +++ b/src/manifests/manifest.json @@ -15,7 +15,7 @@ "64": "resources/icons/icon-64.png" } }, - "permissions": ["tabs", "notifications", "storage", "scripting", "activeTab"], + "permissions": ["tabs", "notifications", "storage"], "host_permissions": ["https://newsapi.org/", "*://*/*"], "background": { "service_worker": "background.ts" diff --git a/src/seqta/utils/listeners/ClickListeners.ts b/src/seqta/utils/listeners/ClickListeners.ts index 84e76699..6baeb463 100644 --- a/src/seqta/utils/listeners/ClickListeners.ts +++ b/src/seqta/utils/listeners/ClickListeners.ts @@ -20,6 +20,10 @@ const handleNotificationClick = async (target: HTMLElement) => { // Select the specific direct message ReactFiber.find('.Viewer__Viewer___32BH-').setState({ selected: new Set([matchingNotification.message.messageID]) }); + + // Close the notifications panel + const notificationButton = document.querySelector('.notifications__notifications___3mmLY > button') as HTMLButtonElement | null; + notificationButton?.click(); }; const clickListeners = [ @@ -29,9 +33,7 @@ const clickListeners = [ }, ]; -const registerClickListeners = () => { - console.log("Registering click listeners..."); - +const registerClickListeners = () => { document.addEventListener('click', (e) => { const target = e.target as HTMLElement;