mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
feat: reduce permissions for pageState script
This commit is contained in:
+8
-4
@@ -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
@@ -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');
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user