feat: add redirection from MSR homepage to extension page

This commit is contained in:
Astrian Zheng 2025-05-24 08:56:16 +10:00
parent a769bbf57e
commit ebd78dcae4
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA
7 changed files with 54 additions and 55 deletions

View File

@ -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",

13
public/background.js Normal file
View File

@ -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"] }
)

View File

@ -1,3 +0,0 @@
// redirect to extension's index.html
const extensonUrl = chrome.extension.getURL('index.html')
const url = window.location.href

View File

@ -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"]
}

View File

@ -1,41 +0,0 @@
<script setup lang="ts">
import { ref } from 'vue'
defineProps<{ msg: string }>()
const count = ref(0)
</script>
<template>
<h1>{{ msg }}</h1>
<div class="card">
<button type="button" @click="count++">count is {{ count }}</button>
<p>
Edit
<code>components/HelloWorld.vue</code> to test HMR
</p>
</div>
<p>
Check out
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
>create-vue</a
>, the official Vue + Vite starter
</p>
<p>
Learn more about IDE Support for Vue in the
<a
href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support"
target="_blank"
>Vue Docs Scaling up Guide</a
>.
</p>
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
</template>
<style scoped>
.read-the-docs {
color: #888;
}
</style>

View File

@ -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 = `
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MSR Mod</title>
</head>
<body>
<div id="app"></div>
</body>
`;
createApp(App).mount('#app')

View File

@ -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`,