mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
feat: remember last opened page when returning to homepage
This commit is contained in:
@@ -34,8 +34,6 @@ function isSupportedPages(): boolean {
|
||||
if (
|
||||
// homepage
|
||||
isHomePage()
|
||||
// fix #166 https://github.com/hakadao/BewlyBewly/issues/166
|
||||
|| /https?:\/\/www\.bilibili\.com\/\?bvid=.*$/.test(currentUrl)
|
||||
|
||||
// video page
|
||||
|| /https?:\/\/(?:www\.)?bilibili\.com\/(?:video|list)\/.*/.test(currentUrl)
|
||||
|
||||
@@ -15,7 +15,16 @@ import { setupNecessarySettingsWatchers } from './necessarySettingsWatchers'
|
||||
const { isDark } = useDark()
|
||||
const [showSettings, toggleSettings] = useToggle(false)
|
||||
|
||||
const activatedPage = ref<AppPage>(settings.value.dockItemVisibilityList.find(e => e.visible === true)?.page ?? AppPage.Home)
|
||||
// Get the 'page' query parameter from the URL
|
||||
function getPageParam(): AppPage | null {
|
||||
const urlParams = new URLSearchParams(window.location.search)
|
||||
const result = urlParams.get('page') as AppPage | null
|
||||
if (result && Object.values(AppPage).includes(result))
|
||||
return result
|
||||
return null
|
||||
}
|
||||
|
||||
const activatedPage = ref<AppPage>(getPageParam() || (settings.value.dockItemVisibilityList.find(e => e.visible === true)?.page || AppPage.Home))
|
||||
const pages = {
|
||||
[AppPage.Home]: defineAsyncComponent(() => import('./Home/Home.vue')),
|
||||
[AppPage.Search]: defineAsyncComponent(() => import('./Search/Search.vue')),
|
||||
@@ -53,6 +62,10 @@ const showBewlyPage = computed((): boolean => {
|
||||
watch(
|
||||
() => activatedPage.value,
|
||||
() => {
|
||||
// Update the URL query parameter when activatedPage changes
|
||||
const url = new URL(window.location.href)
|
||||
url.searchParams.set('page', activatedPage.value)
|
||||
window.history.replaceState({}, '', url.toString())
|
||||
const osInstance = scrollbarRef.value.osInstance()
|
||||
osInstance.elements().viewport.scrollTop = 0
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user