From ebd78dcae44f746a2dc1a13eb8e732b1df9ed9d4 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Sat, 24 May 2025 08:56:16 +1000 Subject: [PATCH] feat: add redirection from MSR homepage to extension page --- package.json | 4 +++- public/background.js | 13 +++++++++++ public/content.js | 3 --- public/manifest.json | 10 ++++++--- src/components/HelloWorld.vue | 41 ----------------------------------- src/main.ts | 30 ++++++++++++++++++++++--- vite.config.ts | 8 +++---- 7 files changed, 54 insertions(+), 55 deletions(-) create mode 100644 public/background.js delete mode 100644 src/components/HelloWorld.vue diff --git a/package.json b/package.json index 45ec998..6cc1458 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,9 @@ "build": "vue-tsc -b && vite build && cp -r public/* dist/", "build:watch": "vite build --watch", "preview": "vite preview", - "lint": "biome format --write ." + "lint": "biome format --write .", + "quality-check": "biome ci", + "qc": "npm run quality-check" }, "dependencies": { "@tailwindcss/vite": "^4.1.7", diff --git a/public/background.js b/public/background.js new file mode 100644 index 0000000..ec6b2a2 --- /dev/null +++ b/public/background.js @@ -0,0 +1,13 @@ +console.log("background.js loaded 55555") + +chrome.webRequest.onBeforeRequest.addListener( + function(details) { + console.log("onBeforeRequest MAIN_FRAME:", details.url, details.type, details.frameId, details.tabId) + if (details.url === "https://monster-siren.hypergryph.com/manifest.json" && details.type === "other" && details.frameId === 0) { + console.log("onBeforeRequest - REDIRECTING MAIN_FRAME") + chrome.tabs.create({ url: chrome.runtime.getURL("index.html") }) + chrome.tabs.remove(details.tabId) + } + }, + { urls: ["https://monster-siren.hypergryph.com/manifest.json"] } +) \ No newline at end of file diff --git a/public/content.js b/public/content.js index 4f26e78..e69de29 100644 --- a/public/content.js +++ b/public/content.js @@ -1,3 +0,0 @@ -// redirect to extension's index.html -const extensonUrl = chrome.extension.getURL('index.html') -const url = window.location.href diff --git a/public/manifest.json b/public/manifest.json index 6bdff86..1d6fe3b 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -10,10 +10,14 @@ "run_at": "document_end" } ], - "permissions": ["webRequest", "webRequestBlocking"], + "host_permissions": ["https://monster-siren.hypergryph.com/*"], "icons": { "16": "vite.svg", "48": "vite.svg", "128": "vite.svg" - } -} + }, + "background": { + "service_worker": "background.js" + }, + "permissions": ["tabs", "webRequest"] +} \ No newline at end of file diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue deleted file mode 100644 index b58e52b..0000000 --- a/src/components/HelloWorld.vue +++ /dev/null @@ -1,41 +0,0 @@ - - - - - diff --git a/src/main.ts b/src/main.ts index 2425c0f..179561a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,29 @@ -import { createApp } from 'vue' -import './style.css' -import App from './App.vue' +import { createApp } from 'vue'; +import './style.css'; +import App from './App.vue'; + +// unregister the service worker +if ('serviceWorker' in navigator) { + navigator.serviceWorker.getRegistrations().then(function(registrations) { + for(let registration of registrations) { + // 可以根据 scope 判断是否是目标网站的 Service Worker + console.log('Unregistering service worker:', registration.scope) + registration.unregister() + } + }) +} + +// Replace the body content with the Vue app +document.getElementsByTagName('html')[0].innerHTML = ` + + + + MSR Mod + + +
+ +`; createApp(App).mount('#app') + diff --git a/vite.config.ts b/vite.config.ts index 3638531..3633fad 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' +import { defineConfig } from 'vite' // https://vite.dev/config/ export default defineConfig({ @@ -14,9 +14,9 @@ export default defineConfig({ // // options: resolve(__dirname, 'options.html'), // If you have an options page // }, output: { - entryFileNames: `assets/[name].js`, - chunkFileNames: `assets/[name].js`, - assetFileNames: `assets/[name].[ext]`, + entryFileNames: 'assets/[name].js', + chunkFileNames: 'assets/[name].js', + assetFileNames: 'assets/[name].[ext]', // Optional: to disable hashing for specific assets if needed // entryFileNames: `assets/[name].js`, // chunkFileNames: `assets/[name].js`,