mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
fix: insertCSS not working in mv3
This commit is contained in:
@@ -52,10 +52,12 @@ onMessage('get-current-tab', async () => {
|
||||
|
||||
// preinsert css
|
||||
browser.tabs.onUpdated.addListener((tabId: number, changInfo: Tabs.OnUpdatedChangeInfoType, tab: Tabs.Tab) => {
|
||||
if (/https?:\/\/bilibili.com\/?$/.test(`${tab.url}`)
|
||||
|| /https?:\/\/www.bilibili.com\/?$/.test(`${tab.url}`)
|
||||
|| /https?:\/\/bilibili.com\/\?spm_id_from=.*/.test(`${tab.url}`)
|
||||
|| /https?:\/\/www.bilibili.com\/\?spm_id_from=(.)*/.test(`${tab.url}`)) {
|
||||
if (
|
||||
/https?:\/\/bilibili.com\/?$/.test(`${tab.url}`)
|
||||
|| /https?:\/\/www.bilibili.com\/?$/.test(`${tab.url}`)
|
||||
|| /https?:\/\/bilibili.com\/\?spm_id_from=.*/.test(`${tab.url}`)
|
||||
|| /https?:\/\/www.bilibili.com\/\?spm_id_from=(.)*/.test(`${tab.url}`)
|
||||
) {
|
||||
if (changInfo.status === 'loading') {
|
||||
const css = `
|
||||
body {
|
||||
@@ -66,16 +68,16 @@ browser.tabs.onUpdated.addListener((tabId: number, changInfo: Tabs.OnUpdatedChan
|
||||
}
|
||||
`
|
||||
|
||||
browser.scripting.insertCSS(tabId, {
|
||||
css: css,
|
||||
runAt: 'document_start',
|
||||
target: {tabId: tabId},
|
||||
matchAboutBlank: true,
|
||||
browser.scripting.insertCSS({
|
||||
css,
|
||||
target: {
|
||||
tabId,
|
||||
},
|
||||
})
|
||||
|
||||
// If it not a macOS, we will inject CSS to design the scrollbar
|
||||
if (!navigator.userAgent.includes('Mac OS X')) {
|
||||
browser.scripting.insertCSS(tabId, {
|
||||
browser.scripting.insertCSS({
|
||||
css: `
|
||||
::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
@@ -94,13 +96,12 @@ browser.tabs.onUpdated.addListener((tabId: number, changInfo: Tabs.OnUpdatedChan
|
||||
border-radius: 20px;
|
||||
}
|
||||
`,
|
||||
runAt: 'document_start',
|
||||
target: {tabId: tabId},
|
||||
matchAboutBlank: true,
|
||||
// runAt: 'document_start',
|
||||
target: { tabId },
|
||||
// matchAboutBlank: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
else if (changInfo.status === 'complete') {
|
||||
const css = `
|
||||
body {
|
||||
@@ -110,11 +111,9 @@ browser.tabs.onUpdated.addListener((tabId: number, changInfo: Tabs.OnUpdatedChan
|
||||
}
|
||||
`
|
||||
|
||||
browser.scripting.insertCSS(tabId, {
|
||||
css: css,
|
||||
runAt: 'document_start',
|
||||
target: {tabId: tabId},
|
||||
matchAboutBlank: true,
|
||||
browser.scripting.insertCSS({
|
||||
css,
|
||||
target: { tabId },
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ export async function getManifest() {
|
||||
{
|
||||
matches: ['http://www.bilibili.com/*', 'https://www.bilibili.com/*'],
|
||||
js: ['./dist/contentScripts/index.global.js'],
|
||||
run_at: 'document_start',
|
||||
match_about_blank: true,
|
||||
},
|
||||
],
|
||||
web_accessible_resources: [
|
||||
|
||||
Reference in New Issue
Block a user