feat: reduce permissions for pageState script

This commit is contained in:
SethBurkart123
2025-02-24 15:52:24 +11:00
parent 44325f0d49
commit ca5d232e47
4 changed files with 15 additions and 31 deletions
+8 -4
View File
@@ -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
+1 -23
View File
@@ -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':
@@ -76,14 +62,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');
}
+1 -1
View File
@@ -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"
+4 -2
View File
@@ -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 = [
@@ -30,8 +34,6 @@ const clickListeners = [
];
const registerClickListeners = () => {
console.log("Registering click listeners...");
document.addEventListener('click', (e) => {
const target = e.target as HTMLElement;