Closed josephj closed 1 month ago
https://poe.com/s/sTMDIx1Iwl6ZJqKc9vCO
import { Storage } from "@plasmohq/storage"; const storage = new Storage(); chrome.runtime.onInstalled.addListener(async () => { const overrideNewTab = await storage.get("overrideNewTab"); if (overrideNewTab === undefined) { await storage.set("overrideNewTab", true); } }); chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => { if (message.type === "UPDATE_NEW_TAB_OVERRIDE") { await handleNewTabOverride(message.value); } }); async function handleNewTabOverride(override: boolean) { if (override) { chrome.tabs.onCreated.addListener(onTabCreated); } else { chrome.tabs.onCreated.removeListener(onTabCreated); } } function onTabCreated(tab: chrome.tabs.Tab) { if (tab.pendingUrl === "chrome://newtab/" || tab.url === "chrome://newtab/") { chrome.tabs.update(tab.id, { url: chrome.runtime.getURL("index.html") }); } } // 初始化 storage.get("overrideNewTab").then(handleNewTabOverride);
https://poe.com/s/sTMDIx1Iwl6ZJqKc9vCO