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 loading, { AppendLoadingSymbol } from '@/seqta/ui/Loading'
|
||||||
import { SettingsResizer } from '@/seqta/ui/SettingsResizer'
|
import { SettingsResizer } from '@/seqta/ui/SettingsResizer'
|
||||||
import { updateAllColors } from '@/seqta/ui/colors/Manager'
|
import { updateAllColors } from '@/seqta/ui/colors/Manager'
|
||||||
|
import pageState from '@/pageState.js?url'
|
||||||
|
|
||||||
// JSON content
|
// JSON content
|
||||||
import MenuitemSVGKey from '@/seqta/content/MenuItemSVGKey.json'
|
import MenuitemSVGKey from '@/seqta/content/MenuItemSVGKey.json'
|
||||||
@@ -74,7 +75,7 @@ async function init() {
|
|||||||
await initializeSettingsState();
|
await initializeSettingsState();
|
||||||
|
|
||||||
if (settingsState.onoff) {
|
if (settingsState.onoff) {
|
||||||
browser.runtime.sendMessage({ type: 'injectMainScript' })
|
injectMainScript();
|
||||||
enableCurrentTheme()
|
enableCurrentTheme()
|
||||||
|
|
||||||
if (typeof settingsState.assessmentsAverage == 'undefined') {
|
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() {
|
export function hideSideBar() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const sidebar = document.getElementById('menu') // The sidebar element to be closed
|
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
|
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)
|
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
|
// 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) {
|
switch (request.type) {
|
||||||
case 'reloadTabs':
|
case 'reloadTabs':
|
||||||
@@ -76,14 +62,6 @@ browser.runtime.onMessage.addListener((request: any, sender: any, sendResponse:
|
|||||||
GetNews(sendResponse, url);
|
GetNews(sendResponse, url);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
case 'injectMainScript': {
|
|
||||||
const senderTab = sender.tab ? sender.tab.id : undefined;
|
|
||||||
|
|
||||||
injectPageState(senderTab!)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log('Unknown request type');
|
console.log('Unknown request type');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"64": "resources/icons/icon-64.png"
|
"64": "resources/icons/icon-64.png"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"permissions": ["tabs", "notifications", "storage", "scripting", "activeTab"],
|
"permissions": ["tabs", "notifications", "storage"],
|
||||||
"host_permissions": ["https://newsapi.org/", "*://*/*"],
|
"host_permissions": ["https://newsapi.org/", "*://*/*"],
|
||||||
"background": {
|
"background": {
|
||||||
"service_worker": "background.ts"
|
"service_worker": "background.ts"
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ const handleNotificationClick = async (target: HTMLElement) => {
|
|||||||
|
|
||||||
// Select the specific direct message
|
// Select the specific direct message
|
||||||
ReactFiber.find('.Viewer__Viewer___32BH-').setState({ selected: new Set([matchingNotification.message.messageID]) });
|
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 = [
|
const clickListeners = [
|
||||||
@@ -30,8 +34,6 @@ const clickListeners = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const registerClickListeners = () => {
|
const registerClickListeners = () => {
|
||||||
console.log("Registering click listeners...");
|
|
||||||
|
|
||||||
document.addEventListener('click', (e) => {
|
document.addEventListener('click', (e) => {
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user