Commit d643e4618d
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/extrepo/ExtensionRepos.vue +34 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <script setup lang="ts"> |
| 2 | 2 | import { refDebounced } from '@vueuse/core' |
| 3 | import { computed, onUnmounted, ref } from 'vue' | |
| 3 | import { computed, nextTick, onUnmounted, ref, watch } from 'vue' | |
| 4 | 4 | import { SEARCH_DEBOUNCE_MS, STATUS_TICK_MS } from './constants' |
| 5 | 5 | import { escapeHtml, stripHtml } from './helpers' |
| 6 | 6 | import { mangayomiCopyValue } from './install' |
| @@ -40,6 +40,39 @@ onUnmounted(() => { | ||
| 40 | 40 | if (tickTimer) clearTimeout(tickTimer) |
| 41 | 41 | }) |
| 42 | 42 | |
| 43 | let lastCorrectedHash: string | null = null | |
| 44 | ||
| 45 | function correctAnchorScroll() { | |
| 46 | if (typeof window === 'undefined') return | |
| 47 | const hash = window.location.hash | |
| 48 | if (!hash || hash.length < 2 || hash === lastCorrectedHash) return | |
| 49 | const raw = hash.slice(1) | |
| 50 | let id = raw | |
| 51 | try { | |
| 52 | id = decodeURIComponent(raw) | |
| 53 | } catch { | |
| 54 | } | |
| 55 | const target = document.getElementById(id) ?? document.getElementById(raw) | |
| 56 | if (!target) return | |
| 57 | lastCorrectedHash = hash | |
| 58 | void nextTick(() => { | |
| 59 | requestAnimationFrame(() => { | |
| 60 | requestAnimationFrame(() => { | |
| 61 | const navBar = document.querySelector<HTMLElement>('.VPNavBar') | |
| 62 | const navOffset = navBar ? navBar.offsetHeight : 0 | |
| 63 | window.scrollTo({ | |
| 64 | top: target.getBoundingClientRect().top + window.scrollY - navOffset, | |
| 65 | behavior: 'auto' | |
| 66 | }) | |
| 67 | }) | |
| 68 | }) | |
| 69 | }) | |
| 70 | } | |
| 71 | ||
| 72 | watch(loading, (value, oldValue) => { | |
| 73 | if (oldValue && !value) correctAnchorScroll() | |
| 74 | }) | |
| 75 | ||
| 43 | 76 | async function onStatusClick() { |
| 44 | 77 | if (loading.value || refreshing.value) return |
| 45 | 78 | if (loadFailed.value) { |