msr-mod/public/background.js
Astrian Zheng 153988c35a
Some checks failed
构建扩展程序 / 构建扩展程序 (push) Successful in 51s
构建扩展程序 / 发布至 Chrome 应用商店 (push) Failing after 26s
fix: update webRequest listener to use browser API and adjust URL for fontset API
2025-05-29 07:41:08 +10:00

37 lines
1.1 KiB
JavaScript

console.log("aaaa")
browser.webRequest.onBeforeRequest.addListener(
async (details) => {
console.log(
'onBeforeRequest MAIN_FRAME:',
details.url,
details.type,
details.frameId,
details.tabId,
)
console.log('recived request for fontset api, redirecting to index.html')
const pref = await browser.storage.sync.get('preferences')
if (pref === undefined || pref.preferences === undefined || pref.preferences.autoRedirect === undefined || pref.preferences.autoRedirect === true) {
const isChrome = typeof browser.runtime.getBrowserInfo === 'undefined';
if (isChrome) {
browser.tabs.create({ url: browser.runtime.getURL('index.html') })
browser.tabs.remove(details.tabId)
} else {
// Firefox: 直接在当前标签页导航
browser.tabs.update(details.tabId, { url: browser.runtime.getURL('index.html') })
}
}
},
{ urls: ['https://monster-siren.hypergryph.com/api/fontset'] },
)
// 兼容新旧版本的 API
const actionAPI = browser.action || browser.browserAction;
if (actionAPI) {
actionAPI.onClicked.addListener(() => {
browser.tabs.create({ url: browser.runtime.getURL('index.html') })
})
}