diff --git a/src/background/index.ts b/src/background/index.ts index e75ac988..6bb7ba6b 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -57,7 +57,7 @@ browser.tabs.onUpdated.addListener((tabId: number, changInfo: Tabs.OnUpdatedChan || /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}`) - // || /https?:\/\/(www.)?bilibili.com\/video\/.*/.test(`${tab.url}`) + || /https?:\/\/(www.)?bilibili.com\/video\/.*/.test(`${tab.url}`) ) { browser.scripting.insertCSS({ css: resetCss, diff --git a/src/contentScripts/index.ts b/src/contentScripts/index.ts index e5097303..08fd3ac3 100644 --- a/src/contentScripts/index.ts +++ b/src/contentScripts/index.ts @@ -52,21 +52,21 @@ let app: AppType | null = null; setupApp(app) app.use(i18n).mount(root) } - // else if (/https?:\/\/(www.)?bilibili.com\/video\/.*/.test(currentUrl)) { - // const container = document.createElement('div') - // const root = document.createElement('div') - // const styleEl = document.createElement('link') - // styleEl.setAttribute('rel', 'stylesheet') - // styleEl.setAttribute('href', browser.runtime.getURL('dist/contentScripts/style.css')) - // container.id = 'bewly' - // container.appendChild(styleEl) - // container.appendChild(root) - // document.body.appendChild(container) + else if (/https?:\/\/(www.)?bilibili.com\/video\/.*/.test(currentUrl)) { + const container = document.createElement('div') + const root = document.createElement('div') + const styleEl = document.createElement('link') + styleEl.setAttribute('rel', 'stylesheet') + styleEl.setAttribute('href', browser.runtime.getURL('dist/contentScripts/style.css')) + container.id = 'bewly' + container.appendChild(styleEl) + container.appendChild(root) + document.body.appendChild(container) - // const app = createApp(App) - // setupApp(app) - // app.use(i18n).mount(root) - // } + const app = createApp(App) + setupApp(app) + app.use(i18n).mount(root) + } })() export default app as AppType diff --git a/src/contentScripts/views/Video/Video.vue b/src/contentScripts/views/Video/Video.vue index 1930e100..9dece27c 100644 --- a/src/contentScripts/views/Video/Video.vue +++ b/src/contentScripts/views/Video/Video.vue @@ -66,8 +66,14 @@ async function getVideoInfo() { const url = location.href // url.match(/video\/[0-9a-zA-Z]*/) = ['video/BV1vx4y1V7VD/', index: 25, input: 'https://www.bilibili.com/video/BV1vx4y1V7VD/', groups: undefined] // url.match(/video\/[0-9a-zA-Z]*/)[0] = 'video/BV1vx4y1V7VD/' - const bvid = url.match(/video\/[0-9a-zA-Z]*\/?/)![0].split('/')[1] - const res = await browser.runtime.sendMessage({ contentScriptQuery: 'getVideoInfo', bvid }) + const videoId = url.match(/video\/[0-9a-zA-Z]*\/?/)![0].split('/')[1] + const isBV = videoId.startsWith('BV') + + let res + if (isBV) + res = await browser.runtime.sendMessage({ contentScriptQuery: 'getVideoInfo', videoId }) + else + res = await browser.runtime.sendMessage({ contentScriptQuery: 'getVideoInfo', aid: videoId.replace('av', '') }) if (res.code === 0) { Object.assign(videoInfo, res.data.View) Object.assign(userCardInfo, res.data.Card)