fix: resolve 网页链接打开无法跳转到视频页,并且主题失效 #166

This commit is contained in:
Hakadao
2024-01-14 23:48:09 +08:00
parent 85c9fd7c76
commit 10bfc7cdbc
2 changed files with 19 additions and 1 deletions

View File

@@ -32,6 +32,8 @@ function isSupportedPages() {
|| /https?:\/\/www.bilibili.com\/index.html$/.test(currentUrl)
|| /https?:\/\/bilibili.com\/\?spm_id_from=.*/.test(currentUrl)
|| /https?:\/\/www.bilibili.com\/\?spm_id_from=(.)*/.test(currentUrl)
// fix #166 https://github.com/hakadao/BewlyBewly/issues/166
|| /https?:\/\/www.bilibili.com\/\?bvid=.*$/.test(currentUrl)
// video page
|| /https?:\/\/(www.)?bilibili.com\/video\/.*/.test(currentUrl)

View File

@@ -12,7 +12,7 @@ import WatchLater from './WatchLater/WatchLater.vue'
import Favorites from './Favorites/Favorites.vue'
import { accessKey, settings } from '~/logic'
import { AppPage, LanguageType } from '~/enums/appEnums'
import { getUserID, hexToRGBA, isHomePage, smoothScrollToTop } from '~/utils/main'
import { getUserID, hexToRGBA, isHomePage, openLinkToNewTab, smoothScrollToTop } from '~/utils/main'
import emitter from '~/utils/mitt'
const activatedPage = ref<AppPage>(settings.value.dockItemVisibilityList.find(e => e.visible === true)?.page ?? AppPage.Home)
@@ -91,6 +91,8 @@ watch(() => settings.value.adaptToOtherPageStyles, () => {
})
onMounted(() => {
openVideoPageIfBvidExists()
if (isHomePage()) {
// Force overwrite Bilibili Evolved body tag & html tag background color
document.body.style.setProperty('background-color', 'unset', 'important')
@@ -237,6 +239,20 @@ function handleOsScroll() {
topBarRef.value?.handleScroll()
}
// fix #166 https://github.com/hakadao/BewlyBewly/issues/166
function openVideoPageIfBvidExists() {
// Assume the URL is https://www.bilibili.com/?bvid=BV1be41127ft&spm_id_from=333.788.seo.out
// Get the current URL's query string
const queryString = window.location.search
// Create a URLSearchParams instance
const urlParams = new URLSearchParams(queryString)
const bvid = urlParams.get('bvid')
if (bvid)
window.open(`https://www.bilibili.com/video/${bvid}`, '_self')
}
provide('handleBackToTop', handleBackToTop)
provide('handleRefresh', handleRefresh)
provide('activatedPage', activatedPage)