Commit a66ad69b50

a66ad69b5009c3d35464518c07f33994d5a7d686

parent: e8f7c44652

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-10-12 14:09 UTC

a

Layout: unified · split

docs/.vitepress/configs/markdown/extRepoPlugin.ts +55 −18
@@ -40,20 +40,26 @@ interface ParsedRepoEntry {
4040 builds?: ParsedRepoBuild[]
4141}
4242
43import { parseExtRepoAttrs } from '../../../ext/extensionRepos/attrs'
44
4345// Parser
4446
45function parseAttrs(info: string): Record<string, string> {
46 const match = info.match(/\{([^}]*)\}/)
47 if (!match) return {}
48 const attrs: Record<string, string> = {}
49 for (const pair of match[1].split(/\s+/).filter(Boolean)) {
50 const [key, value] = pair.split('=')
51 if (key && value) attrs[key] = value.replace(/^["']|["']$/g, '')
52 }
53 return attrs
47function isManualOrder(attrs: Record<string, string>): boolean {
48 if (attrs.order !== undefined) return attrs.order === 'manual'
49 const manual = attrs.manual?.toLowerCase()
50 return manual === 'true' || manual === '1'
5451}
5552
56const FIELD_KEYS = new Set(['url', 'src', 'raw', 'note', 'manga', 'anime', 'novel', 'data'])
53const FIELD_KEYS = new Set([
54 'url',
55 'src',
56 'raw',
57 'note',
58 'manga',
59 'anime',
60 'novel',
61 'data'
62])
5763
5864function parseEntries(bodyLines: string[]): ParsedRepoEntry[] {
5965 const entries: ParsedRepoEntry[] = []
@@ -88,7 +94,19 @@ function parseEntries(bodyLines: string[]): ParsedRepoEntry[] {
8894 if (key === 'raw') currentBuild.raw = value
8995 continue
9096 }
91 if (FIELD_KEYS.has(key)) current[key as 'url' | 'src' | 'raw' | 'note' | 'manga' | 'anime' | 'novel' | 'data'] = value
97 if (FIELD_KEYS.has(key)) {
98 current[
99 key as
100 | 'url'
101 | 'src'
102 | 'raw'
103 | 'note'
104 | 'manga'
105 | 'anime'
106 | 'novel'
107 | 'data'
108 ] = value
109 }
92110 }
93111 }
94112 if (current) entries.push(current)
@@ -101,13 +119,21 @@ function nameMarkdown(entry: ParsedRepoEntry): string {
101119 return entry.src ? `${label} [:src:](${entry.src})` : label
102120}
103121
104function buildVariants(entry: ParsedRepoEntry): ParsedRepoVariant[] | undefined {
105 const typeCount = [entry.manga, entry.anime, entry.novel].filter(Boolean).length
122function buildVariants(
123 entry: ParsedRepoEntry
124): ParsedRepoVariant[] | undefined {
125 const typeCount =
126 [entry.manga, entry.anime, entry.novel].filter(Boolean).length
106127 if (typeCount === 0) return undefined
107128
108129 const variants: ParsedRepoVariant[] = []
109130 if (typeCount > 1) {
110 variants.push({ label: 'All-in-One', mangaUrl: entry.manga, animeUrl: entry.anime, novelUrl: entry.novel })
131 variants.push({
132 label: 'All-in-One',
133 mangaUrl: entry.manga,
134 animeUrl: entry.anime,
135 novelUrl: entry.novel
136 })
111137 }
112138 if (entry.manga) variants.push({ label: 'Manga', mangaUrl: entry.manga })
113139 if (entry.anime) variants.push({ label: 'Anime', animeUrl: entry.anime })
@@ -149,7 +175,10 @@ export function extRepoPlugin(md: MarkdownIt): void {
149175 if (p < m && state.sCount[nextLine] < state.blkIndent) break
150176
151177 let cnt = 0
152 while (p < m && state.src[p] === MARKER) { p++; cnt++ }
178 while (p < m && state.src[p] === MARKER) {
179 p++
180 cnt++
181 }
153182 if (cnt >= markerCount && state.src.slice(p, m).trim() === '') {
154183 found = true
155184 break
@@ -162,9 +191,10 @@ export function extRepoPlugin(md: MarkdownIt): void {
162191 bodyLines.push(state.src.slice(state.bMarks[i], state.eMarks[i]))
163192 }
164193
165 const attrs = parseAttrs(params)
194 const attrs = parseExtRepoAttrs(params)
166195 const scheme = attrs.scheme || 'mihon'
167196 const from = attrs.from
197 const manualAttr = isManualOrder(attrs) ? ' manual' : ''
168198
169199 const rows: ParsedRepoRow[] = []
170200 for (const entry of parseEntries(bodyLines)) {
@@ -180,7 +210,13 @@ export function extRepoPlugin(md: MarkdownIt): void {
180210 .filter((b): b is Required<ParsedRepoBuild> => Boolean(b.raw))
181211 .map(b => ({ label: b.label, mangaUrl: b.raw }))
182212 if (groupVariants.length) {
183 rows.push({ name, indexUrl: groupVariants[0].mangaUrl!, note, data: entry.data, variants: groupVariants })
213 rows.push({
214 name,
215 indexUrl: groupVariants[0].mangaUrl!,
216 note,
217 data: entry.data,
218 variants: groupVariants
219 })
184220 }
185221 continue
186222 }
@@ -210,7 +246,8 @@ export function extRepoPlugin(md: MarkdownIt): void {
210246
211247 const token = state.push('html_block', '', 0)
212248 token.map = [startLine, nextLine]
213 token.content = `<ExtensionRepos scheme="${scheme}"${fromAttr} :repos='${reposJson}' />\n`
249 token.content =
250 `<ExtensionRepos scheme="${scheme}"${fromAttr}${manualAttr} :repos='${reposJson}' />\n`
214251
215252 state.line = found ? nextLine + 1 : nextLine
216253 return true
docs/.vitepress/theme/components/extrepo/ContentTypeFilter.vue deleted −179
@@ -1,179 +0,0 @@
1<script setup lang="ts">
2import { NuInputHighlight, NuVerticalTransition } from '@nolebase/ui'
3import { computed, onMounted, onUnmounted, ref } from 'vue'
4import { contentTypeLabel } from './helpers'
5import MenuHelp from '../settings/MenuHelp.vue'
6import MenuTitle from '../settings/MenuTitle.vue'
7
8const props = withDefaults(defineProps<{
9 // Excluded type values; empty means nothing is excluded, so everything is shown.
10 modelValue: Set<string>
11 availableTypes: string[]
12 title?: string
13 icon?: string
14 helpText?: string
15}>(), {
16 title: 'Content Type',
17 icon: 'i-lucide:tags',
18 helpText: 'Shows or hides specific content types. Unchecking a type hides matching entries from the list.'
19})
20
21const emit = defineEmits<{
22 'update:modelValue': [value: Set<string>]
23}>()
24
25const rootRef = ref<HTMLElement>()
26const open = ref(false)
27const menuTitleElementRef = ref<HTMLDivElement>()
28const isMenuHelpPoppedUp = ref(false)
29
30const selectedCount = computed(() => props.availableTypes.length - props.modelValue.size)
31const summaryLabel = computed(() => {
32 if (props.modelValue.size === 0) return 'All types'
33 return `${selectedCount.value} of ${props.availableTypes.length}`
34})
35
36function isChecked(type: string): boolean {
37 return !props.modelValue.has(type)
38}
39
40function toggle(type: string) {
41 const next = new Set(props.modelValue)
42 if (next.has(type)) next.delete(type)
43 else next.add(type)
44 emit('update:modelValue', next)
45}
46
47function onDocClick(e: MouseEvent) {
48 if (rootRef.value && !rootRef.value.contains(e.target as Node)) open.value = false
49}
50
51onMounted(() => document.addEventListener('click', onDocClick, true))
52onUnmounted(() => document.removeEventListener('click', onDocClick, true))
53</script>
54
55<template>
56 <div ref="rootRef" class="ext-ctype-select" :class="{ 'ext-ctype-select--open': open }">
57 <div ref="menuTitleElementRef" relative flex items-center mb-2>
58 <MenuTitle :title="title" :aria-label="title" flex="1" pr-4>
59 <template #icon>
60 <span :class="icon" mr-1 aria-hidden="true" />
61 </template>
62 </MenuTitle>
63 <MenuHelp
64 v-model:is-popped-up="isMenuHelpPoppedUp"
65 :menu-title-element-ref="menuTitleElementRef"
66 >
67 <h4 text-md mb-1 font-semibold>{{ title }}</h4>
68 <p text="sm" mb-2 max-w-100>
69 {{ helpText }}
70 </p>
71 </MenuHelp>
72 </div>
73 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
74 <button
75 type="button"
76 class="ext-ctype-trigger"
77 aria-haspopup="listbox"
78 :aria-expanded="open"
79 @click="open = !open"
80 >
81 <span class="ext-ctype-label">{{ summaryLabel }}</span>
82 <span class="ext-ctype-chevron i-lucide:chevron-down" :class="{ 'ext-ctype-chevron--open': open }" />
83 </button>
84
85 <NuVerticalTransition :duration="200">
86 <div v-show="open" class="ext-ctype-options" role="listbox">
87 <label v-for="type in availableTypes" :key="type" class="ext-ctype-option">
88 <input type="checkbox" :checked="isChecked(type)" @change="toggle(type)" />
89 <span class="ext-ctype-option-label">{{ contentTypeLabel(type) }}</span>
90 </label>
91 </div>
92 </NuVerticalTransition>
93 </NuInputHighlight>
94 </div>
95</template>
96
97<style scoped>
98.ext-ctype-select {
99 position: relative;
100}
101
102.ext-ctype-trigger {
103 display: flex;
104 align-items: center;
105 gap: 8px;
106 width: 100%;
107 min-height: 44px;
108 padding: 7px 10px;
109 border-radius: 8px;
110 border: 2px solid var(--vp-c-divider);
111 background: var(--wk-c-menu-bg);
112 color: var(--vp-c-text-1);
113 font-size: 13px;
114 cursor: pointer;
115 transition: border-color 0.15s, background-color 0.15s;
116}
117
118.ext-ctype-trigger:hover,
119.ext-ctype-select--open .ext-ctype-trigger {
120 border-color: var(--vp-c-brand-1);
121}
122
123.ext-ctype-label {
124 flex: 1;
125 text-align: left;
126}
127
128.ext-ctype-chevron {
129 flex-shrink: 0;
130 color: var(--vp-c-text-2);
131 transition: transform 0.2s ease;
132}
133
134.ext-ctype-chevron--open {
135 transform: rotate(180deg);
136}
137
138.ext-ctype-options {
139 margin-top: 6px;
140 max-height: 240px;
141 overflow-y: auto;
142 overscroll-behavior: contain;
143 display: flex;
144 flex-direction: column;
145 gap: 2px;
146 padding: 4px;
147 border-radius: 8px;
148 border: 1px solid var(--vp-c-divider);
149 background: var(--vp-c-bg-elv);
150 box-shadow: var(--vp-shadow-2, 0 4px 16px rgba(0, 0, 0, 0.2));
151}
152
153.ext-ctype-option {
154 display: flex;
155 align-items: center;
156 gap: 8px;
157 padding: 5px 8px;
158 border-radius: 8px;
159 cursor: pointer;
160 color: var(--vp-c-text-1);
161 font-size: 13px;
162 width: 100%;
163 transition: background-color 0.15s;
164}
165
166.ext-ctype-option:hover {
167 background-color: var(--vp-c-bg-soft);
168}
169
170.ext-ctype-option input {
171 flex-shrink: 0;
172 accent-color: var(--vp-c-brand-1);
173}
174
175.ext-ctype-option-label {
176 flex: 1;
177 min-width: 0;
178}
179</style>
docs/.vitepress/theme/components/extrepo/ExtensionRepos.vue +170 −89
@@ -1,54 +1,124 @@
11<script setup lang="ts">
2import { computed, ref } from 'vue'
3import { data } from '../../../../ext/extensionRepos.data'
4import { escapeHtml, langLabel, stripHtml } from './helpers'
2import { refDebounced } from '@vueuse/core'
3import { computed, onUnmounted, ref } from 'vue'
4import { SEARCH_DEBOUNCE_MS, STATUS_TICK_MS } from './constants'
5import { escapeHtml, stripHtml } from './helpers'
56import { mangayomiCopyValue } from './install'
67import RepoRow from './RepoRow.vue'
78import SettingsMenu from './SettingsMenu.vue'
89import SiteGrid from './SiteGrid.vue'
910import type { MatchedSite, RatingFilter, Repo } from './types'
11import { indexSites, useRepoFilter } from './useRepoFilter'
12import { provideRepoStore } from './useRepoStore'
1013import { provideTooltip } from './useTooltip'
1114
1215const { tooltip } = provideTooltip()
1316
14const repoData = data.sites
15const soraAuthors = data.soraAuthors
16const echoAuthors = data.echoAuthors
17const repoLists = data.repoLists ?? {}
18
1917const props = defineProps<{
2018 repos: Repo[]
2119 scheme: string
2220 from?: string
21 manual?: boolean
2322}>()
2423
24const {
25 store,
26 loading,
27 refreshing,
28 refreshFailed,
29 loadFailed,
30 updatedAt,
31 loadMs,
32 refresh,
33 retry
34} = provideRepoStore(props.scheme)
35
36const ticked = ref(false)
37let tickTimer: ReturnType<typeof setTimeout> | undefined
38
39onUnmounted(() => {
40 if (tickTimer) clearTimeout(tickTimer)
41})
42
43async function onStatusClick() {
44 if (loading.value || refreshing.value) return
45 if (loadFailed.value) {
46 await retry()
47 return
48 }
49 ticked.value = false
50 if (tickTimer) clearTimeout(tickTimer)
51 await refresh()
52 if (!refreshFailed.value) {
53 ticked.value = true
54 tickTimer = setTimeout(() => {
55 ticked.value = false
56 }, STATUS_TICK_MS)
57 }
58}
59
60const busy = computed(() => loading.value || refreshing.value)
61const failed = computed(() => loadFailed.value || refreshFailed.value)
62
63const statusIcon = computed(() => {
64 if (busy.value) return 'i-lucide:loader-circle'
65 if (failed.value) return 'i-lucide:x'
66 if (ticked.value) return 'i-lucide:check'
67 return 'i-lucide:refresh-cw'
68})
69
70const statusTitle = computed(() => {
71 const ms = loadMs.value !== null ? ` (${loadMs.value}ms)` : ''
72 if (loading.value) return `Loading sites…${ms}`
73 if (refreshing.value) return 'Refreshing…'
74 if (failed.value) return `Loading failed${ms} — click to retry`
75 if (ticked.value) return 'Database refreshed'
76 if (updatedAt.value) {
77 return `Database refreshed at ${new Date(updatedAt.value).toLocaleTimeString()}`
78 }
79 return `Refresh data${ms}`
80})
81
82const repoData = computed(() => store.value?.sites ?? {})
83const echoAuthors = computed(() => store.value?.echoAuthors ?? {})
84const repoLists = computed(() => store.value?.repoLists ?? {})
85
2586const baseRepos = computed<Repo[]>(() => {
26 const list = props.from ? repoLists[props.from] ?? [] : []
87 const list = props.from ? repoLists.value[props.from] ?? [] : []
2788 const auto: Repo[] = list.map(entry => ({
2889 name: entry.repoUrl
29 ? `<a href="${entry.repoUrl}" target="_blank" rel="noopener noreferrer">${escapeHtml(entry.label)}</a>`
90 ? `<a href="${entry.repoUrl}" target="_blank" rel="noopener noreferrer">${
91 escapeHtml(entry.label)
92 }</a>`
3093 : escapeHtml(entry.label),
3194 indexUrl: entry.indexUrl,
3295 repoName: entry.label,
3396 repoUrl: entry.repoUrl
3497 }))
3598 const manualByUrl = new Map(props.repos.map(repo => [repo.indexUrl, repo]))
36 const merged = [...auto.filter(repo => !manualByUrl.has(repo.indexUrl)), ...props.repos]
37 merged.sort((a, b) => stripHtml(a.name).localeCompare(stripHtml(b.name)))
99 const merged = [
100 ...auto.filter(repo => !manualByUrl.has(repo.indexUrl)),
101 ...props.repos
102 ]
103 if (!props.manual) {
104 merged.sort((a, b) => stripHtml(a.name).localeCompare(stripHtml(b.name)))
105 }
38106 return merged
39107})
40108
41109const resolvedRepos = computed<Repo[]>(() => {
42110 const result: Repo[] = []
43111 for (const repo of baseRepos.value) {
44 const authors = soraAuthors[repo.indexUrl] ?? echoAuthors[repo.indexUrl]
112 const authors = echoAuthors.value[repo.indexUrl]
45113 if (!authors?.length) {
46114 result.push(repo)
47115 continue
48116 }
49117 for (const author of authors) {
50118 const name = author.repoUrl
51 ? `<a href="${author.repoUrl}" target="_blank" rel="noopener noreferrer">${escapeHtml(author.label)}</a>`
119 ? `<a href="${author.repoUrl}" target="_blank" rel="noopener noreferrer">${
120 escapeHtml(author.label)
121 }</a>`
52122 : escapeHtml(author.label)
53123 result.push({ name, indexUrl: author.indexUrl, repoName: author.label })
54124 }
@@ -57,24 +127,22 @@ const resolvedRepos = computed<Repo[]>(() => {
57127})
58128
59129const query = ref('')
130const debouncedQuery = refDebounced(query, SEARCH_DEBOUNCE_MS)
60131const langFilter = ref('')
61132const ratingFilter = ref<RatingFilter>('all')
62133const contentTypeFilter = ref('')
63const excludedStreamTypes = ref<Set<string>>(new Set())
64const excludedQualities = ref<Set<string>>(new Set())
65134const showBroken = ref(false)
66135
67const allSites = computed<MatchedSite[]>(() => {
136const allSites = computed(() => {
68137 const sites: MatchedSite[] = []
69138 for (const repo of resolvedRepos.value) {
70139 if (repo.variants?.length) {
71 // search fix for variations of setup. (mangayomi and kotatsu)
72140 const sameRepoName = repo.repoName ? stripHtml(repo.name) : undefined
73141 for (const variant of repo.variants) {
74142 const url = mangayomiCopyValue(variant)
75143 if (!url) continue
76144 const repoName = sameRepoName ?? variant.label
77 for (const site of repoData[url]?.sites ?? []) {
145 for (const site of repoData.value[url]?.sites ?? []) {
78146 sites.push({ ...site, repoName })
79147 }
80148 }
@@ -82,62 +150,19 @@ const allSites = computed<MatchedSite[]>(() => {
82150 }
83151 const repoName = stripHtml(repo.name)
84152 const dataUrl = repo.data ?? repo.indexUrl
85 for (const site of repoData[dataUrl]?.sites ?? []) {
153 for (const site of repoData.value[dataUrl]?.sites ?? []) {
86154 sites.push({ ...site, repoName })
87155 }
88156 }
89 return sites
90})
91
92const availableContentTypes = computed(() => {
93 const types = new Set<string>()
94 for (const site of allSites.value) if (site.contentType) types.add(site.contentType)
95 return [...types].sort()
157 return indexSites(sites)
96158})
97const hasContentTypes = computed(() => availableContentTypes.value.length > 0)
98159
99const availableStreamTypes = computed(() => {
100 const types = new Set<string>()
101 for (const site of allSites.value) if (site.streamType) types.add(site.streamType)
102 return [...types].sort()
103})
104const hasStreamTypes = computed(() => availableStreamTypes.value.length > 0)
105
106const availableQualities = computed(() => {
107 const types = new Set<string>()
108 for (const site of allSites.value) if (site.quality) types.add(site.quality)
109 return [...types].sort()
110})
111const hasQualities = computed(() => availableQualities.value.length > 0)
112
113const hasRatings = computed(() => allSites.value.some(site => site.rating !== 'safe'))
114const hasSuggestive = computed(() => allSites.value.some(site => site.rating === 'suggestive'))
115const hasMultiLanguage = computed(() => allSites.value.some(site => site.lang.toLowerCase() === 'all'))
116const hasBroken = computed(() => allSites.value.some(site => site.isBroken))
117
118const availableLangs = computed(() => {
119 const codes = new Set(allSites.value.map(site => site.lang))
120 codes.delete('all')
121 return [...codes].sort((a, b) => langLabel(a).localeCompare(langLabel(b)))
122})
123
124const isFiltering = computed(() => {
125 return query.value.trim() !== '' || langFilter.value !== '' || ratingFilter.value !== 'all'
126 || contentTypeFilter.value !== '' || excludedStreamTypes.value.size > 0 || excludedQualities.value.size > 0
127})
128
129const filteredSites = computed(() => {
130 const q = query.value.trim().toLowerCase()
131 return allSites.value.filter(site => {
132 if (site.isBroken && !showBroken.value) return false
133 if (q && !site.name.toLowerCase().includes(q) && !site.url.toLowerCase().includes(q)) return false
134 if (langFilter.value && site.lang !== langFilter.value) return false
135 if (ratingFilter.value !== 'all' && site.rating !== ratingFilter.value) return false
136 if (contentTypeFilter.value && site.contentType !== contentTypeFilter.value) return false
137 if (site.streamType && excludedStreamTypes.value.has(site.streamType)) return false
138 if (site.quality && excludedQualities.value.has(site.quality)) return false
139 return true
140 })
160const { facets, isFiltering, filteredSites } = useRepoFilter(allSites, {
161 query: debouncedQuery,
162 langFilter,
163 ratingFilter,
164 contentTypeFilter,
165 showBroken
141166})
142167</script>
143168
@@ -148,24 +173,33 @@ const filteredSites = computed(() => {
148173 <span class="i-lucide:search" />
149174 <input v-model="query" type="text" placeholder="Search all sites…" />
150175 </div>
176 <button
177 type="button"
178 class="ext-status-btn"
179 :class="{
180 spinning: busy,
181 'is-failed': !busy && failed,
182 'is-ok': !busy && !failed && ticked
183 }"
184 :disabled="busy"
185 :title="statusTitle"
186 aria-label="Reload site data"
187 @click="onStatusClick"
188 >
189 <span :class="statusIcon" />
190 </button>
151191 <SettingsMenu
152192 v-model:lang-filter="langFilter"
153193 v-model:rating-filter="ratingFilter"
154194 v-model:content-type-filter="contentTypeFilter"
155 v-model:stream-type-filter="excludedStreamTypes"
156 v-model:quality-filter="excludedQualities"
157195 v-model:show-broken="showBroken"
158 :available-langs="availableLangs"
159 :has-multi-language="hasMultiLanguage"
160 :has-ratings="hasRatings"
161 :has-suggestive="hasSuggestive"
162 :available-content-types="availableContentTypes"
163 :has-content-types="hasContentTypes"
164 :available-stream-types="availableStreamTypes"
165 :has-stream-types="hasStreamTypes"
166 :available-qualities="availableQualities"
167 :has-qualities="hasQualities"
168 :has-broken="hasBroken"
196 :available-langs="facets.availableLangs"
197 :has-multi-language="facets.hasMultiLanguage"
198 :has-ratings="facets.hasRatings"
199 :has-suggestive="facets.hasSuggestive"
200 :available-content-types="facets.availableContentTypes"
201 :has-content-types="facets.availableContentTypes.length > 0"
202 :has-broken="facets.hasBroken"
169203 />
170204 </div>
171205
@@ -178,7 +212,13 @@ const filteredSites = computed(() => {
178212 />
179213
180214 <div v-else>
181 <RepoRow v-for="repo in resolvedRepos" :key="repo.indexUrl" :repo="repo" :scheme="scheme" :show-broken="showBroken" />
215 <RepoRow
216 v-for="repo in resolvedRepos"
217 :key="repo.indexUrl"
218 :repo="repo"
219 :scheme="scheme"
220 :show-broken="showBroken"
221 />
182222 </div>
183223 </div>
184224
@@ -187,7 +227,9 @@ const filteredSites = computed(() => {
187227 v-if="tooltip"
188228 class="ext-fixed-tooltip"
189229 :style="{ left: tooltip.x + 'px', top: tooltip.y + 'px' }"
190 >{{ tooltip.text }}</div>
230 >
231 {{ tooltip.text }}
232 </div>
191233 </Teleport>
192234</template>
193235
@@ -198,7 +240,6 @@ const filteredSites = computed(() => {
198240 border-radius: var(--radius-xl, 12px);
199241 overflow: hidden;
200242}
201
202243.ext-toolbar {
203244 display: flex;
204245 flex-wrap: wrap;
@@ -208,7 +249,6 @@ const filteredSites = computed(() => {
208249 background-color: var(--vp-c-bg-soft);
209250 border-bottom: 1px solid var(--vp-c-divider);
210251}
211
212252.ext-search {
213253 display: flex;
214254 align-items: center;
@@ -220,7 +260,6 @@ const filteredSites = computed(() => {
220260 background-color: var(--vp-c-bg);
221261 color: var(--vp-c-text-2);
222262}
223
224263.ext-search input {
225264 flex: 1;
226265 min-width: 0;
@@ -230,7 +269,49 @@ const filteredSites = computed(() => {
230269 color: var(--vp-c-text-1);
231270 font-size: 13px;
232271}
233
272.ext-status-btn {
273 display: flex;
274 align-items: center;
275 justify-content: center;
276 width: 30px;
277 height: 30px;
278 padding: 0;
279 border: none;
280 border-radius: 0;
281 background: transparent;
282 color: var(--vp-c-text-1);
283 opacity: 0.55;
284 cursor: pointer;
285 transition: opacity 0.25s;
286}
287.ext-status-btn:hover:not(:disabled) {
288 opacity: 1;
289}
290.ext-status-btn:disabled {
291 cursor: default;
292}
293.ext-status-btn span {
294 font-size: 15px;
295}
296.ext-status-btn.spinning span {
297 animation: ext-spin 1s linear infinite;
298}
299.ext-status-btn.is-failed {
300 color: var(--vp-c-red-2, #e5484d);
301 opacity: 1;
302}
303.ext-status-btn.is-ok {
304 color: var(--vp-c-green-1, #3dd68c);
305 opacity: 1;
306}
307@keyframes ext-spin {
308 to {
309 transform: rotate(360deg);
310 }
311}
312html.effects-disabled .ext-status-btn.spinning span {
313 animation: none;
314}
234315.ext-fixed-tooltip {
235316 position: fixed;
236317 z-index: 9999;
docs/.vitepress/theme/components/extrepo/TypeSelect.vue → docs/.vitepress/theme/components/extrepo/FilterSelect.vue renamed +79 −71
@@ -1,90 +1,105 @@
11<script setup lang="ts">
22import { NuInputHighlight, NuVerticalTransition } from '@nolebase/ui'
3import { onMounted, onUnmounted, ref } from 'vue'
4import { contentTypeLabel } from './helpers'
3import { computed, ref } from 'vue'
54import MenuHelp from '../settings/MenuHelp.vue'
65import MenuTitle from '../settings/MenuTitle.vue'
6import { useDropdown } from './useDropdown'
77
8defineProps<{
9 modelValue: string
10 availableTypes: string[]
11}>()
8export interface FilterOption {
9 value: string
10 label: string
11 flag?: string
12}
13
14const props = withDefaults(
15 defineProps<{
16 title: string
17 icon: string
18 helpText: string
19 options: FilterOption[]
20 modelValue: string
21 triggerLabel?: string
22 }>(),
23 {
24 triggerLabel: undefined
25 }
26)
1227
1328const emit = defineEmits<{
1429 'update:modelValue': [value: string]
1530}>()
1631
17const rootRef = ref<HTMLElement>()
18const open = ref(false)
32const { rootRef, open, toggle } = useDropdown()
1933const menuTitleElementRef = ref<HTMLDivElement>()
2034const isMenuHelpPoppedUp = ref(false)
2135
22function select(type: string) {
23 emit('update:modelValue', type)
24 open.value = false
25}
36const currentLabel = computed(() => {
37 if (props.triggerLabel) return props.triggerLabel
38 return props.options.find(o => o.value === props.modelValue)?.label ?? 'All'
39})
2640
27function onDocClick(e: MouseEvent) {
28 if (rootRef.value && !rootRef.value.contains(e.target as Node)) open.value = false
41function select(value: string) {
42 emit('update:modelValue', value)
43 open.value = false
2944}
30
31onMounted(() => document.addEventListener('click', onDocClick, true))
32onUnmounted(() => document.removeEventListener('click', onDocClick, true))
3345</script>
3446
3547<template>
36 <div ref="rootRef" class="ext-type-select" :class="{ 'ext-type-select--open': open }">
48 <div ref="rootRef" class="ext-fselect" :class="{ 'ext-fselect--open': open }">
3749 <div ref="menuTitleElementRef" relative flex items-center mb-2>
38 <MenuTitle title="Type" aria-label="Type" flex="1" pr-4>
50 <MenuTitle :title="title" :aria-label="title" flex="1" pr-4>
3951 <template #icon>
40 <span i-lucide:tags mr-1 aria-hidden="true" />
52 <span :class="icon" mr-1 aria-hidden="true" />
4153 </template>
4254 </MenuTitle>
4355 <MenuHelp
4456 v-model:is-popped-up="isMenuHelpPoppedUp"
4557 :menu-title-element-ref="menuTitleElementRef"
4658 >
47 <h4 text-md mb-1 font-semibold>Type</h4>
59 <h4 text-md mb-1 font-semibold>{{ title }}</h4>
4860 <p text="sm" mb-2 max-w-100>
49 Filters extensions by type.
61 {{ helpText }}
5062 </p>
63 <slot name="help-extra" />
5164 </MenuHelp>
5265 </div>
5366 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
5467 <button
5568 type="button"
56 class="ext-type-trigger"
69 class="ext-fselect-trigger"
5770 aria-haspopup="listbox"
5871 :aria-expanded="open"
59 @click="open = !open"
72 @click="toggle"
6073 >
61 <span class="ext-type-label">{{ modelValue ? contentTypeLabel(modelValue) : 'All types' }}</span>
62 <span class="ext-type-chevron i-lucide:chevron-down" :class="{ 'ext-type-chevron--open': open }" />
74 <span class="ext-fselect-label">{{ currentLabel }}</span>
75 <span
76 class="ext-fselect-chevron i-lucide:chevron-down"
77 :class="{ 'ext-fselect-chevron--open': open }"
78 />
6379 </button>
6480
6581 <NuVerticalTransition :duration="200">
66 <div v-show="open" class="ext-type-options" role="listbox">
67 <button
68 type="button"
69 role="option"
70 class="ext-type-option"
71 :class="{ 'ext-type-option--selected': modelValue === '' }"
72 :aria-selected="modelValue === ''"
73 @click="select('')"
74 >
75 <span class="ext-type-option-label">All types</span>
76 </button>
82 <div v-show="open" class="ext-fselect-options" role="listbox">
7783 <button
78 v-for="type in availableTypes"
79 :key="type"
84 v-for="option in options"
85 :key="option.value"
8086 type="button"
8187 role="option"
82 class="ext-type-option"
83 :class="{ 'ext-type-option--selected': modelValue === type }"
84 :aria-selected="modelValue === type"
85 @click="select(type)"
88 class="ext-fselect-option"
89 :class="{
90 'ext-fselect-option--selected':
91 modelValue === option.value
92 }"
93 :aria-selected="modelValue === option.value"
94 @click="select(option.value)"
8695 >
87 <span class="ext-type-option-label">{{ contentTypeLabel(type) }}</span>
96 <span class="ext-fselect-option-label">{{ option.label }}</span>
97 <span
98 v-if="option.flag"
99 class="ext-fselect-option-flag"
100 :class="option.flag"
101 aria-hidden="true"
102 />
88103 </button>
89104 </div>
90105 </NuVerticalTransition>
@@ -93,11 +108,10 @@ onUnmounted(() => document.removeEventListener('click', onDocClick, true))
93108</template>
94109
95110<style scoped>
96.ext-type-select {
111.ext-fselect {
97112 position: relative;
98113}
99
100.ext-type-trigger {
114.ext-fselect-trigger {
101115 display: flex;
102116 align-items: center;
103117 gap: 8px;
@@ -112,28 +126,23 @@ onUnmounted(() => document.removeEventListener('click', onDocClick, true))
112126 cursor: pointer;
113127 transition: border-color 0.15s, background-color 0.15s;
114128}
115
116.ext-type-trigger:hover,
117.ext-type-select--open .ext-type-trigger {
129.ext-fselect-trigger:hover,
130.ext-fselect--open .ext-fselect-trigger {
118131 border-color: var(--vp-c-brand-1);
119132}
120
121.ext-type-label {
133.ext-fselect-label {
122134 flex: 1;
123135 text-align: left;
124136}
125
126.ext-type-chevron {
137.ext-fselect-chevron {
127138 flex-shrink: 0;
128139 color: var(--vp-c-text-2);
129140 transition: transform 0.2s ease;
130141}
131
132.ext-type-chevron--open {
142.ext-fselect-chevron--open {
133143 transform: rotate(180deg);
134144}
135
136.ext-type-options {
145.ext-fselect-options {
137146 margin-top: 6px;
138147 max-height: 240px;
139148 overflow-y: auto;
@@ -147,8 +156,7 @@ onUnmounted(() => document.removeEventListener('click', onDocClick, true))
147156 background: var(--vp-c-bg-elv);
148157 box-shadow: var(--vp-shadow-2, 0 4px 16px rgba(0, 0, 0, 0.2));
149158}
150
151.ext-type-option {
159.ext-fselect-option {
152160 display: flex;
153161 align-items: center;
154162 gap: 8px;
@@ -163,22 +171,22 @@ onUnmounted(() => document.removeEventListener('click', onDocClick, true))
163171 width: 100%;
164172 transition: background-color 0.15s;
165173}
166
167.ext-type-option-label {
168 flex: 1;
169 min-width: 0;
170}
171
172.ext-type-option:hover {
174.ext-fselect-option:hover {
173175 background-color: var(--vp-c-bg-soft);
174176}
175
176.ext-type-option--selected {
177.ext-fselect-option--selected {
177178 background-color: var(--vp-c-brand-soft);
178179 font-weight: 600;
179180}
180
181.ext-type-option--selected:hover {
181.ext-fselect-option--selected:hover {
182182 background-color: var(--vp-c-brand-soft);
183183}
184.ext-fselect-option-label {
185 flex: 1;
186 min-width: 0;
187}
188.ext-fselect-option-flag {
189 flex-shrink: 0;
190 font-size: 14px;
191}
184192</style>
docs/.vitepress/theme/components/extrepo/LangSelect.vue deleted −204
@@ -1,204 +0,0 @@
1<script setup lang="ts">
2import { NuInputHighlight, NuVerticalTransition } from '@nolebase/ui'
3import { onMounted, onUnmounted, ref } from 'vue'
4import { langFlagClass, langLabel } from './helpers'
5import MenuHelp from '../settings/MenuHelp.vue'
6import MenuTitle from '../settings/MenuTitle.vue'
7
8defineProps<{
9 modelValue: string
10 availableLangs: string[]
11 hasMultiLanguage: boolean
12}>()
13
14const emit = defineEmits<{
15 'update:modelValue': [value: string]
16}>()
17
18const rootRef = ref<HTMLElement>()
19const open = ref(false)
20const menuTitleElementRef = ref<HTMLDivElement>()
21const isMenuHelpPoppedUp = ref(false)
22
23function select(lang: string) {
24 emit('update:modelValue', lang)
25 open.value = false
26}
27
28function onDocClick(e: MouseEvent) {
29 if (rootRef.value && !rootRef.value.contains(e.target as Node)) open.value = false
30}
31
32onMounted(() => document.addEventListener('click', onDocClick, true))
33onUnmounted(() => document.removeEventListener('click', onDocClick, true))
34</script>
35
36<template>
37 <div ref="rootRef" class="ext-lang-select" :class="{ 'ext-lang-select--open': open }">
38 <div ref="menuTitleElementRef" relative flex items-center mb-2>
39 <MenuTitle title="Language" aria-label="Language" flex="1" pr-4>
40 <template #icon>
41 <span i-lucide:languages mr-1 aria-hidden="true" />
42 </template>
43 </MenuTitle>
44 <MenuHelp
45 v-model:is-popped-up="isMenuHelpPoppedUp"
46 :menu-title-element-ref="menuTitleElementRef"
47 >
48 <h4 text-md mb-1 font-semibold>Language</h4>
49 <p text="sm" mb-2 max-w-100>
50 Filters extensions by translated language (not original language).
51 </p>
52 </MenuHelp>
53 </div>
54 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
55 <button
56 type="button"
57 class="ext-lang-trigger"
58 aria-haspopup="listbox"
59 :aria-expanded="open"
60 @click="open = !open"
61 >
62 <span class="ext-lang-label">{{ modelValue ? langLabel(modelValue) : 'All languages' }}</span>
63 <span class="ext-lang-chevron i-lucide:chevron-down" :class="{ 'ext-lang-chevron--open': open }" />
64 </button>
65
66 <NuVerticalTransition :duration="200">
67 <div v-show="open" class="ext-lang-options" role="listbox">
68 <button
69 type="button"
70 role="option"
71 class="ext-lang-option"
72 :class="{ 'ext-lang-option--selected': modelValue === '' }"
73 :aria-selected="modelValue === ''"
74 @click="select('')"
75 >
76 <span class="ext-lang-option-label">All languages</span>
77 <span class="ext-lang-option-flag" :class="langFlagClass('')" aria-hidden="true" />
78 </button>
79 <button
80 v-if="hasMultiLanguage"
81 type="button"
82 role="option"
83 class="ext-lang-option"
84 :class="{ 'ext-lang-option--selected': modelValue === 'all' }"
85 :aria-selected="modelValue === 'all'"
86 @click="select('all')"
87 >
88 <span class="ext-lang-option-label">Multi-language</span>
89 <span class="ext-lang-option-flag" :class="langFlagClass('all')" aria-hidden="true" />
90 </button>
91 <button
92 v-for="lang in availableLangs"
93 :key="lang"
94 type="button"
95 role="option"
96 class="ext-lang-option"
97 :class="{ 'ext-lang-option--selected': modelValue === lang }"
98 :aria-selected="modelValue === lang"
99 @click="select(lang)"
100 >
101 <span class="ext-lang-option-label">{{ langLabel(lang) }}</span>
102 <span class="ext-lang-option-flag" :class="langFlagClass(lang)" aria-hidden="true" />
103 </button>
104 </div>
105 </NuVerticalTransition>
106 </NuInputHighlight>
107 </div>
108</template>
109
110<style scoped>
111.ext-lang-select {
112 position: relative;
113}
114
115.ext-lang-trigger {
116 display: flex;
117 align-items: center;
118 gap: 8px;
119 width: 100%;
120 min-height: 44px;
121 padding: 7px 10px;
122 border-radius: 8px;
123 border: 2px solid var(--vp-c-divider);
124 background: var(--wk-c-menu-bg);
125 color: var(--vp-c-text-1);
126 font-size: 13px;
127 cursor: pointer;
128 transition: border-color 0.15s, background-color 0.15s;
129}
130
131.ext-lang-trigger:hover,
132.ext-lang-select--open .ext-lang-trigger {
133 border-color: var(--vp-c-brand-1);
134}
135
136.ext-lang-label {
137 flex: 1;
138 text-align: left;
139}
140
141.ext-lang-chevron {
142 flex-shrink: 0;
143 color: var(--vp-c-text-2);
144 transition: transform 0.2s ease;
145}
146
147.ext-lang-chevron--open {
148 transform: rotate(180deg);
149}
150
151.ext-lang-options {
152 margin-top: 6px;
153 max-height: 240px;
154 overflow-y: auto;
155 overscroll-behavior: contain;
156 display: flex;
157 flex-direction: column;
158 gap: 2px;
159 padding: 4px;
160 border-radius: 8px;
161 border: 1px solid var(--vp-c-divider);
162 background: var(--vp-c-bg-elv);
163 box-shadow: var(--vp-shadow-2, 0 4px 16px rgba(0, 0, 0, 0.2));
164}
165
166.ext-lang-option {
167 display: flex;
168 align-items: center;
169 gap: 8px;
170 padding: 5px 8px;
171 border-radius: 8px;
172 border: none;
173 background: transparent;
174 cursor: pointer;
175 color: var(--vp-c-text-1);
176 font-size: 13px;
177 text-align: left;
178 width: 100%;
179 transition: background-color 0.15s;
180}
181
182.ext-lang-option-label {
183 flex: 1;
184 min-width: 0;
185}
186
187.ext-lang-option-flag {
188 flex-shrink: 0;
189 font-size: 14px;
190}
191
192.ext-lang-option:hover {
193 background-color: var(--vp-c-bg-soft);
194}
195
196.ext-lang-option--selected {
197 background-color: var(--vp-c-brand-soft);
198 font-weight: 600;
199}
200
201.ext-lang-option--selected:hover {
202 background-color: var(--vp-c-brand-soft);
203}
204</style>
docs/.vitepress/theme/components/extrepo/LazyIcon.vue +68 −20
@@ -1,5 +1,6 @@
11<script setup lang="ts">
22import { onBeforeUnmount, onMounted, ref } from 'vue'
3import { iconResultCache, observeIcon } from './iconObserver'
34import { scheduleIconLoad } from './iconQueue'
45
56const props = defineProps<{
@@ -10,40 +11,87 @@ const props = defineProps<{
1011const rootRef = ref<HTMLElement>()
1112const loaded = ref(false)
1213const failed = ref(false)
13let observer: IntersectionObserver | undefined
14let unobserve: (() => void) | undefined
15let cancelLoad: (() => void) | undefined
1416
15onMounted(() => {
16 const el = rootRef.value
17 if (!el || !props.src) return
18 // Preload a bit before the card is actually visible so it's ready by the time it scrolls in.
19 observer = new IntersectionObserver((entries) => {
20 if (!entries.some(entry => entry.isIntersecting)) return
21 observer?.disconnect()
22 scheduleIconLoad(() => new Promise<void>((resolve) => {
17function startLoad() {
18 if (!props.src) return
19 const cached = iconResultCache.get(props.src)
20 if (cached !== undefined) {
21 if (cached) loaded.value = true
22 else failed.value = true
23 return
24 }
25 cancelLoad = scheduleIconLoad(() =>
26 new Promise<void>((resolve) => {
2327 const img = new Image()
2428 img.onload = () => {
2529 loaded.value = true
30 iconResultCache.set(props.src!, true)
2631 resolve()
2732 }
2833 img.onerror = () => {
2934 failed.value = true
35 iconResultCache.set(props.src!, false)
3036 resolve()
3137 }
3238 img.src = props.src!
33 }))
34 }, { rootMargin: '200px' })
35 observer.observe(el)
39 })
40 )
41}
42
43onMounted(() => {
44 const el = rootRef.value
45 if (!el) return
46 if (!props.src) return
47 unobserve = observeIcon(el, () => {
48 startLoad()
49 })
3650})
3751
38onBeforeUnmount(() => observer?.disconnect())
52onBeforeUnmount(() => {
53 unobserve?.()
54 cancelLoad?.()
55})
3956</script>
4057
4158<template>
42 <img v-if="loaded" ref="rootRef" :src="src" :alt="alt" />
43 <span
44 v-else
45 ref="rootRef"
46 class="ext-site-icon-fallback"
47 :class="{ 'i-lucide:globe': !src || failed, 'ext-site-icon-loading': src && !failed }"
48 />
59 <span ref="rootRef" class="ext-site-icon-slot">
60 <img v-if="loaded" :src="src" :alt="alt" loading="lazy" decoding="async" />
61 <span
62 v-else
63 class="ext-site-icon-fallback"
64 :class="{
65 'i-lucide:globe': !src || failed,
66 'ext-site-icon-loading': src && !failed
67 }"
68 />
69 </span>
4970</template>
71
72<style scoped>
73.ext-site-icon-slot {
74 width: 18px;
75 height: 18px;
76 flex-shrink: 0;
77 display: inline-flex;
78}
79.ext-site-icon-slot img {
80 width: 18px;
81 height: 18px;
82 border-radius: 4px;
83 object-fit: contain;
84}
85.ext-site-icon-fallback {
86 display: flex;
87 align-items: center;
88 justify-content: center;
89 color: var(--vp-c-text-3);
90 width: 18px;
91 height: 18px;
92}
93.ext-site-icon-loading {
94 background-color: var(--vp-c-bg-mute, var(--vp-c-bg-soft));
95 border-radius: 4px;
96}
97</style>
docs/.vitepress/theme/components/extrepo/RatingFilter.vue deleted −234
@@ -1,234 +0,0 @@
1<script setup lang="ts">
2import { NuInputHighlight, NuVerticalTransition } from '@nolebase/ui'
3import { computed, onMounted, onUnmounted, ref } from 'vue'
4import MenuHelp from '../settings/MenuHelp.vue'
5import MenuTitle from '../settings/MenuTitle.vue'
6import type { RatingFilter } from './types'
7
8const props = defineProps<{
9 modelValue: RatingFilter
10 hasSuggestive: boolean
11}>()
12
13const emit = defineEmits<{
14 'update:modelValue': [value: RatingFilter]
15}>()
16
17const options = computed(() => {
18 const base = [
19 { value: 'all' as RatingFilter, label: 'All' },
20 { value: 'safe' as RatingFilter, label: 'Safe' }
21 ]
22 if (props.hasSuggestive) {
23 base.push({ value: 'suggestive' as RatingFilter, label: 'Mature' })
24 }
25 base.push({
26 value: 'nsfw' as RatingFilter,
27 label: props.hasSuggestive ? 'Adult' : 'NSFW'
28 })
29 return base
30})
31
32const rootRef = ref<HTMLElement>()
33const open = ref(false)
34const menuTitleElementRef = ref<HTMLDivElement>()
35const isMenuHelpPoppedUp = ref(false)
36
37const currentLabel = computed(() => options.value.find(o => o.value === props.modelValue)?.label ?? 'All')
38
39function select(value: RatingFilter) {
40 emit('update:modelValue', value)
41 open.value = false
42}
43
44function onDocClick(e: MouseEvent) {
45 if (rootRef.value && !rootRef.value.contains(e.target as Node)) open.value = false
46}
47
48onMounted(() => document.addEventListener('click', onDocClick, true))
49onUnmounted(() => document.removeEventListener('click', onDocClick, true))
50</script>
51
52<template>
53 <div ref="rootRef" class="ext-rating-select" :class="{ 'ext-rating-select--open': open }">
54 <div ref="menuTitleElementRef" relative flex items-center mb-2>
55 <MenuTitle title="Rating" aria-label="Rating" flex="1" pr-4>
56 <template #icon>
57 <span i-lucide:shield mr-1 aria-hidden="true" />
58 </template>
59 </MenuTitle>
60 <MenuHelp
61 v-model:is-popped-up="isMenuHelpPoppedUp"
62 :menu-title-element-ref="menuTitleElementRef"
63 >
64 <h4 text-md mb-1 font-semibold>Rating</h4>
65 <p text="sm" mb-2>Choose the highest content rating to include.</p>
66 <div class="rating-help-options">
67 <div class="rating-help-option">
68 <strong>All</strong>
69 <span>Shows entries at every rating level</span>
70 </div>
71 <div class="rating-help-option">
72 <strong>Safe</strong>
73 <span>Only entries with no mature content</span>
74 </div>
75 <div v-if="hasSuggestive" class="rating-help-option">
76 <strong>Mature</strong>
77 <span>Includes suggestive content</span>
78 </div>
79 <div class="rating-help-option">
80 <strong>{{ hasSuggestive ? 'Adult' : 'NSFW' }}</strong>
81 <span>Includes explicit adult content</span>
82 </div>
83 </div>
84 </MenuHelp>
85 </div>
86 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
87 <button
88 type="button"
89 class="ext-rating-trigger"
90 aria-haspopup="listbox"
91 :aria-expanded="open"
92 @click="open = !open"
93 >
94 <span class="ext-rating-label">{{ currentLabel }}</span>
95 <span class="ext-rating-chevron i-lucide:chevron-down" :class="{ 'ext-rating-chevron--open': open }" />
96 </button>
97
98 <NuVerticalTransition :duration="200">
99 <div v-show="open" class="ext-rating-options" role="listbox">
100 <button
101 v-for="option in options"
102 :key="option.value"
103 type="button"
104 role="option"
105 class="ext-rating-option"
106 :class="{ 'ext-rating-option--selected': modelValue === option.value }"
107 :aria-selected="modelValue === option.value"
108 @click="select(option.value)"
109 >
110 <span class="ext-rating-option-label">{{ option.label }}</span>
111 </button>
112 </div>
113 </NuVerticalTransition>
114 </NuInputHighlight>
115 </div>
116</template>
117
118<style scoped>
119.rating-help-options {
120 display: flex;
121 flex-direction: column;
122 gap: 5px;
123}
124
125.rating-help-option {
126 display: flex;
127 flex-direction: column;
128 gap: 4px;
129 background: var(--wk-c-menu-bg);
130 border-radius: 12px;
131 padding: 10px 12px;
132}
133
134.rating-help-option strong {
135 font-size: 0.875rem;
136 font-weight: 600;
137 color: var(--vp-c-text-1);
138}
139
140.rating-help-option span {
141 font-size: 0.875rem;
142 color: var(--vp-c-text-2);
143 line-height: 1.4;
144}
145
146.ext-rating-select {
147 position: relative;
148}
149
150.ext-rating-trigger {
151 display: flex;
152 align-items: center;
153 gap: 8px;
154 width: 100%;
155 min-height: 44px;
156 padding: 7px 10px;
157 border-radius: 8px;
158 border: 2px solid var(--vp-c-divider);
159 background: var(--wk-c-menu-bg);
160 color: var(--vp-c-text-1);
161 font-size: 13px;
162 cursor: pointer;
163 transition: border-color 0.15s, background-color 0.15s;
164}
165
166.ext-rating-trigger:hover,
167.ext-rating-select--open .ext-rating-trigger {
168 border-color: var(--vp-c-brand-1);
169}
170
171.ext-rating-label {
172 flex: 1;
173 text-align: left;
174}
175
176.ext-rating-chevron {
177 flex-shrink: 0;
178 color: var(--vp-c-text-2);
179 transition: transform 0.2s ease;
180}
181
182.ext-rating-chevron--open {
183 transform: rotate(180deg);
184}
185
186.ext-rating-options {
187 margin-top: 6px;
188 max-height: 240px;
189 overflow-y: auto;
190 overscroll-behavior: contain;
191 display: flex;
192 flex-direction: column;
193 gap: 2px;
194 padding: 4px;
195 border-radius: 8px;
196 border: 1px solid var(--vp-c-divider);
197 background: var(--vp-c-bg-elv);
198 box-shadow: var(--vp-shadow-2, 0 4px 16px rgba(0, 0, 0, 0.2));
199}
200
201.ext-rating-option {
202 display: flex;
203 align-items: center;
204 gap: 8px;
205 padding: 5px 8px;
206 border-radius: 8px;
207 border: none;
208 background: transparent;
209 cursor: pointer;
210 color: var(--vp-c-text-1);
211 font-size: 13px;
212 text-align: left;
213 width: 100%;
214 transition: background-color 0.15s;
215}
216
217.ext-rating-option-label {
218 flex: 1;
219 min-width: 0;
220}
221
222.ext-rating-option:hover {
223 background-color: var(--vp-c-bg-soft);
224}
225
226.ext-rating-option--selected {
227 background-color: var(--vp-c-brand-soft);
228 font-weight: 600;
229}
230
231.ext-rating-option--selected:hover {
232 background-color: var(--vp-c-brand-soft);
233}
234</style>
docs/.vitepress/theme/components/extrepo/RepoRow.vue +101 −210
@@ -1,15 +1,28 @@
11<script setup lang="ts">
22import { computed, ref } from 'vue'
3import { data } from '../../../../ext/extensionRepos.data'
3import { NOT_EXPANDABLE_REPOS } from './constants'
44import { stripHtml } from './helpers'
5import { copyValue, hasBrowseOnlyCopyButton, hasCopyButton, installHref, isBrowseOnly, mangayomiCopyValue, mangayomiHref, mangayomiLiveContainerHref } from './install'
5import {
6 copyValue,
7 hasCopyButton,
8 installHref,
9 isBrowseOnly,
10 mangayomiCopyValue,
11 mangayomiHref,
12 mangayomiLiveContainerHref
13} from './install'
14import RepoVariantRow from './RepoVariantRow.vue'
615import SiteGrid from './SiteGrid.vue'
7import type { Repo, RepoVariant } from './types'
16import type { Repo } from './types'
17import { useCopy } from './useCopy'
18import { useRepoStore } from './useRepoStore'
819import { useTooltip } from './useTooltip'
920
1021const { show: showTooltip, hide: hideTooltip } = useTooltip()
22const { copiedKey, copy } = useCopy()
23const { store } = useRepoStore()
1124
12const repoData = data.sites
25const repoData = computed(() => store.value?.sites ?? {})
1326
1427const props = defineProps<{
1528 repo: Repo
@@ -17,60 +30,51 @@ const props = defineProps<{
1730 showBroken?: boolean
1831}>()
1932
20const NOT_EXPANDABLE = new Set(['MegaRepo', 'Shotetsu Compatability'])
21
2233const open = ref(false)
23const copied = ref(false)
24const copiedLabel = ref<string | null>(null)
25const openVariants = ref<Set<string>>(new Set())
2634
2735const sites = computed(() => {
2836 const dataUrl = props.repo.data ?? props.repo.indexUrl
29 const all = repoData[dataUrl]?.sites ?? []
37 const all = repoData.value[dataUrl]?.sites ?? []
3038 return props.showBroken ? all : all.filter(site => !site.isBroken)
3139})
32const isExpandable = computed(() => !NOT_EXPANDABLE.has(stripHtml(props.repo.name)))
33const installUrl = computed(() => installHref(props.scheme, props.repo, {
34 suwatteV6: repoData[props.repo.indexUrl]?.suwatteV6,
35 suwatteListUrl: repoData[props.repo.indexUrl]?.suwatteListUrl
36}))
37// Browse-only schemes (e.g. Kotatsu forks) have no app to deep-link into, so install,
38// copy, and livecontainer actions are hidden everywhere in this component.
40const repoName = computed(() => stripHtml(props.repo.name))
41const isExpandable = computed(() => !NOT_EXPANDABLE_REPOS.has(repoName.value))
42const installUrl = computed(() =>
43 installHref(props.scheme, props.repo, {
44 suwatteV6: repoData.value[props.repo.indexUrl]?.suwatteV6,
45 suwatteListUrl: repoData.value[props.repo.indexUrl]?.suwatteListUrl
46 })
47)
3948const showActions = computed(() => !isBrowseOnly(props.scheme))
4049
41// First variant is the combined "All-in-One" one (when 2+ types exist), shown directly
42// on the repo header; remaining variants list below as their own collapsible sub-rows.
43// Browse-only groups have no such combined header since the builds share nothing to
44// combine, so every variant renders as a sub-row instead.
45const headerVariant = computed(() => showActions.value ? props.repo.variants?.[0] : undefined)
50const headerVariant = computed(() =>
51 showActions.value ? props.repo.variants?.[0] : undefined
52)
53const headerCopyValue = computed(() =>
54 headerVariant.value ? mangayomiCopyValue(headerVariant.value) : null
55)
56const headerInstallUrl = computed(() =>
57 headerVariant.value ? mangayomiHref(props.repo, headerVariant.value) : null
58)
59const headerLiveUrl = computed(() =>
60 headerVariant.value
61 ? mangayomiLiveContainerHref(props.repo, headerVariant.value)
62 : null
63)
4664const subVariants = computed(() => {
4765 if (!props.repo.variants?.length) return []
48 return showActions.value && props.repo.variants.length > 1 ? props.repo.variants.slice(1) : props.repo.variants
66 return showActions.value && props.repo.variants.length > 1
67 ? props.repo.variants.slice(1)
68 : props.repo.variants
4969})
5070
5171async function copyUrl() {
52 await navigator.clipboard.writeText(copyValue(props.scheme, props.repo.indexUrl))
53 copied.value = true
54 setTimeout(() => { copied.value = false }, 1500)
55}
56
57async function copyVariantUrl(variant: RepoVariant) {
58 const value = mangayomiCopyValue(variant)
59 if (!value) return
60 await navigator.clipboard.writeText(value)
61 copiedLabel.value = variant.label
62 setTimeout(() => { if (copiedLabel.value === variant.label) copiedLabel.value = null }, 1500)
72 await copy(props.repo.indexUrl, copyValue(props.scheme, props.repo.indexUrl))
6373}
6474
65function toggleVariant(label: string) {
66 if (openVariants.value.has(label)) openVariants.value.delete(label)
67 else openVariants.value.add(label)
68}
69
70function variantSites(variant: RepoVariant) {
71 const url = mangayomiCopyValue(variant)
72 const all = url ? repoData[url]?.sites ?? [] : []
73 return props.showBroken ? all : all.filter(site => !site.isBroken)
75async function copyHeaderVariantUrl() {
76 if (!headerVariant.value || !headerCopyValue.value) return
77 await copy(headerVariant.value.label, headerCopyValue.value)
7478}
7579</script>
7680
@@ -90,44 +94,66 @@ function variantSites(variant: RepoVariant) {
9094 </div>
9195 <div class="ext-repo-actions">
9296 <template v-if="headerVariant">
93 <a class="ext-btn ext-btn-install" :href="mangayomiHref(repo, headerVariant)">
97 <a class="ext-btn ext-btn-install" :href="headerInstallUrl!">
9498 <span class="i-lucide:download" />
9599 <span class="ext-btn-install-label">Install</span>
96100 </a>
97 <a class="ext-btn ext-btn-livecontainer" :href="mangayomiLiveContainerHref(repo, headerVariant)" aria-label="Install via LiveContainer (iOS)" @mouseenter="showTooltip($event, 'Install via LiveContainer (iOS)')" @mouseleave="hideTooltip">
101 <a
102 class="ext-btn ext-btn-livecontainer"
103 :href="headerLiveUrl!"
104 aria-label="Install via LiveContainer (iOS)"
105 @mouseenter="showTooltip($event, 'Install via LiveContainer (iOS)')"
106 @mouseleave="hideTooltip"
107 >
98108 <span class="i-mdi:apple" />
99109 </a>
100110 <button
101 v-if="mangayomiCopyValue(headerVariant)"
111 v-if="headerCopyValue"
102112 class="ext-btn ext-btn-copy"
103113 type="button"
104 @click="copyVariantUrl(headerVariant)"
114 @click="copyHeaderVariantUrl"
105115 >
106 <span v-if="copiedLabel === headerVariant.label" class="i-lucide:check" />
116 <span
117 v-if="copiedKey === headerVariant.label"
118 class="i-lucide:check"
119 />
107120 <span v-else class="i-lucide:copy" />
108121 </button>
109 <!-- Invisible spacers so the header's action group lines up with the sub-rows' -->
110 <button v-if="!mangayomiCopyValue(headerVariant)" class="ext-btn ext-btn-copy ext-btn-spacer" tabindex="-1" aria-hidden="true">
122 <button
123 v-else
124 class="ext-btn ext-btn-copy ext-btn-spacer"
125 tabindex="-1"
126 aria-hidden="true"
127 >
111128 <span class="i-lucide:copy" />
112129 </button>
113 <button class="ext-btn ext-btn-toggle ext-btn-spacer" tabindex="-1" aria-hidden="true">
130 <button
131 class="ext-btn ext-btn-toggle ext-btn-spacer"
132 tabindex="-1"
133 aria-hidden="true"
134 >
114135 <span class="i-lucide:chevron-down" />
115136 </button>
116137 </template>
117138 <template v-else-if="showActions">
118 <a v-if="installUrl" class="ext-btn ext-btn-install" :href="installUrl">
139 <a
140 v-if="installUrl"
141 class="ext-btn ext-btn-install"
142 :href="installUrl"
143 >
119144 <span class="i-lucide:download" />
120145 <span class="ext-btn-install-label">Install</span>
121146 </a>
122 <button v-if="hasCopyButton(scheme)" class="ext-btn ext-btn-copy" type="button" @click="copyUrl">
123 <span v-if="copied" class="i-lucide:check" />
147 <button
148 v-if="hasCopyButton(scheme)"
149 class="ext-btn ext-btn-copy"
150 type="button"
151 @click="copyUrl"
152 >
153 <span v-if="copiedKey === repo.indexUrl" class="i-lucide:check" />
124154 <span v-else class="i-lucide:copy" />
125155 </button>
126156 </template>
127 <button v-else-if="hasBrowseOnlyCopyButton(scheme)" class="ext-btn ext-btn-copy" type="button" @click="copyUrl">
128 <span v-if="copied" class="i-lucide:check" />
129 <span v-else class="i-lucide:copy" />
130 </button>
131157 <button
132158 v-if="!repo.variants"
133159 class="ext-btn ext-btn-toggle"
@@ -144,62 +170,32 @@ function variantSites(variant: RepoVariant) {
144170 </div>
145171
146172 <div v-if="subVariants.length" class="ext-repo-variants">
147 <div v-for="variant in subVariants" :key="variant.label" class="ext-repo-variant">
148 <div class="ext-repo-variant-row">
149 <span class="ext-repo-variant-label">{{ variant.label }}</span>
150 <div class="ext-repo-actions">
151 <template v-if="showActions">
152 <a class="ext-btn ext-btn-install" :href="mangayomiHref(repo, variant)">
153 <span class="i-lucide:download" />
154 <span class="ext-btn-install-label">Install</span>
155 </a>
156 <a class="ext-btn ext-btn-livecontainer" :href="mangayomiLiveContainerHref(repo, variant)" aria-label="Install via LiveContainer (iOS)" @mouseenter="showTooltip($event, 'Install via LiveContainer (iOS)')" @mouseleave="hideTooltip">
157 <span class="i-mdi:apple" />
158 </a>
159 <button
160 v-if="mangayomiCopyValue(variant)"
161 class="ext-btn ext-btn-copy"
162 type="button"
163 @click="copyVariantUrl(variant)"
164 >
165 <span v-if="copiedLabel === variant.label" class="i-lucide:check" />
166 <span v-else class="i-lucide:copy" />
167 </button>
168 </template>
169 <button
170 v-else-if="mangayomiCopyValue(variant)"
171 class="ext-btn ext-btn-copy"
172 type="button"
173 @click="copyVariantUrl(variant)"
174 >
175 <span v-if="copiedLabel === variant.label" class="i-lucide:check" />
176 <span v-else class="i-lucide:copy" />
177 </button>
178 <button
179 class="ext-btn ext-btn-toggle"
180 type="button"
181 :class="{ open: openVariants.has(variant.label) }"
182 :aria-expanded="openVariants.has(variant.label)"
183 @click="toggleVariant(variant.label)"
184 >
185 <span class="i-lucide:chevron-down" />
186 </button>
187 </div>
188 </div>
189
190 <SiteGrid v-if="openVariants.has(variant.label)" :sites="variantSites(variant)" :scheme="scheme" empty-text="No site data available." />
191 </div>
173 <RepoVariantRow
174 v-for="variant in subVariants"
175 :key="variant.label"
176 :repo="repo"
177 :variant="variant"
178 :scheme="scheme"
179 :show-actions="showActions"
180 :show-broken="showBroken"
181 />
192182 </div>
193183
194 <SiteGrid v-if="!repo.variants && isExpandable && open" :sites="sites" :scheme="scheme" empty-text="No site data available." />
184 <SiteGrid
185 v-if="!repo.variants && isExpandable && open"
186 :sites="sites"
187 :scheme="scheme"
188 empty-text="No site data available."
189 />
195190 </div>
196191</template>
197192
193<style scoped src="./repoRowShared.css"></style>
194
198195<style scoped>
199196.ext-repo + .ext-repo {
200197 border-top: 1px solid var(--vp-c-divider);
201198}
202
203199.ext-repo-row {
204200 display: flex;
205201 align-items: center;
@@ -208,7 +204,6 @@ function variantSites(variant: RepoVariant) {
208204 padding: 10px 14px;
209205 background-color: var(--vp-c-bg-soft);
210206}
211
212207.ext-repo-name {
213208 font-size: 14px;
214209 font-weight: 600;
@@ -218,11 +213,9 @@ function variantSites(variant: RepoVariant) {
218213 gap: 6px;
219214 min-width: 0;
220215}
221
222216.ext-repo-name :deep(a) {
223217 color: inherit;
224218}
225
226219.ext-note-btn {
227220 display: inline-flex;
228221 align-items: center;
@@ -236,12 +229,10 @@ function variantSites(variant: RepoVariant) {
236229 line-height: 0;
237230 flex-shrink: 0;
238231}
239
240232.ext-note-btn span {
241233 font-size: 13px;
242234 vertical-align: 0;
243235}
244
245236.ext-note-popper {
246237 max-width: 280px;
247238 padding: 10px 12px;
@@ -254,108 +245,8 @@ function variantSites(variant: RepoVariant) {
254245 line-height: 1.5;
255246 color: var(--vp-c-text-2);
256247}
257
258.ext-repo-actions {
259 display: flex;
260 align-items: center;
261 gap: 6px;
262 flex-shrink: 0;
263}
264
265.ext-btn {
266 display: inline-flex;
267 align-items: center;
268 gap: 4px;
269 padding: 5px 10px;
270 border-radius: 8px;
271 border: 1px solid var(--vp-c-divider);
272 background-color: var(--vp-c-bg);
273 color: var(--vp-c-text-1);
274 font-size: 13px;
275 line-height: 1;
276 cursor: pointer;
277 transition: border-color 0.2s, background-color 0.2s, color 0.2s;
278}
279
280.ext-btn:hover {
281 border-color: var(--vp-c-brand-1);
282}
283
284.ext-btn-install {
285 background-color: var(--vp-button-brand-bg);
286 color: var(--vp-button-brand-text) !important;
287 border-color: var(--vp-button-brand-border);
288 text-decoration: none !important;
289 font-weight: 600;
290}
291
292.ext-btn-install:hover {
293 filter: brightness(1.08);
294 border-color: var(--vp-button-brand-hover-border);
295}
296
297.ext-btn-copy,
298.ext-btn-livecontainer {
299 padding: 5px 8px;
300}
301
302.ext-btn-toggle {
303 padding: 0;
304 border: none;
305 background: transparent;
306 color: var(--vp-c-text-1);
307}
308
309.ext-btn-toggle:hover {
310 border-color: transparent;
311 color: var(--vp-c-brand-1);
312}
313
314.ext-btn-toggle span {
315 font-size: 18px;
316 transition: transform 0.2s;
317}
318
319.ext-btn-toggle.open span {
320 transform: rotate(180deg);
321}
322
323.ext-btn-toggle-hidden {
324 visibility: hidden;
325 pointer-events: none;
326}
327
328.ext-btn-spacer {
329 visibility: hidden;
330 pointer-events: none;
331}
332
333248.ext-repo-variants {
334249 display: flex;
335250 flex-direction: column;
336251}
337
338.ext-repo-variant-row {
339 display: flex;
340 align-items: center;
341 justify-content: space-between;
342 gap: 12px;
343 padding: 8px 14px 8px 28px;
344 border-top: 1px solid var(--vp-c-divider);
345}
346
347.ext-repo-variant-label {
348 font-size: 13px;
349 color: var(--vp-c-text-2);
350}
351
352@media (max-width: 767px) {
353 .ext-btn-install {
354 padding: 5px 8px;
355 }
356
357 .ext-btn-install-label {
358 display: none;
359 }
360}
361252</style>
docs/.vitepress/theme/components/extrepo/RepoVariantRow.vue added +121
@@ -0,0 +1,121 @@
1<script setup lang="ts">
2import { computed, ref } from 'vue'
3import {
4 mangayomiCopyValue,
5 mangayomiHref,
6 mangayomiLiveContainerHref
7} from './install'
8import SiteGrid from './SiteGrid.vue'
9import type { Repo, RepoVariant } from './types'
10import { useCopy } from './useCopy'
11import { useRepoStore } from './useRepoStore'
12import { useTooltip } from './useTooltip'
13
14const { show: showTooltip, hide: hideTooltip } = useTooltip()
15const { copiedKey, copy } = useCopy()
16const { store } = useRepoStore()
17
18const repoData = computed(() => store.value?.sites ?? {})
19
20const props = defineProps<{
21 repo: Repo
22 variant: RepoVariant
23 scheme: string
24 showActions: boolean
25 showBroken?: boolean
26}>()
27
28const open = ref(false)
29const copyValue = computed(() => mangayomiCopyValue(props.variant))
30const installUrl = computed(() => mangayomiHref(props.repo, props.variant))
31const liveUrl = computed(() =>
32 mangayomiLiveContainerHref(props.repo, props.variant)
33)
34
35const sites = computed(() => {
36 const url = copyValue.value
37 const all = url ? repoData.value[url]?.sites ?? [] : []
38 return props.showBroken ? all : all.filter(site => !site.isBroken)
39})
40
41async function copyVariantUrl() {
42 if (!copyValue.value) return
43 await copy(props.variant.label, copyValue.value)
44}
45</script>
46
47<template>
48 <div class="ext-repo-variant">
49 <div class="ext-repo-variant-row">
50 <span class="ext-repo-variant-label">{{ variant.label }}</span>
51 <div class="ext-repo-actions">
52 <template v-if="showActions">
53 <a class="ext-btn ext-btn-install" :href="installUrl">
54 <span class="i-lucide:download" />
55 <span class="ext-btn-install-label">Install</span>
56 </a>
57 <a
58 class="ext-btn ext-btn-livecontainer"
59 :href="liveUrl"
60 aria-label="Install via LiveContainer (iOS)"
61 @mouseenter="showTooltip($event, 'Install via LiveContainer (iOS)')"
62 @mouseleave="hideTooltip"
63 >
64 <span class="i-mdi:apple" />
65 </a>
66 <button
67 v-if="copyValue"
68 class="ext-btn ext-btn-copy"
69 type="button"
70 @click="copyVariantUrl"
71 >
72 <span v-if="copiedKey === variant.label" class="i-lucide:check" />
73 <span v-else class="i-lucide:copy" />
74 </button>
75 </template>
76 <button
77 v-else-if="copyValue"
78 class="ext-btn ext-btn-copy"
79 type="button"
80 @click="copyVariantUrl"
81 >
82 <span v-if="copiedKey === variant.label" class="i-lucide:check" />
83 <span v-else class="i-lucide:copy" />
84 </button>
85 <button
86 class="ext-btn ext-btn-toggle"
87 type="button"
88 :class="{ open }"
89 :aria-expanded="open"
90 @click="open = !open"
91 >
92 <span class="i-lucide:chevron-down" />
93 </button>
94 </div>
95 </div>
96
97 <SiteGrid
98 v-if="open"
99 :sites="sites"
100 :scheme="scheme"
101 empty-text="No site data available."
102 />
103 </div>
104</template>
105
106<style scoped src="./repoRowShared.css"></style>
107
108<style scoped>
109.ext-repo-variant-row {
110 display: flex;
111 align-items: center;
112 justify-content: space-between;
113 gap: 12px;
114 padding: 8px 14px 8px 28px;
115 border-top: 1px solid var(--vp-c-divider);
116}
117.ext-repo-variant-label {
118 font-size: 13px;
119 color: var(--vp-c-text-2);
120}
121</style>
docs/.vitepress/theme/components/extrepo/SettingsMenu.vue +133 −61
@@ -1,13 +1,11 @@
11<script setup lang="ts">
2import { nextTick, onMounted, onUnmounted, ref } from 'vue'
2import { computed, nextTick, onMounted, onUnmounted, ref } from 'vue'
33import BrokenFilter from './BrokenFilter.vue'
4import ContentTypeFilter from './ContentTypeFilter.vue'
5import LangSelect from './LangSelect.vue'
6import RatingFilter from './RatingFilter.vue'
7import TypeSelect from './TypeSelect.vue'
4import FilterSelect, { type FilterOption } from './FilterSelect.vue'
5import { contentTypeLabel, langFlagClass, langLabel } from './helpers'
86import type { RatingFilter as RatingFilterValue } from './types'
97
10defineProps<{
8const props = defineProps<{
119 langFilter: string
1210 ratingFilter: RatingFilterValue
1311 availableLangs: string[]
@@ -17,12 +15,6 @@ defineProps<{
1715 contentTypeFilter: string
1816 availableContentTypes: string[]
1917 hasContentTypes: boolean
20 streamTypeFilter: Set<string>
21 availableStreamTypes: string[]
22 hasStreamTypes: boolean
23 qualityFilter: Set<string>
24 availableQualities: string[]
25 hasQualities: boolean
2618 showBroken: boolean
2719 hasBroken: boolean
2820}>()
@@ -31,8 +23,6 @@ defineEmits<{
3123 'update:langFilter': [value: string]
3224 'update:ratingFilter': [value: RatingFilterValue]
3325 'update:contentTypeFilter': [value: string]
34 'update:streamTypeFilter': [value: Set<string>]
35 'update:qualityFilter': [value: Set<string>]
3626 'update:showBroken': [value: boolean]
3727}>()
3828
@@ -41,18 +31,23 @@ const btnRef = ref<HTMLElement>()
4131const menuRef = ref<HTMLElement>()
4232const open = ref(false)
4333const menuStyle = ref<Record<string, string>>({})
34let raf = 0
4435
4536function updatePosition() {
4637 if (!btnRef.value) return
47
4838 const viewportMargin = 12
4939 const menuWidth = menuRef.value?.offsetWidth ?? 260
5040 const btnRect = btnRef.value.getBoundingClientRect()
51 const maxLeft = Math.max(viewportMargin, window.innerWidth - viewportMargin - menuWidth)
52 const left = Math.min(Math.max(btnRect.right - menuWidth, viewportMargin), maxLeft)
41 const maxLeft = Math.max(
42 viewportMargin,
43 window.innerWidth - viewportMargin - menuWidth
44 )
45 const left = Math.min(
46 Math.max(btnRect.right - menuWidth, viewportMargin),
47 maxLeft
48 )
5349 const maxTop = Math.max(viewportMargin, window.innerHeight - viewportMargin)
5450 const top = Math.min(btnRect.bottom + 6, maxTop)
55
5651 menuStyle.value = { top: `${top}px`, left: `${left}px` }
5752}
5853
@@ -64,28 +59,74 @@ function toggle() {
6459function onDocClick(e: MouseEvent) {
6560 const target = e.target as Node
6661 if (
67 rootRef.value && !rootRef.value.contains(target)
68 && menuRef.value && !menuRef.value.contains(target)
62 rootRef.value && !rootRef.value.contains(target) &&
63 menuRef.value && !menuRef.value.contains(target)
6964 ) {
7065 open.value = false
7166 }
7267}
7368
7469function onReposition() {
75 if (open.value) updatePosition()
70 if (!open.value || raf) return
71 raf = requestAnimationFrame(() => {
72 raf = 0
73 updatePosition()
74 })
7675}
7776
7877onMounted(() => {
7978 document.addEventListener('click', onDocClick, true)
80 window.addEventListener('resize', onReposition)
81 window.addEventListener('scroll', onReposition, true)
79 window.addEventListener('resize', onReposition, { passive: true })
80 window.addEventListener('scroll', onReposition, {
81 capture: true,
82 passive: true
83 })
8284})
8385
8486onUnmounted(() => {
8587 document.removeEventListener('click', onDocClick, true)
8688 window.removeEventListener('resize', onReposition)
8789 window.removeEventListener('scroll', onReposition, true)
90 if (raf) cancelAnimationFrame(raf)
8891})
92
93const langOptions = computed<FilterOption[]>(() => [
94 { value: '', label: 'All languages' },
95 ...(props.hasMultiLanguage
96 ? [{ value: 'all', label: 'Multi-language', flag: langFlagClass('all') }]
97 : []),
98 ...props.availableLangs.map(lang => ({
99 value: lang,
100 label: langLabel(lang),
101 flag: langFlagClass(lang)
102 }))
103])
104const langTrigger = computed(() =>
105 props.langFilter ? langLabel(props.langFilter) : 'All languages'
106)
107
108const ratingOptions = computed<FilterOption[]>(() => {
109 const opts: FilterOption[] = [
110 { value: 'all', label: 'All' },
111 { value: 'safe', label: 'Safe' }
112 ]
113 if (props.hasSuggestive) opts.push({ value: 'suggestive', label: 'Mature' })
114 opts.push({ value: 'nsfw', label: props.hasSuggestive ? 'Adult' : 'NSFW' })
115 return opts
116})
117
118const typeOptions = computed<FilterOption[]>(() => [
119 { value: '', label: 'All types' },
120 ...props.availableContentTypes.map(t => ({
121 value: t,
122 label: contentTypeLabel(t)
123 }))
124])
125const typeTrigger = computed(() =>
126 props.contentTypeFilter
127 ? contentTypeLabel(props.contentTypeFilter)
128 : 'All types'
129)
89130</script>
90131
91132<template>
@@ -107,46 +148,61 @@ onUnmounted(() => {
107148 v-show="open"
108149 ref="menuRef"
109150 class="ext-settings-menu VPMenu"
110 :class="{ 'ext-settings-menu--wide': hasSuggestive || hasContentTypes || hasStreamTypes || hasQualities }"
151 :class="{
152 'ext-settings-menu--wide': hasSuggestive || hasContentTypes
153 }"
111154 :style="menuStyle"
112155 >
113 <LangSelect
156 <FilterSelect
114157 v-if="availableLangs.length > 0"
115158 :model-value="langFilter"
116 :available-langs="availableLangs"
117 :has-multi-language="hasMultiLanguage"
159 :options="langOptions"
160 :trigger-label="langTrigger"
161 title="Language"
162 icon="i-lucide:languages"
163 help-text="Filters extensions by translated language (not original language)."
118164 @update:model-value="$emit('update:langFilter', $event)"
119165 />
120 <RatingFilter
166 <FilterSelect
121167 v-if="hasRatings"
122168 :model-value="ratingFilter"
123 :has-suggestive="hasSuggestive"
124 @update:model-value="$emit('update:ratingFilter', $event)"
125 />
126 <TypeSelect
169 :options="ratingOptions"
170 title="Rating"
171 icon="i-lucide:shield"
172 help-text="Choose the highest content rating to include."
173 @update:model-value="$emit('update:ratingFilter', $event as RatingFilterValue)"
174 >
175 <template #help-extra>
176 <div class="rating-help-options">
177 <div class="rating-help-option">
178 <strong>All</strong>
179 <span>Shows entries at every rating level</span>
180 </div>
181 <div class="rating-help-option">
182 <strong>Safe</strong>
183 <span>Only entries with no mature content</span>
184 </div>
185 <div v-if="hasSuggestive" class="rating-help-option">
186 <strong>Mature</strong>
187 <span>Includes suggestive content</span>
188 </div>
189 <div class="rating-help-option">
190 <strong>{{ hasSuggestive ? 'Adult' : 'NSFW' }}</strong>
191 <span>Includes explicit adult content</span>
192 </div>
193 </div>
194 </template>
195 </FilterSelect>
196 <FilterSelect
127197 v-if="hasContentTypes"
128198 :model-value="contentTypeFilter"
129 :available-types="availableContentTypes"
199 :options="typeOptions"
200 :trigger-label="typeTrigger"
201 title="Type"
202 icon="i-lucide:tags"
203 help-text="Filters extensions by type."
130204 @update:model-value="$emit('update:contentTypeFilter', $event)"
131205 />
132 <ContentTypeFilter
133 v-if="hasStreamTypes"
134 :model-value="streamTypeFilter"
135 :available-types="availableStreamTypes"
136 title="Stream Type"
137 icon="i-lucide:cast"
138 help-text="Shows or hides specific stream types. Unchecking a type hides matching entries from the list."
139 @update:model-value="$emit('update:streamTypeFilter', $event)"
140 />
141 <ContentTypeFilter
142 v-if="hasQualities"
143 :model-value="qualityFilter"
144 :available-types="availableQualities"
145 title="Quality"
146 icon="i-lucide:monitor"
147 help-text="Shows or hides specific quality levels. Unchecking a quality hides matching entries from the list."
148 @update:model-value="$emit('update:qualityFilter', $event)"
149 />
150206 <BrokenFilter
151207 v-if="hasBroken"
152208 :model-value="showBroken"
@@ -161,7 +217,6 @@ onUnmounted(() => {
161217.ext-settings {
162218 position: relative;
163219}
164
165220.ext-settings-btn {
166221 display: flex;
167222 align-items: center;
@@ -177,32 +232,28 @@ onUnmounted(() => {
177232 cursor: pointer;
178233 transition: opacity 0.25s, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
179234}
180
181235.ext-settings-btn:hover,
182236.ext-settings-btn[aria-expanded="true"] {
183237 color: var(--vp-c-text-1);
184238 opacity: 1;
185239 background: transparent;
186240}
187
188241.ext-settings-btn:active {
189242 transform: scale(0.94);
190243}
191
192244.ext-settings-btn span {
193245 font-size: 15px;
194246}
195
196247html.effects-disabled .ext-settings-btn {
197248 transition: none;
198249}
199
200250html.effects-disabled .ext-settings-btn:active {
201251 transform: none;
202252}
203
204253.ext-settings-menu {
205 --vp-nolebase-enhanced-readabilities-menu-background-color: var(--wk-c-menu-bg);
254 --vp-nolebase-enhanced-readabilities-menu-background-color: var(
255 --wk-c-menu-bg
256 );
206257 --vp-nolebase-enhanced-readabilities-menu-text-color: var(--vp-c-text-1);
207258 position: fixed;
208259 z-index: 100;
@@ -216,12 +267,33 @@ html.effects-disabled .ext-settings-btn:active {
216267 background-color: var(--vp-c-bg-elv);
217268 box-shadow: var(--vp-shadow-3, 0 4px 16px rgba(0, 0, 0, 0.3));
218269}
219
220270.ext-settings-menu > * + * {
221271 margin-top: 14px;
222272}
223
224273.ext-settings-menu--wide {
225274 width: 320px;
226275}
276.rating-help-options {
277 display: flex;
278 flex-direction: column;
279 gap: 5px;
280}
281.rating-help-option {
282 display: flex;
283 flex-direction: column;
284 gap: 4px;
285 background: var(--wk-c-menu-bg);
286 border-radius: 12px;
287 padding: 10px 12px;
288}
289.rating-help-option strong {
290 font-size: 0.875rem;
291 font-weight: 600;
292 color: var(--vp-c-text-1);
293}
294.rating-help-option span {
295 font-size: 0.875rem;
296 color: var(--vp-c-text-2);
297 line-height: 1.4;
298}
227299</style>
docs/.vitepress/theme/components/extrepo/SiteCell.vue +49 −101
@@ -1,27 +1,23 @@
11<script setup lang="ts">
2import { ref } from 'vue'
32import { langFlagClass, ratingIcon, ratingTitle } from './helpers'
43import { hasCopyButton } from './install'
54import LazyIcon from './LazyIcon.vue'
65import type { RepoSite } from './types'
6import { useCopy } from './useCopy'
77import { useTooltip } from './useTooltip'
88
99const { show: showTooltip, hide: hideTooltip } = useTooltip()
10const { copiedKey, copy } = useCopy()
1011
1112const props = defineProps<{
1213 site: RepoSite & { repoName?: string }
1314 scheme?: string
1415}>()
1516
16const copied = ref(false)
17
1817async function copyInstallUrl() {
19 const soraMatch = props.site.installUrl?.match(/^sora:\/\/module\?url=(.+)$/)
20 const value = soraMatch ? soraMatch[1] : props.site.installUrl
18 const value = props.site.installUrl
2119 if (!value) return
22 await navigator.clipboard.writeText(value)
23 copied.value = true
24 setTimeout(() => { copied.value = false }, 1500)
20 await copy(value, value)
2521}
2622</script>
2723
@@ -36,23 +32,60 @@ async function copyInstallUrl() {
3632 :rel="site.url ? 'noopener noreferrer' : undefined"
3733 >
3834 <div class="ext-site-row">
39 <LazyIcon class="ext-site-icon" :src="site.icon" :alt="site.name" />
40 <span class="ext-site-name-text" :aria-label="site.name" @mouseenter="showTooltip($event, site.name)" @mouseleave="hideTooltip"><span class="ext-site-name-inner">{{ site.name }}</span></span>
41 <span v-if="site.rating !== 'safe'" class="ext-site-nsfw" :class="ratingIcon(site.rating)" :aria-label="ratingTitle(site.rating)" @mouseenter="showTooltip($event, ratingTitle(site.rating))" @mouseleave="hideTooltip" />
42 <span class="ext-site-lang" :class="langFlagClass(site.lang)" :aria-label="site.lang" @mouseenter="showTooltip($event, site.lang)" @mouseleave="hideTooltip" />
35 <LazyIcon :src="site.icon" :alt="site.name" />
36 <span
37 class="ext-site-name-text"
38 :aria-label="site.name"
39 @mouseenter="showTooltip($event, site.name)"
40 @mouseleave="hideTooltip"
41 ><span class="ext-site-name-inner">{{ site.name }}</span></span>
42 <span
43 v-if="site.rating !== 'safe'"
44 class="ext-site-nsfw"
45 :class="ratingIcon(site.rating)"
46 :aria-label="ratingTitle(site.rating)"
47 @mouseenter="showTooltip($event, ratingTitle(site.rating))"
48 @mouseleave="hideTooltip"
49 />
50 <span
51 class="ext-site-lang"
52 :class="langFlagClass(site.lang)"
53 :aria-label="site.lang"
54 @mouseenter="showTooltip($event, site.lang)"
55 @mouseleave="hideTooltip"
56 />
4357 </div>
44 <span v-if="site.repoName" class="ext-site-repo">{{ site.repoName }}</span>
58 <span v-if="site.repoName" class="ext-site-repo">{{
59 site.repoName
60 }}</span>
4561 </component>
46 <a v-if="site.installUrl" class="ext-site-install-btn" :href="site.installUrl" :aria-label="`Install ${site.name}`" @mouseenter="showTooltip($event, `Install ${site.name}`)" @mouseleave="hideTooltip">
62 <a
63 v-if="site.installUrl"
64 class="ext-site-install-btn"
65 :href="site.installUrl"
66 :aria-label="`Install ${site.name}`"
67 @mouseenter="showTooltip($event, `Install ${site.name}`)"
68 @mouseleave="hideTooltip"
69 >
4770 <span class="i-lucide:download" />
4871 </a>
49 <button v-if="site.installUrl && hasCopyButton(scheme ?? '')" class="ext-site-copy-btn" type="button" :aria-label="`Copy ${site.name} url`" @mouseenter="showTooltip($event, `Copy ${site.name} url`)" @mouseleave="hideTooltip" @click="copyInstallUrl">
50 <span v-if="copied" class="i-lucide:check" />
72 <button
73 v-if="site.installUrl && hasCopyButton(scheme ?? '')"
74 class="ext-site-copy-btn"
75 type="button"
76 :aria-label="`Copy ${site.name} url`"
77 @mouseenter="showTooltip($event, `Copy ${site.name} url`)"
78 @mouseleave="hideTooltip"
79 @click="copyInstallUrl"
80 >
81 <span v-if="copiedKey === site.installUrl" class="i-lucide:check" />
5182 <span v-else class="i-lucide:copy" />
5283 </button>
5384 </div>
5485</template>
5586
87<style scoped src="./siteCellShared.css"></style>
88
5689<style scoped>
5790.ext-site-cell-wrap {
5891 display: flex;
@@ -60,97 +93,17 @@ async function copyInstallUrl() {
6093 gap: 4px;
6194 min-width: 0;
6295}
63
64.ext-site-repo {
65 display: block;
66 padding-left: 24px;
67 font-size: 10.5px;
68 font-weight: 400;
69 line-height: 1.1;
70 color: var(--vp-c-text-2);
71 white-space: nowrap;
72 overflow: hidden;
73 text-overflow: ellipsis;
74}
75
76.ext-site-cell {
77 flex: 1;
78 display: flex;
79 flex-direction: column;
80 gap: 0;
81 padding: 6px 8px;
82 border-radius: 6px;
83 border: 1px solid var(--vp-c-divider);
84 background-color: var(--vp-c-bg-soft);
85 min-width: 0;
86 color: var(--vp-c-text-1) !important;
87 text-decoration: none !important;
88 transition: border-color 0.2s, background-color 0.2s;
89}
90
91.ext-site-row {
92 display: flex;
93 align-items: center;
94 gap: 6px;
95 min-width: 0;
96}
97
9896.ext-site-cell:hover {
9997 border-color: var(--vp-c-brand-1);
10098 background-color: var(--vp-c-bg);
10199}
102
103100.ext-site-cell-static {
104101 cursor: default;
105102}
106
107103.ext-site-cell-static:hover {
108104 border-color: var(--vp-c-divider);
109105 background-color: var(--vp-c-bg-soft);
110106}
111
112.ext-site-icon {
113 width: 18px;
114 height: 18px;
115 border-radius: 4px;
116 flex-shrink: 0;
117 object-fit: contain;
118}
119
120.ext-site-icon-fallback {
121 display: flex;
122 align-items: center;
123 justify-content: center;
124 color: var(--vp-c-text-3);
125}
126
127.ext-site-icon-loading {
128 background-color: var(--vp-c-bg-mute, var(--vp-c-bg-soft));
129}
130
131.ext-site-name-text {
132 display: block;
133 flex: 1;
134 min-width: 0;
135}
136
137.ext-site-name-inner {
138 display: block;
139 font-size: 12.5px;
140 font-weight: 600;
141 line-height: 1.2;
142 color: var(--vp-c-text-1);
143 white-space: nowrap;
144 overflow: hidden;
145 text-overflow: ellipsis;
146}
147
148.ext-site-nsfw,
149.ext-site-lang {
150 flex-shrink: 0;
151 font-size: 12px;
152}
153
154107.ext-site-install-btn {
155108 flex-shrink: 0;
156109 display: flex;
@@ -164,16 +117,13 @@ async function copyInstallUrl() {
164117 text-decoration: none !important;
165118 transition: filter 0.2s, border-color 0.2s;
166119}
167
168120.ext-site-install-btn:hover {
169121 filter: brightness(1.08);
170122 border-color: var(--vp-button-brand-hover-border);
171123}
172
173124.ext-site-install-btn span {
174125 font-size: 15px;
175126}
176
177127.ext-site-copy-btn {
178128 flex-shrink: 0;
179129 display: flex;
@@ -187,11 +137,9 @@ async function copyInstallUrl() {
187137 cursor: pointer;
188138 transition: border-color 0.2s, background-color 0.2s;
189139}
190
191140.ext-site-copy-btn:hover {
192141 border-color: var(--vp-c-brand-1);
193142}
194
195143.ext-site-copy-btn span {
196144 font-size: 15px;
197145}
docs/.vitepress/theme/components/extrepo/SiteGrid.vue +51 −23
@@ -1,5 +1,7 @@
11<script setup lang="ts">
2import { computed, ref } from 'vue'
2import { computed, ref, watch } from 'vue'
3import { SITE_GRID_PAGE_SIZE } from './constants'
4import { groupSites } from './groupSites'
35import SiteCell from './SiteCell.vue'
46import SiteGroupCell from './SiteGroupCell.vue'
57import type { RepoSite } from './types'
@@ -10,24 +12,7 @@ const props = defineProps<{
1012 scheme?: string
1113}>()
1214
13interface SiteGroup {
14 key: string
15 sites: (RepoSite & { repoName?: string })[]
16}
17
18const groups = computed<SiteGroup[]>(() => {
19 const map = new Map<string, SiteGroup>()
20 props.sites.forEach((site, i) => {
21 const key = site.url ? `${site.repoName ?? ''}-${site.url}` : `no-url-${i}`
22 let group = map.get(key)
23 if (!group) {
24 group = { key, sites: [] }
25 map.set(key, group)
26 }
27 group.sites.push(site)
28 })
29 return [...map.values()]
30})
15const groups = computed(() => groupSites(props.sites))
3116
3217const openGroups = ref<Set<string>>(new Set())
3318
@@ -37,6 +22,20 @@ function toggleGroup(key: string) {
3722 else next.add(key)
3823 openGroups.value = next
3924}
25
26const visibleCount = ref(SITE_GRID_PAGE_SIZE)
27watch(() => props.sites, () => {
28 visibleCount.value = SITE_GRID_PAGE_SIZE
29})
30
31const visibleGroups = computed(() => groups.value.slice(0, visibleCount.value))
32const remaining = computed(() =>
33 groups.value.length - visibleGroups.value.length
34)
35
36function showMore() {
37 visibleCount.value += SITE_GRID_PAGE_SIZE
38}
4039</script>
4140
4241<template>
@@ -44,8 +43,12 @@ function toggleGroup(key: string) {
4443 <div v-if="sites.length === 0" class="ext-site-empty">
4544 {{ emptyText }}
4645 </div>
47 <template v-for="group in groups" :key="group.key">
48 <SiteCell v-if="group.sites.length === 1" :site="group.sites[0]" :scheme="scheme" />
46 <template v-for="group in visibleGroups" :key="group.key">
47 <SiteCell
48 v-if="group.sites.length === 1"
49 :site="group.sites[0]"
50 :scheme="scheme"
51 />
4952 <template v-else>
5053 <SiteGroupCell
5154 :sites="group.sites"
@@ -53,10 +56,23 @@ function toggleGroup(key: string) {
5356 @toggle="toggleGroup(group.key)"
5457 />
5558 <template v-if="openGroups.has(group.key)">
56 <SiteCell v-for="site in group.sites" :key="`${group.key}-${site.lang}`" :site="site" :scheme="scheme" />
59 <SiteCell
60 v-for="(site, j) in group.sites"
61 :key="`${group.key}::${site.lang}::${j}`"
62 :site="site"
63 :scheme="scheme"
64 />
5765 </template>
5866 </template>
5967 </template>
68 <button
69 v-if="remaining > 0"
70 type="button"
71 class="ext-site-more"
72 @click="showMore"
73 >
74 Show more ({{ remaining }} remaining)
75 </button>
6076 </div>
6177</template>
6278
@@ -70,11 +86,23 @@ function toggleGroup(key: string) {
7086 overflow-y: auto;
7187 background-color: var(--vp-c-bg);
7288}
73
7489.ext-site-empty {
7590 grid-column: 1 / -1;
7691 color: var(--vp-c-text-2);
7792 font-size: 13px;
7893 padding: 8px 4px;
7994}
95.ext-site-more {
96 grid-column: 1 / -1;
97 padding: 8px;
98 border-radius: 8px;
99 border: 1px solid var(--vp-c-divider);
100 background-color: var(--vp-c-bg-soft);
101 color: var(--vp-c-text-1);
102 font-size: 13px;
103 cursor: pointer;
104}
105.ext-site-more:hover {
106 border-color: var(--vp-c-brand-1);
107}
80108</style>
docs/.vitepress/theme/components/extrepo/SiteGroupCell.vue +14 −82
@@ -17,8 +17,10 @@ defineEmits<{
1717}>()
1818
1919const primary = computed(() => props.sites[0])
20const highestRated = computed(() => props.sites.find(site => site.rating === 'nsfw')
21 ?? props.sites.find(site => site.rating === 'suggestive'))
20const highestRated = computed(() =>
21 props.sites.find(site => site.rating === 'nsfw') ??
22 props.sites.find(site => site.rating === 'suggestive')
23)
2224
2325const groupName = computed(() => {
2426 const wordLists = props.sites.map(site => site.name.trim().split(/\s+/))
@@ -32,7 +34,10 @@ const groupName = computed(() => {
3234 if (common.length > 0) return common.join(' ')
3335
3436 const label = langLabel(primary.value.lang)
35 const stripped = primary.value.name.replace(new RegExp(`\\s*${label}$`, 'i'), '').trim()
37 const stripped = primary.value.name.replace(
38 new RegExp(`\\s*${label}$`, 'i'),
39 ''
40 ).trim()
3641 return stripped || primary.value.name
3742})
3843</script>
@@ -47,7 +52,7 @@ const groupName = computed(() => {
4752 @click="$emit('toggle')"
4853 >
4954 <div class="ext-site-row">
50 <LazyIcon class="ext-site-icon" :src="primary.icon" :alt="primary.name" />
55 <LazyIcon :src="primary.icon" :alt="primary.name" />
5156 <span
5257 class="ext-site-name-text"
5358 :aria-label="groupName"
@@ -69,100 +74,27 @@ const groupName = computed(() => {
6974 @mouseleave="hideTooltip"
7075 />
7176 </div>
72 <span v-if="primary.repoName" class="ext-site-repo">{{ primary.repoName }}</span>
77 <span v-if="primary.repoName" class="ext-site-repo">{{
78 primary.repoName
79 }}</span>
7380 </button>
7481</template>
7582
76<style scoped>
77.ext-site-cell {
78 display: flex;
79 flex-direction: column;
80 gap: 0;
81 padding: 6px 8px;
82 border-radius: 6px;
83 border: 1px solid var(--vp-c-divider);
84 background-color: var(--vp-c-bg-soft);
85 min-width: 0;
86 color: var(--vp-c-text-1) !important;
87 text-decoration: none !important;
88 transition: border-color 0.2s, background-color 0.2s;
89}
83<style scoped src="./siteCellShared.css"></style>
9084
85<style scoped>
9186.ext-site-group {
9287 width: 100%;
9388 font: inherit;
9489 text-align: left;
9590 cursor: pointer;
9691}
97
9892.ext-site-group:hover,
9993.ext-site-group-active {
10094 border-color: var(--vp-c-brand-1);
10195 background-color: var(--vp-c-bg);
10296}
103
104.ext-site-row {
105 display: flex;
106 align-items: center;
107 gap: 6px;
108 min-width: 0;
109}
110
111.ext-site-icon {
112 width: 18px;
113 height: 18px;
114 border-radius: 4px;
115 flex-shrink: 0;
116 object-fit: contain;
117}
118
119.ext-site-icon-fallback {
120 display: flex;
121 align-items: center;
122 justify-content: center;
123 color: var(--vp-c-text-3);
124}
125
126.ext-site-icon-loading {
127 background-color: var(--vp-c-bg-mute, var(--vp-c-bg-soft));
128}
129
130.ext-site-name-text {
131 display: block;
132 flex: 1;
133 min-width: 0;
134}
135
136.ext-site-name-inner {
137 display: block;
138 font-size: 12.5px;
139 font-weight: 600;
140 line-height: 1.2;
141 color: var(--vp-c-text-1);
142 white-space: nowrap;
143 overflow: hidden;
144 text-overflow: ellipsis;
145}
146
147.ext-site-nsfw,
148.ext-site-layers {
149 flex-shrink: 0;
150 font-size: 12px;
151}
152
15397.ext-site-layers {
15498 color: var(--vp-c-brand-1);
15599}
156
157.ext-site-repo {
158 display: block;
159 padding-left: 24px;
160 font-size: 10.5px;
161 font-weight: 400;
162 line-height: 1.1;
163 color: var(--vp-c-text-2);
164 white-space: nowrap;
165 overflow: hidden;
166 text-overflow: ellipsis;
167}
168100</style>
docs/.vitepress/theme/components/extrepo/constants.ts added +13
@@ -0,0 +1,13 @@
1export const SEARCH_DEBOUNCE_MS = 150
2export const SITE_GRID_PAGE_SIZE = 120
3export const ICON_ROOT_MARGIN = '200px'
4export const COPY_RESET_MS = 1500
5export const MAX_CONCURRENT_MOBILE = 6
6export const MAX_CONCURRENT_DESKTOP = 24
7export const STATUS_TICK_MS = 1500
8export const LOAD_TIMEOUT_MS = 30000
9export const CACHE_TTL_MS = 6 * 60 * 60 * 1000
10export const NOT_EXPANDABLE_REPOS = new Set([
11 'MegaRepo',
12 'Shotetsu Compatability'
13])
docs/.vitepress/theme/components/extrepo/groupSites.ts added +25
@@ -0,0 +1,25 @@
1import type { RepoSite } from './types'
2
3export interface SiteGroup {
4 key: string
5 sites: (RepoSite & { repoName?: string })[]
6}
7
8export function groupSites(
9 sites: (RepoSite & { repoName?: string })[]
10): SiteGroup[] {
11 const map = new Map<string, SiteGroup>()
12 for (const site of sites) {
13 const key = site.url
14 ? 'url::' + (site.repoName ?? '') + '::' + site.url
15 : 'nourl::' + site.name + '::' + site.lang + '::' +
16 (site.repoName ?? '') + '::' + site.icon
17 let group = map.get(key)
18 if (!group) {
19 group = { key, sites: [] }
20 map.set(key, group)
21 }
22 group.sites.push(site)
23 }
24 return [...map.values()]
25}
docs/.vitepress/theme/components/extrepo/helpers.ts +61 −16
@@ -1,33 +1,71 @@
1import { LANG_FLAG_FALLBACK, LANG_FLAG_ICONS } from '../../../configs/markdown/langFlags'
1import {
2 LANG_FLAG_FALLBACK,
3 LANG_FLAG_ICONS
4} from '../../../configs/markdown/langFlags'
25import type { Rating } from './types'
36
4export function langFlagClass(lang: string): string {
5 const key = lang.toLowerCase()
6 const icon = LANG_FLAG_ICONS[key] ?? LANG_FLAG_ICONS[key.split('-')[0]] ?? LANG_FLAG_FALLBACK
7 return `i-twemoji-${icon}`
8}
7const flagCache = new Map<string, string>()
8const labelCache = new Map<string, string>()
9const stripCache = new Map<string, string>()
10const contentTypeCache = new Map<string, string>()
911
1012const langDisplayNames = new Intl.DisplayNames(['en'], { type: 'language' })
1113
12export function langLabel(lang: string): string {
13 if (lang.toLowerCase() === 'all') return 'Multi-language'
14 try {
15 return langDisplayNames.of(lang) ?? lang
16 } catch {
17 return lang
14export function langFlagClass(lang: string = 'all'): string {
15 const key = lang.toLowerCase()
16 let hit = flagCache.get(key)
17 if (hit === undefined) {
18 hit = `i-twemoji-${
19 LANG_FLAG_ICONS[key] ?? LANG_FLAG_ICONS[key.split('-')[0]] ??
20 LANG_FLAG_FALLBACK
21 }`
22 flagCache.set(key, hit)
1823 }
24 return hit
25}
26
27export function langLabel(lang: string = 'all'): string {
28 const key = lang.toLowerCase()
29 let hit = labelCache.get(key)
30 if (hit === undefined) {
31 if (key === 'all') hit = 'Multi-language'
32 else {
33 try {
34 hit = langDisplayNames.of(lang) ?? lang
35 } catch {
36 hit = lang
37 }
38 }
39 labelCache.set(key, hit)
40 }
41 return hit
1942}
2043
2144export function stripHtml(html: string): string {
22 return html.replace(/<[^>]*>/g, '').trim()
45 let hit = stripCache.get(html)
46 if (hit === undefined) {
47 hit = html.replace(/<[^>]*>/g, '').trim()
48 if (stripCache.size > 2000) stripCache.clear()
49 stripCache.set(html, hit)
50 }
51 return hit
52}
53
54const ESCAPE_MAP: Record<string, string> = {
55 '&': '&amp;',
56 '<': '&lt;',
57 '>': '&gt;',
58 '"': '&quot;'
2359}
2460
2561export function escapeHtml(text: string): string {
26 return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
62 return text.replace(/[&<>"]/g, c => ESCAPE_MAP[c])
2763}
2864
2965export function ratingIcon(rating: Rating): string {
30 return rating === 'nsfw' ? 'i-twemoji-no-one-under-eighteen' : 'i-twemoji-warning'
66 return rating === 'nsfw'
67 ? 'i-twemoji-no-one-under-eighteen'
68 : 'i-twemoji-warning'
3169}
3270
3371export function ratingTitle(rating: Rating): string {
@@ -35,5 +73,12 @@ export function ratingTitle(rating: Rating): string {
3573}
3674
3775export function contentTypeLabel(type: string): string {
38 return type.toLowerCase().split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ')
76 let hit = contentTypeCache.get(type)
77 if (hit === undefined) {
78 hit = type.toLowerCase().split('_').map(word =>
79 word.charAt(0).toUpperCase() + word.slice(1)
80 ).join(' ')
81 contentTypeCache.set(type, hit)
82 }
83 return hit
3984}
docs/.vitepress/theme/components/extrepo/iconObserver.ts added +41
@@ -0,0 +1,41 @@
1import { ICON_ROOT_MARGIN } from './constants'
2
3const callbacks = new Map<Element, () => void>()
4let observer: IntersectionObserver | undefined
5
6function ensureObserver(): IntersectionObserver | undefined {
7 if (
8 observer || typeof window === 'undefined' ||
9 !('IntersectionObserver' in window)
10 ) return observer
11 observer = new IntersectionObserver((entries) => {
12 for (const entry of entries) {
13 if (!entry.isIntersecting) continue
14 const cb = callbacks.get(entry.target)
15 if (cb) {
16 callbacks.delete(entry.target)
17 observer?.unobserve(entry.target)
18 cb()
19 }
20 }
21 }, { rootMargin: ICON_ROOT_MARGIN })
22 return observer
23}
24
25// Shared observer for all lazy icons; calls cb once when visible.
26export function observeIcon(el: Element, cb: () => void): () => void {
27 const io = ensureObserver()
28 if (!io) {
29 cb()
30 return () => {}
31 }
32 callbacks.set(el, cb)
33 io.observe(el)
34 return () => {
35 callbacks.delete(el)
36 io.unobserve(el)
37 }
38}
39
40// Remembers load results per src so repeated icons skip the queue.
41export const iconResultCache = new Map<string, boolean>()
docs/.vitepress/theme/components/extrepo/iconQueue.ts +17 −8
@@ -1,16 +1,20 @@
1const MAX_CONCURRENT_MOBILE = 6
2const MAX_CONCURRENT_DESKTOP = 24
1import { MAX_CONCURRENT_DESKTOP, MAX_CONCURRENT_MOBILE } from './constants'
32
4function maxConcurrent(): number {
5 if (typeof window === 'undefined') return MAX_CONCURRENT_DESKTOP
6 return window.matchMedia('(max-width: 767px)').matches ? MAX_CONCURRENT_MOBILE : MAX_CONCURRENT_DESKTOP
3let limit = MAX_CONCURRENT_DESKTOP
4if (typeof window !== 'undefined') {
5 const mq = window.matchMedia('(max-width: 767px)')
6 const sync = () => {
7 limit = mq.matches ? MAX_CONCURRENT_MOBILE : MAX_CONCURRENT_DESKTOP
8 }
9 sync()
10 mq.addEventListener('change', sync)
711}
812
913let active = 0
1014const queue: (() => Promise<void>)[] = []
1115
1216function pump() {
13 while (active < maxConcurrent() && queue.length) {
17 while (active < limit && queue.length) {
1418 const job = queue.shift()!
1519 active++
1620 job().finally(() => {
@@ -20,7 +24,12 @@ function pump() {
2024 }
2125}
2226
23export function scheduleIconLoad(load: () => Promise<void>) {
24 queue.push(load)
27// Returns a cancel fn that drops the job if it hasn't started yet.
28export function scheduleIconLoad(load: () => Promise<void>): () => void {
29 let cancelled = false
30 queue.push(() => cancelled ? Promise.resolve() : load())
2531 pump()
32 return () => {
33 cancelled = true
34 }
2635}
docs/.vitepress/theme/components/extrepo/install.ts +42 −16
@@ -14,17 +14,24 @@ interface InstallOpts {
1414 suwatteListUrl?: string
1515}
1616
17const INSTALL_URL_BUILDERS: Record<string, (repo: Repo, opts?: InstallOpts) => string> = {
17const INSTALL_URL_BUILDERS: Record<
18 string,
19 (repo: Repo, opts?: InstallOpts) => string
20> = {
1821 aidoku: repo => `aidoku://addSourceList?url=${repo.indexUrl}`,
1922 mihon: repo => `mihon://extension-store?url=${repo.indexUrl}`,
20 paperback: repo => `paperback://addRepo?displayName=${encodeURIComponent(stripHtml(repo.name))}&url=${paperbackBase(repo.indexUrl)}`,
23 paperback: repo =>
24 `paperback://addRepo?displayName=${
25 encodeURIComponent(stripHtml(repo.name))
26 }&url=${paperbackBase(repo.indexUrl)}`,
2127 suwatte: (repo, opts) => {
2228 const listUrl = opts?.suwatteListUrl ?? suwatteBase(repo.indexUrl)
2329 return opts?.suwatteV6
2430 ? `suwatte://list?url=${listUrl}`
2531 : `suwatte://AddSourceList?list=${encodeURIComponent(listUrl)}`
2632 },
27 cloudstreamrepo: repo => `cloudstreamrepo://${repo.indexUrl.replace(/^https?:\/\//, '')}`,
33 cloudstreamrepo: repo =>
34 `cloudstreamrepo://${repo.indexUrl.replace(/^https?:\/\//, '')}`,
2835 hayase: repo => `hayase://extensions/install?url=${repo.indexUrl}`,
2936 legado: repo => `legado://import/bookSource?src=${repo.indexUrl}`,
3037 lnreader: repo => `lnreader://repo/add?url=${repo.indexUrl}`
@@ -34,12 +41,10 @@ const INSTALL_URL_BUILDERS: Record<string, (repo: Repo, opts?: InstallOpts) => s
3441const MANUAL_ONLY_SCHEMES = new Set(['manual'])
3542
3643// Schemes with no install or copy action
37const BROWSE_ONLY_SCHEMES = new Set(['kotatsu', 'sora', 'echo'])
44const BROWSE_ONLY_SCHEMES = new Set(['kotatsu', 'echo'])
3845
3946const NO_COPY_SCHEMES = new Set(['suwatte', 'echo'])
4047
41const COPYABLE_BROWSE_ONLY_SCHEMES = new Set(['sora'])
42
4348export function isBrowseOnly(scheme: string): boolean {
4449 return BROWSE_ONLY_SCHEMES.has(scheme)
4550}
@@ -48,14 +53,16 @@ export function hasCopyButton(scheme: string): boolean {
4853 return !NO_COPY_SCHEMES.has(scheme)
4954}
5055
51export function hasBrowseOnlyCopyButton(scheme: string): boolean {
52 return COPYABLE_BROWSE_ONLY_SCHEMES.has(scheme)
53}
54
55export function installHref(scheme: string, repo: Repo, opts?: InstallOpts): string | null {
56export function installHref(
57 scheme: string,
58 repo: Repo,
59 opts?: InstallOpts
60): string | null {
5661 const build = INSTALL_URL_BUILDERS[scheme]
5762 if (build) return build(repo, opts)
58 if (MANUAL_ONLY_SCHEMES.has(scheme) || BROWSE_ONLY_SCHEMES.has(scheme)) return null
63 if (MANUAL_ONLY_SCHEMES.has(scheme) || BROWSE_ONLY_SCHEMES.has(scheme)) {
64 return null
65 }
5966 return `${scheme}://add-repo?url=${repo.indexUrl}`
6067}
6168
@@ -67,7 +74,9 @@ export function copyValue(scheme: string, indexUrl: string): string {
6774
6875export function mangayomiHref(repo: Repo, variant: RepoVariant): string {
6976 const params: string[] = []
70 if (repo.repoName) params.push(`repo_name=${encodeURIComponent(repo.repoName)}`)
77 if (repo.repoName) {
78 params.push(`repo_name=${encodeURIComponent(repo.repoName)}`)
79 }
7180 if (repo.repoUrl) params.push(`repo_url=${repo.repoUrl}`)
7281 if (variant.mangaUrl) params.push(`manga_url=${variant.mangaUrl}`)
7382 if (variant.animeUrl) params.push(`anime_url=${variant.animeUrl}`)
@@ -75,12 +84,29 @@ export function mangayomiHref(repo: Repo, variant: RepoVariant): string {
7584 return `mangayomi://add-repo?${params.join('&')}`
7685}
7786
78export function mangayomiLiveContainerHref(repo: Repo, variant: RepoVariant): string {
79 return `livecontainer://open-url?url=${btoa(mangayomiHref(repo, variant))}`
87export function mangayomiLiveContainerHref(
88 repo: Repo,
89 variant: RepoVariant
90): string {
91 return `livecontainer://open-url?url=${
92 b64encodeUnicode(mangayomiHref(repo, variant))
93 }`
94}
95
96// btoa throws on non-latin1 chars, so encode UTF-8 first.
97function b64encodeUnicode(s: string): string {
98 const bytes = new TextEncoder().encode(s)
99 let bin = ''
100 for (let i = 0; i < bytes.length; i += 0x8000) {
101 bin += String.fromCharCode(...bytes.subarray(i, i + 0x8000))
102 }
103 return btoa(bin)
80104}
81105
82106// mangayomi all in one
83107export function mangayomiCopyValue(variant: RepoVariant): string | null {
84 const urls = [variant.mangaUrl, variant.animeUrl, variant.novelUrl].filter(Boolean)
108 const urls = [variant.mangaUrl, variant.animeUrl, variant.novelUrl].filter(
109 Boolean
110 )
85111 return urls.length === 1 ? urls[0]! : null
86112}
docs/.vitepress/theme/components/extrepo/repoRowShared.css added +71
@@ -0,0 +1,71 @@
1.ext-repo-actions {
2 display: flex;
3 align-items: center;
4 gap: 6px;
5 flex-shrink: 0;
6}
7.ext-btn {
8 display: inline-flex;
9 align-items: center;
10 gap: 4px;
11 padding: 5px 10px;
12 border-radius: 8px;
13 border: 1px solid var(--vp-c-divider);
14 background-color: var(--vp-c-bg);
15 color: var(--vp-c-text-1);
16 font-size: 13px;
17 line-height: 1;
18 cursor: pointer;
19 transition: border-color 0.2s, background-color 0.2s, color 0.2s;
20}
21.ext-btn:hover {
22 border-color: var(--vp-c-brand-1);
23}
24.ext-btn-install {
25 background-color: var(--vp-button-brand-bg);
26 color: var(--vp-button-brand-text) !important;
27 border-color: var(--vp-button-brand-border);
28 text-decoration: none !important;
29 font-weight: 600;
30}
31.ext-btn-install:hover {
32 filter: brightness(1.08);
33 border-color: var(--vp-button-brand-hover-border);
34}
35.ext-btn-copy,
36.ext-btn-livecontainer {
37 padding: 5px 8px;
38}
39.ext-btn-toggle {
40 padding: 0;
41 border: none;
42 background: transparent;
43 color: var(--vp-c-text-1);
44}
45.ext-btn-toggle:hover {
46 border-color: transparent;
47 color: var(--vp-c-brand-1);
48}
49.ext-btn-toggle span {
50 font-size: 18px;
51 transition: transform 0.2s;
52}
53.ext-btn-toggle.open span {
54 transform: rotate(180deg);
55}
56.ext-btn-toggle-hidden {
57 visibility: hidden;
58 pointer-events: none;
59}
60.ext-btn-spacer {
61 visibility: hidden;
62 pointer-events: none;
63}
64@media (max-width: 767px) {
65 .ext-btn-install {
66 padding: 5px 8px;
67 }
68 .ext-btn-install-label {
69 display: none;
70 }
71}
docs/.vitepress/theme/components/extrepo/siteCellShared.css added +52
@@ -0,0 +1,52 @@
1.ext-site-cell {
2 flex: 1;
3 display: flex;
4 flex-direction: column;
5 gap: 0;
6 padding: 6px 8px;
7 border-radius: 6px;
8 border: 1px solid var(--vp-c-divider);
9 background-color: var(--vp-c-bg-soft);
10 min-width: 0;
11 color: var(--vp-c-text-1) !important;
12 text-decoration: none !important;
13 transition: border-color 0.2s, background-color 0.2s;
14}
15.ext-site-row {
16 display: flex;
17 align-items: center;
18 gap: 6px;
19 min-width: 0;
20}
21.ext-site-name-text {
22 display: block;
23 flex: 1;
24 min-width: 0;
25}
26.ext-site-name-inner {
27 display: block;
28 font-size: 12.5px;
29 font-weight: 600;
30 line-height: 1.2;
31 color: var(--vp-c-text-1);
32 white-space: nowrap;
33 overflow: hidden;
34 text-overflow: ellipsis;
35}
36.ext-site-nsfw,
37.ext-site-lang,
38.ext-site-layers {
39 flex-shrink: 0;
40 font-size: 12px;
41}
42.ext-site-repo {
43 display: block;
44 padding-left: 24px;
45 font-size: 10.5px;
46 font-weight: 400;
47 line-height: 1.1;
48 color: var(--vp-c-text-2);
49 white-space: nowrap;
50 overflow: hidden;
51 text-overflow: ellipsis;
52}
docs/.vitepress/theme/components/extrepo/types.ts −2
@@ -25,8 +25,6 @@ export interface RepoSite {
2525 url: string
2626 rating: Rating
2727 contentType?: string
28 streamType?: string
29 quality?: string
3028 isBroken?: boolean
3129 installUrl?: string
3230}
docs/.vitepress/theme/components/extrepo/useCopy.ts added +22
@@ -0,0 +1,22 @@
1import { onUnmounted, ref } from 'vue'
2import { COPY_RESET_MS } from './constants'
3
4export function useCopy() {
5 const copiedKey = ref<string | null>(null)
6 let timer: ReturnType<typeof setTimeout> | undefined
7
8 async function copy(key: string, value: string) {
9 await navigator.clipboard.writeText(value)
10 copiedKey.value = key
11 if (timer) clearTimeout(timer)
12 timer = setTimeout(() => {
13 if (copiedKey.value === key) copiedKey.value = null
14 }, COPY_RESET_MS)
15 }
16
17 onUnmounted(() => {
18 if (timer) clearTimeout(timer)
19 })
20
21 return { copiedKey, copy }
22}
docs/.vitepress/theme/components/extrepo/useDropdown.ts added +31
@@ -0,0 +1,31 @@
1import { onMounted, onUnmounted, ref } from 'vue'
2
3export function useDropdown() {
4 const rootRef = ref<HTMLElement>()
5 const open = ref(false)
6
7 function toggle() {
8 open.value = !open.value
9 }
10
11 function onDocClick(e: MouseEvent) {
12 if (rootRef.value && !rootRef.value.contains(e.target as Node)) {
13 open.value = false
14 }
15 }
16
17 function onKey(e: KeyboardEvent) {
18 if (e.key === 'Escape') open.value = false
19 }
20
21 onMounted(() => {
22 document.addEventListener('click', onDocClick, true)
23 document.addEventListener('keydown', onKey)
24 })
25 onUnmounted(() => {
26 document.removeEventListener('click', onDocClick, true)
27 document.removeEventListener('keydown', onKey)
28 })
29
30 return { rootRef, open, toggle }
31}
docs/.vitepress/theme/components/extrepo/useRepoFilter.ts added +80
@@ -0,0 +1,80 @@
1import { computed, type ComputedRef, type Ref } from 'vue'
2import { langLabel } from './helpers'
3import type { MatchedSite, RatingFilter } from './types'
4
5export interface RepoFilterState {
6 query: Ref<string>
7 langFilter: Ref<string>
8 ratingFilter: Ref<RatingFilter>
9 contentTypeFilter: Ref<string>
10 showBroken: Ref<boolean>
11}
12
13export interface IndexedSite extends MatchedSite {
14 hay: string
15}
16
17export function indexSites(sites: MatchedSite[]): IndexedSite[] {
18 return sites.map(site => ({
19 ...site,
20 hay: `${site.name ?? ''} ${site.url ?? ''}`.toLowerCase()
21 }))
22}
23
24export function useRepoFilter(
25 allSites: ComputedRef<IndexedSite[]>,
26 state: RepoFilterState
27) {
28 // Single pass over allSites for every facet + flag.
29 const facets = computed(() => {
30 const contentTypes = new Set<string>()
31 const langs = new Set<string>()
32 let hasRatings = false
33 let hasSuggestive = false
34 let hasMultiLanguage = false
35 let hasBroken = false
36 for (const site of allSites.value) {
37 if (site.contentType) contentTypes.add(site.contentType)
38 if (site.rating !== 'safe') hasRatings = true
39 if (site.rating === 'suggestive') hasSuggestive = true
40 if (site.isBroken) hasBroken = true
41 if (typeof site.lang !== 'string') continue
42 if (site.lang.toLowerCase() === 'all') hasMultiLanguage = true
43 if (site.lang !== 'all') langs.add(site.lang)
44 }
45 return {
46 availableContentTypes: [...contentTypes].sort(),
47 availableLangs: [...langs].sort((a, b) =>
48 langLabel(a).localeCompare(langLabel(b))
49 ),
50 hasRatings,
51 hasSuggestive,
52 hasMultiLanguage,
53 hasBroken
54 }
55 })
56
57 const isFiltering = computed(() => {
58 return state.query.value.trim() !== '' || state.langFilter.value !== '' ||
59 state.ratingFilter.value !== 'all' ||
60 state.contentTypeFilter.value !== ''
61 })
62
63 const filteredSites = computed(() => {
64 const q = state.query.value.trim().toLowerCase()
65 const lang = state.langFilter.value
66 const rating = state.ratingFilter.value
67 const ctype = state.contentTypeFilter.value
68 const showBroken = state.showBroken.value
69 return allSites.value.filter((site) => {
70 if (site.isBroken && !showBroken) return false
71 if (q && !site.hay.includes(q)) return false
72 if (lang && site.lang !== lang) return false
73 if (rating !== 'all' && site.rating !== rating) return false
74 if (ctype && site.contentType !== ctype) return false
75 return true
76 })
77 })
78
79 return { facets, isFiltering, filteredSites }
80}
docs/.vitepress/theme/components/extrepo/useRepoStore.ts added +153
@@ -0,0 +1,153 @@
1import {
2 inject,
3 type InjectionKey,
4 onMounted,
5 provide,
6 type ShallowRef,
7 shallowRef
8} from 'vue'
9import {
10 assembleSchemeData,
11 fetchJsonHttp
12} from '../../../../ext/extensionRepos/parsers'
13import type { ExtensionRepoData } from '../../../../ext/extensionRepos/shared'
14
15import { LOAD_TIMEOUT_MS } from './constants'
16
17export interface RepoStore {
18 store: ShallowRef<ExtensionRepoData | null>
19 loading: ShallowRef<boolean>
20 refreshing: ShallowRef<boolean>
21 refreshFailed: ShallowRef<boolean>
22 loadFailed: ShallowRef<boolean>
23 updatedAt: ShallowRef<number | null>
24 loadMs: ShallowRef<number | null>
25 refresh: () => Promise<void>
26 retry: () => Promise<void>
27}
28
29const KEY: InjectionKey<RepoStore> = Symbol('ext-store')
30
31const schemeModules = import.meta.glob<{ data: ExtensionRepoData }>(
32 '../../../../ext/extensionRepos/*.data.ts'
33)
34
35function emptyData(): ExtensionRepoData {
36 return { sites: {}, echoAuthors: {}, repoLists: {} }
37}
38
39// Never let a hung chunk or upstream fetch spin forever.
40function withTimeout<T>(p: Promise<T>, ms: number): Promise<T | null> {
41 let timer: ReturnType<typeof setTimeout> | undefined
42 const timeout = new Promise<null>((resolve) => {
43 timer = setTimeout(() => resolve(null), ms)
44 })
45 return Promise.race([p, timeout]).finally(() => {
46 if (timer) clearTimeout(timer)
47 })
48}
49
50async function loadSchemeData(scheme: string): Promise<ExtensionRepoData> {
51 const load = schemeModules[`../../../../ext/extensionRepos/${scheme}.data.ts`]
52 if (!load) return emptyData()
53 try {
54 const mod = await load()
55 return mod.data ?? emptyData()
56 } catch {
57 return emptyData()
58 }
59}
60
61export function provideRepoStore(scheme: string): RepoStore {
62 const store = shallowRef<ExtensionRepoData | null>(null)
63 const loading = shallowRef(false)
64 const refreshing = shallowRef(false)
65 const refreshFailed = shallowRef(false)
66 const loadFailed = shallowRef(false)
67 const updatedAt = shallowRef<number | null>(null)
68 const loadMs = shallowRef<number | null>(null)
69
70 async function loadInitial() {
71 if (loading.value) return
72 loading.value = true
73 loadFailed.value = false
74 const t0 = performance.now()
75 try {
76 const data = await withTimeout(loadSchemeData(scheme), LOAD_TIMEOUT_MS)
77 if (data === null) {
78 store.value = emptyData()
79 loadFailed.value = true
80 } else {
81 store.value = data
82 loadFailed.value = Object.keys(data.sites).length === 0
83 }
84 } catch {
85 store.value = emptyData()
86 loadFailed.value = true
87 } finally {
88 loadMs.value = Math.round(performance.now() - t0)
89 loading.value = false
90 }
91 }
92
93 async function refresh() {
94 const prev = store.value
95 if (!prev || refreshing.value) return
96 refreshing.value = true
97 refreshFailed.value = false
98 try {
99 const urls = Object.keys(prev.sites).filter(k => !k.includes('#'))
100 const fresh = await withTimeout(
101 assembleSchemeData(urls, Object.keys(prev.repoLists), fetchJsonHttp),
102 LOAD_TIMEOUT_MS
103 )
104 if (fresh === null) {
105 refreshFailed.value = true
106 return
107 }
108 if (Object.keys(fresh.sites).length === 0 && urls.length > 0) {
109 refreshFailed.value = true
110 return
111 }
112 const sites = { ...prev.sites }
113 for (const u of urls) {
114 if (u in fresh.sites) {
115 for (const k of Object.keys(sites)) {
116 if (k === u || k.startsWith(`${u}#`)) delete sites[k]
117 }
118 }
119 }
120 store.value = {
121 sites: { ...sites, ...fresh.sites },
122 echoAuthors: { ...prev.echoAuthors, ...fresh.echoAuthors },
123 repoLists: { ...prev.repoLists, ...fresh.repoLists }
124 }
125 updatedAt.value = Date.now()
126 } finally {
127 refreshing.value = false
128 }
129 }
130
131 onMounted(loadInitial)
132 const ctx: RepoStore = {
133 store,
134 loading,
135 refreshing,
136 refreshFailed,
137 loadFailed,
138 updatedAt,
139 loadMs,
140 refresh,
141 retry: loadInitial
142 }
143 provide(KEY, ctx)
144 return ctx
145}
146
147export function useRepoStore(): RepoStore {
148 const ctx = inject(KEY)
149 if (!ctx) {
150 throw new Error('useRepoStore() must be used within provideRepoStore()')
151 }
152 return ctx
153}
docs/.vitepress/theme/components/extrepo/useTooltip.ts +17 −3
@@ -1,4 +1,4 @@
1import { inject, provide, ref, type InjectionKey } from 'vue'
1import { inject, type InjectionKey, provide, ref } from 'vue'
22
33interface TooltipState {
44 text: string
@@ -13,11 +13,21 @@ interface TooltipCtx {
1313
1414const KEY: InjectionKey<TooltipCtx> = Symbol('ext-tooltip')
1515
16let hoverable: boolean | undefined
17
18function canHover(): boolean {
19 if (hoverable === undefined) {
20 hoverable = typeof window !== 'undefined' &&
21 window.matchMedia('(hover: hover)').matches
22 }
23 return hoverable
24}
25
1626export function provideTooltip() {
1727 const tooltip = ref<TooltipState | null>(null)
1828
1929 function show(e: MouseEvent, text: string) {
20 if (typeof window === 'undefined' || !window.matchMedia('(hover: hover)').matches) return
30 if (!canHover()) return
2131 const rect = (e.currentTarget as HTMLElement).getBoundingClientRect()
2232 tooltip.value = { text, x: rect.left + rect.width / 2, y: rect.top }
2333 }
@@ -33,6 +43,10 @@ export function provideTooltip() {
3343
3444export function useTooltip(): TooltipCtx {
3545 const ctx = inject(KEY)
36 if (!ctx) throw new Error('useTooltip() must be called within a component tree wrapped by provideTooltip()')
46 if (!ctx) {
47 throw new Error(
48 'useTooltip() must be called within a component tree wrapped by provideTooltip()'
49 )
50 }
3751 return ctx
3852}
docs/.vitepress/theme/globalComponents.ts +5 −1
@@ -1,8 +1,8 @@
11import type { App } from 'vue'
2import { defineAsyncComponent } from 'vue'
23import Authors from './components/Authors.vue'
34import Block from './components/Block.vue'
45import Collapsible from './components/Collapsible.vue'
5import { ExtensionRepos } from './components/extrepo'
66import Fb from './components/Fb.vue'
77import Feedback from './components/Feedback.vue'
88import Highlight from './components/Highlight.vue'
@@ -11,6 +11,10 @@ import MirrorTooltip from './components/MirrorTooltip.vue'
1111import ScrapeTable from './components/ScrapeTable.vue'
1212import Tooltip from './components/Tooltip.vue'
1313
14const ExtensionRepos = defineAsyncComponent(
15 () => import('./components/extrepo').then(m => m.ExtensionRepos)
16)
17
1418export function registerGlobalComponents(app: App) {
1519 app.component('LinkInline', LinkInline)
1620 app.component('hl', Highlight)
docs/ext/extensionRepos.data.ts deleted −979
@@ -1,979 +0,0 @@
1import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
2import { dirname, join } from 'node:path'
3import { fileURLToPath } from 'node:url'
4
5const IGNORED_DIRS = new Set(['node_modules', '.vitepress', '.git'])
6
7export type Rating = 'safe' | 'suggestive' | 'nsfw'
8
9export interface RepoSite {
10 name: string
11 lang: string
12 icon: string
13 url: string
14 rating: Rating
15 contentType?: string
16 streamType?: string
17 quality?: string
18 isBroken?: boolean
19 installUrl?: string
20}
21
22interface MihonIndexSource {
23 id: string
24 name: string
25 language: string
26 homeUrl: string
27 mirrorUrls?: string[]
28}
29
30interface MihonIndexExtension {
31 name: string
32 packageName: string
33 resources: {
34 apkUrl: string
35 iconUrl: string
36 jarUrl: string
37 }
38 extensionLib: string
39 versionCode: string
40 versionName: string
41 contentWarning: string
42 sources: MihonIndexSource[]
43}
44
45interface MihonIndex {
46 name: string
47 badgeLabel: string
48 signingKey: string
49 contact?: {
50 website?: string
51 discord?: string
52 }
53 extensionList: {
54 extensions: MihonIndexExtension[]
55 }
56}
57
58export interface RepoData {
59 sites: RepoSite[]
60 suwatteV6?: boolean
61 suwatteListUrl?: string
62}
63
64interface MihonSource {
65 name: string
66 lang: string
67 baseUrl: string
68}
69
70interface MihonExtension {
71 pkg: string
72 nsfw?: number
73 sources?: MihonSource[]
74}
75
76interface AidokuSource {
77 name: string
78 iconURL: string
79 languages?: string[]
80 contentRating?: number
81 baseURL: string
82}
83
84interface AidokuIndex {
85 sources: AidokuSource[]
86}
87
88interface AidokuLegacySource {
89 name: string
90 icon: string
91 lang: string
92 nsfw?: number
93}
94
95interface PaperbackSource {
96 id: string
97 name: string
98 icon: string
99 language?: string
100 contentRating?: string
101 websiteBaseURL?: string
102}
103
104interface PaperbackIndex {
105 sources: PaperbackSource[]
106 builtWith?: { toolchain?: string }
107}
108
109interface CloudstreamRepo {
110 name?: string
111 pluginLists: string[]
112}
113
114interface CloudstreamRepoListItem {
115 url: string
116 verified?: boolean
117}
118
119export interface RepoListEntry {
120 label: string
121 indexUrl: string
122 repoUrl?: string
123}
124
125interface CloudstreamPlugin {
126 name: string
127 iconUrl?: string
128 language?: string
129}
130
131interface HayaseExtension {
132 name: string
133 icon?: string
134 languages?: string[]
135}
136
137interface LegadoBookSource {
138 bookSourceName: string
139 bookSourceUrl: string
140 bookSourceGroup?: string
141}
142
143interface LNReaderPlugin {
144 name: string
145 lang: string
146 url: string
147 iconUrl?: string
148}
149
150interface MangayomiSource {
151 name: string
152 lang: string
153 baseUrl: string
154 iconUrl?: string
155 isNsfw?: boolean
156}
157
158interface IReaderSource {
159 pkg: string
160 apk: string
161 name: string
162 lang: string
163 nsfw?: boolean
164}
165
166interface SuwatteCatalogSource {
167 name: string
168 website?: string
169 languages?: string[]
170 thumbnail?: string
171 path?: string
172}
173
174interface SuwatteCatalogIndex {
175 listUrl?: string
176 catalogVersion?: number
177 sources: SuwatteCatalogSource[]
178}
179
180// For kotatsu
181interface KotatsuSite {
182 name: string
183 lang: string
184 url: string
185 icon: string
186 contentType: string
187 isBroken: boolean
188}
189
190interface KotatsuIndex {
191 sites: KotatsuSite[]
192}
193
194interface SoraRepoIndexEntry {
195 slug: string
196 name: string
197 source: string
198 path?: string
199 totalSources?: number
200 error?: string
201}
202
203interface SoraRepoIndex {
204 repos: SoraRepoIndexEntry[]
205}
206
207interface SoraModule {
208 sourceName: string
209 iconUrl?: string
210 iconURL?: string
211 language?: string
212 baseUrl?: string
213 scriptUrl?: string
214 scriptURL?: string
215 wotaku_sourceName?: string
216 wotaku_language?: string[]
217 wotaku_type?: string[]
218 wotaku_streamType?: string[]
219 wotaku_quality?: string[]
220}
221
222export interface SoraAuthorRepo {
223 label: string
224 repoUrl?: string
225 indexUrl: string
226}
227
228interface EchoExtension {
229 id: string
230 type: string
231 name: string
232 subtitle?: string
233 iconUrl?: string
234 url?: string
235 updateUrl: string
236}
237
238export interface EchoAuthorRepo {
239 label: string
240 repoUrl?: string
241 indexUrl: string
242}
243
244const EXT_DIR = dirname(fileURLToPath(import.meta.url))
245const DOCS_DIR = join(EXT_DIR, '..')
246const CACHE_DIR = join(EXT_DIR, '../.vitepress/cache/extension-repos')
247const CACHE_TTL_MS = 6 * 60 * 60 * 1000
248
249function findMarkdownFiles(dir: string): string[] {
250 const files: string[] = []
251 for (const entry of readdirSync(dir, { withFileTypes: true })) {
252 if (entry.isDirectory()) {
253 if (!IGNORED_DIRS.has(entry.name)) files.push(...findMarkdownFiles(join(dir, entry.name)))
254 } else if (entry.name.endsWith('.md')) {
255 files.push(join(dir, entry.name))
256 }
257 }
258 return files
259}
260
261function collectIndexUrls(): string[] {
262 const urls = new Set<string>()
263 const blockRe = /:::\s*extrepo[^\n]*\n([\s\S]*?)\n\s*:::/g
264 const rowRe = /^\s*-\s*(raw|manga|anime|novel|data)\s*:\s*(https?:\/\/\S+)\s*$/i
265 const headingRe = /^\s*==\s+.+$/
266 const buildRe = /^\s*--\s+.+$/
267
268 function flushEntry(plainRaws: string[], variantUrls: string[], buildRaws: string[], dataUrls: string[]): void {
269 for (const url of variantUrls) urls.add(url)
270 for (const url of buildRaws) urls.add(url)
271 for (const url of dataUrls) urls.add(url)
272 if (dataUrls.length === 0) {
273 for (const url of plainRaws) urls.add(url)
274 }
275 }
276
277 for (const file of findMarkdownFiles(DOCS_DIR)) {
278 const src = readFileSync(file, 'utf-8')
279
280 let block: RegExpExecArray | null
281 blockRe.lastIndex = 0
282 while ((block = blockRe.exec(src))) {
283 let plainRaws: string[] = []
284 let variantUrls: string[] = []
285 let buildRaws: string[] = []
286 let dataUrls: string[] = []
287 let inEntry = false
288 let inBuild = false
289
290 for (const line of block[1].split('\n')) {
291 if (headingRe.test(line)) {
292 if (inEntry) flushEntry(plainRaws, variantUrls, buildRaws, dataUrls)
293 plainRaws = []
294 variantUrls = []
295 buildRaws = []
296 dataUrls = []
297 inEntry = true
298 inBuild = false
299 continue
300 }
301 if (buildRe.test(line)) {
302 inBuild = true
303 continue
304 }
305 const row = rowRe.exec(line)
306 if (row && inEntry) {
307 const key = row[1].toLowerCase()
308 const url = row[2].trim()
309 if (key === 'data') dataUrls.push(url)
310 else if (key === 'raw') (inBuild ? buildRaws : plainRaws).push(url)
311 else variantUrls.push(url)
312 }
313 }
314 if (inEntry) flushEntry(plainRaws, variantUrls, buildRaws, dataUrls)
315 }
316 }
317 return [...urls]
318}
319
320function cachePathFor(url: string): string {
321 return join(CACHE_DIR, `${Buffer.from(url).toString('base64url')}.json`)
322}
323
324function collectRepoListUrls(): string[] {
325 const urls = new Set<string>()
326 const blockRe = /:::\s*extrepo\s*\{([^}]*)\}/g
327
328 for (const file of findMarkdownFiles(DOCS_DIR)) {
329 const src = readFileSync(file, 'utf-8')
330
331 let match: RegExpExecArray | null
332 blockRe.lastIndex = 0
333 while ((match = blockRe.exec(src))) {
334 const from = match[1].match(/(?:^|\s)from=(?:"([^"]+)"|'([^']+)'|(\S+))/)
335 if (from) urls.add((from[1] ?? from[2] ?? from[3]).trim())
336 }
337 }
338 return [...urls]
339}
340
341function isCloudstreamRepoList(json: unknown): json is Array<string | CloudstreamRepoListItem> {
342 if (!Array.isArray(json) || json.length === 0) return false
343 return json.every(item => {
344 if (typeof item === 'string') return /^https?:\/\//.test(item)
345 if (item && typeof item === 'object') {
346 const rec = item as Record<string, unknown>
347 // LNReader plugins also carry a `url` field — rule those out.
348 if ('name' in rec || 'lang' in rec || 'baseUrl' in rec || 'baseURL' in rec) return false
349 return typeof rec.url === 'string' && /^https?:\/\//.test(rec.url)
350 }
351 return false
352 })
353}
354
355function inferRepoUrl(rawUrl: string): string | undefined {
356 try {
357 const u = new URL(rawUrl)
358 const parts = u.pathname.split('/').filter(Boolean)
359 if (u.hostname === 'raw.githubusercontent.com' && parts.length >= 2) {
360 return `https://github.com/${parts[0]}/${parts[1]}`
361 }
362 const dashRaw = u.pathname.indexOf('/-/raw/')
363 if (dashRaw > 0) return `${u.origin}${u.pathname.slice(0, dashRaw)}`
364 const rawSeg = parts.indexOf('raw')
365 if (rawSeg > 1) return `${u.origin}/${parts.slice(0, rawSeg).join('/')}`
366 } catch {
367 return undefined
368 }
369 return undefined
370}
371
372function inferLabel(rawUrl: string): string {
373 const repoUrl = inferRepoUrl(rawUrl)
374 if (repoUrl) {
375 try {
376 const parts = new URL(repoUrl).pathname.split('/').filter(Boolean)
377 if (parts.length >= 2) return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`
378 if (parts.length === 1) return decodeURIComponent(parts[0])
379 } catch {
380 // fall through to raw-URL fallback below
381 }
382 }
383 try {
384 const parts = new URL(rawUrl).pathname.split('/').filter(Boolean)
385 return decodeURIComponent(parts[parts.length - 2] ?? parts[parts.length - 1] ?? rawUrl)
386 } catch {
387 return rawUrl
388 }
389}
390
391function repoListLabel(indexUrl: string, repoJson: unknown): string {
392 if (repoJson && typeof repoJson === 'object' && !Array.isArray(repoJson)) {
393 const name = (repoJson as { name?: unknown }).name
394 if (typeof name === 'string' && name.trim() !== '') return name.trim()
395 }
396 return inferLabel(indexUrl)
397}
398
399async function fetchIndex(url: string): Promise<unknown> {
400 const cachePath = cachePathFor(url)
401 if (existsSync(cachePath) && Date.now() - statSync(cachePath).mtimeMs < CACHE_TTL_MS) {
402 return JSON.parse(readFileSync(cachePath, 'utf-8'))
403 }
404
405 try {
406 const res = await fetch(url)
407 if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
408 const json = await res.json()
409 mkdirSync(CACHE_DIR, { recursive: true })
410 writeFileSync(cachePath, JSON.stringify(json))
411 return json
412 } catch (err) {
413 if (existsSync(cachePath)) return JSON.parse(readFileSync(cachePath, 'utf-8'))
414 console.warn(`[extrepo] failed to fetch ${url}: ${(err as Error).message}`)
415 return []
416 }
417}
418
419function ratingFromLevel(level: number): Rating {
420 if (level >= 2) return 'nsfw'
421 if (level >= 1) return 'suggestive'
422 return 'safe'
423}
424
425const LANG_ALIASES: Record<string, string> = {
426 jp: 'ja',
427 english: 'en',
428 'bahasa indonesia': 'id',
429 español: 'es',
430 français: 'fr',
431 polski: 'pl',
432 português: 'pt',
433 'tiếng việt': 'vi',
434 türkçe: 'tr',
435 русский: 'ru',
436 українська: 'uk',
437 ไทย: 'th',
438 العربية: 'ar',
439 chinese: 'zh',
440 japanese: 'ja',
441 korean: 'ko',
442 french: 'fr',
443 german: 'de',
444 greek: 'el',
445 indonesian: 'id',
446 italian: 'it',
447 spanish: 'es',
448 turkish: 'tr',
449 polish: 'pl',
450 russian: 'ru',
451 portuguese: 'pt',
452 arabic: 'ar',
453 tamil: 'ta',
454 ukrainian: 'uk',
455 vietnamese: 'vi',
456 thai: 'th',
457 hindi: 'hi',
458 malay: 'ms',
459 serbian: 'sr'
460}
461
462const LANG_SUBSTRING_ALIASES: [RegExp, string][] = [
463 [/日语原版/, 'ja'],
464 [/中文|汉语|漢語|轻小说/, 'zh'],
465 [/日本語/, 'ja'],
466 [/한국어|조선말/, 'ko']
467]
468
469function normalizeLang(lang: string): string {
470 // Strip bidi control marks (e.g. U+200E/U+200F) some indices prepend to lang names.
471 const cleaned = lang.replace(/[‎‏]/g, '').trim()
472 if (cleaned === '') return 'all'
473 const exact = LANG_ALIASES[cleaned.toLowerCase()]
474 if (exact) return exact
475 for (const [re, code] of LANG_SUBSTRING_ALIASES) {
476 if (re.test(cleaned)) return code
477 }
478 const key = cleaned.toLowerCase()
479 return key === 'multi' ? 'all' : key
480}
481
482function toRepoDataMihon(iconBase: string, extensions: MihonExtension[]): RepoSite[] {
483 const seen = new Set<string>()
484 const sites: RepoSite[] = []
485
486 for (const ext of extensions) {
487 const icon = `${iconBase}/icon/${ext.pkg}.png`
488 for (const source of ext.sources ?? []) {
489 const key = `${source.name}::${source.lang}::${source.baseUrl}`
490 if (seen.has(key)) continue
491 seen.add(key)
492 sites.push({ name: source.name, lang: source.lang, icon, url: source.baseUrl, rating: ext.nsfw === 1 ? 'nsfw' : 'safe' })
493 }
494 }
495
496 return sites
497}
498
499function toRepoDataAidoku(iconBase: string, index: AidokuIndex): RepoSite[] {
500 const seen = new Set<string>()
501 const sites: RepoSite[] = []
502
503 for (const source of index.sources ?? []) {
504 const icon = `${iconBase}/${source.iconURL}`
505 const rating = ratingFromLevel(source.contentRating ?? 0)
506 const langs = source.languages?.length ? source.languages : ['all']
507 for (const rawLang of langs) {
508 const lang = normalizeLang(rawLang)
509 const key = `${source.name}::${lang}::${source.baseURL}`
510 if (seen.has(key)) continue
511 seen.add(key)
512 sites.push({ name: source.name, lang, icon, url: source.baseURL, rating })
513 }
514 }
515
516 return sites
517}
518
519function toRepoDataPaperback(iconBase: string, index: PaperbackIndex): RepoSite[] {
520 const seen = new Set<string>()
521 const sites: RepoSite[] = []
522 // Legacy 0.8.x toolchain builds serve icons under `<id>/includes/`
523 const iconDir = index.builtWith?.toolchain?.startsWith('0.8') ? 'includes' : 'static'
524
525 for (const source of index.sources ?? []) {
526 const lang = normalizeLang(source.language ?? 'all')
527 const key = `${source.id}::${lang}`
528 if (seen.has(key)) continue
529 seen.add(key)
530 const icon = `${iconBase}/${source.id}/${iconDir}/${source.icon}`
531 const rating: Rating = source.contentRating === 'ADULT' ? 'nsfw' : source.contentRating === 'MATURE' ? 'suggestive' : 'safe'
532 sites.push({ name: source.name, lang, icon, url: source.websiteBaseURL ?? '', rating })
533 }
534
535 return sites
536}
537
538function normalizeGoogleFaviconUrl(url: string): string {
539 return url.replace('%size%', '64')
540}
541
542async function toRepoDataCloudstream(repo: CloudstreamRepo): Promise<RepoSite[]> {
543 const seen = new Set<string>()
544 const sites: RepoSite[] = []
545
546 const lists = await Promise.all(repo.pluginLists.map(url => fetchIndex(url)))
547 for (const list of lists) {
548 if (!Array.isArray(list)) continue
549 for (const plugin of list as CloudstreamPlugin[]) {
550 if (seen.has(plugin.name)) continue
551 seen.add(plugin.name)
552 const lang = normalizeLang(plugin.language ?? 'all')
553 const icon = plugin.iconUrl ? normalizeGoogleFaviconUrl(plugin.iconUrl) : ''
554 sites.push({ name: plugin.name, lang, icon, url: '', rating: 'safe' })
555 }
556 }
557
558 return sites
559}
560
561function toRepoDataAidokuLegacy(iconBase: string, sources: AidokuLegacySource[]): RepoSite[] {
562 const seen = new Set<string>()
563 const sites: RepoSite[] = []
564
565 for (const source of sources) {
566 const lang = normalizeLang(source.lang)
567 const key = `${source.name}::${lang}`
568 if (seen.has(key)) continue
569 seen.add(key)
570 sites.push({ name: source.name, lang, icon: `${iconBase}/icons/${source.icon}`, url: '', rating: ratingFromLevel(source.nsfw ?? 0) })
571 }
572
573 return sites
574}
575
576function toRepoDataHayase(extensions: HayaseExtension[]): RepoSite[] {
577 const seen = new Set<string>()
578 const sites: RepoSite[] = []
579
580 for (const ext of extensions) {
581 const langs = ext.languages?.length ? ext.languages : ['all']
582 for (const rawLang of langs) {
583 const lang = normalizeLang(rawLang)
584 const key = `${ext.name}::${lang}`
585 if (seen.has(key)) continue
586 seen.add(key)
587 sites.push({ name: ext.name, lang, icon: ext.icon ?? '', url: '', rating: 'safe' })
588 }
589 }
590
591 return sites
592}
593
594function toRepoDataLegado(sources: LegadoBookSource[]): RepoSite[] {
595 const seen = new Set<string>()
596 const sites: RepoSite[] = []
597
598 for (const source of sources) {
599 const lang = normalizeLang(source.bookSourceGroup ?? 'all')
600 const key = `${source.bookSourceName}::${lang}`
601 if (seen.has(key)) continue
602 seen.add(key)
603 sites.push({ name: source.bookSourceName, lang, icon: '', url: source.bookSourceUrl, rating: 'safe' })
604 }
605
606 return sites
607}
608
609function toRepoDataMangayomi(sources: MangayomiSource[]): RepoSite[] {
610 const seen = new Set<string>()
611 const sites: RepoSite[] = []
612
613 for (const source of sources) {
614 const lang = normalizeLang(source.lang)
615 const key = `${source.name}::${lang}`
616 if (seen.has(key)) continue
617 seen.add(key)
618 sites.push({ name: source.name, lang, icon: source.iconUrl ?? '', url: source.baseUrl, rating: source.isNsfw ? 'nsfw' : 'safe' })
619 }
620
621 return sites
622}
623
624function toRepoDataIReader(sources: IReaderSource[]): RepoSite[] {
625 const seen = new Set<string>()
626 const sites: RepoSite[] = []
627
628 for (const source of sources) {
629 const lang = normalizeLang(source.lang)
630 const key = `${source.name}::${lang}`
631 if (seen.has(key)) continue
632 seen.add(key)
633 // No confirmed icon path convention in this repo's format — omit rather than guess wrong.
634 sites.push({ name: source.name, lang, icon: '', url: '', rating: source.nsfw ? 'nsfw' : 'safe' })
635 }
636
637 return sites
638}
639
640function toRepoDataSuwatte(iconBase: string, index: SuwatteCatalogIndex): { sites: RepoSite[]; listUrl: string } {
641 const seen = new Set<string>()
642 const sites: RepoSite[] = []
643
644 const listUrl = index.listUrl ?? iconBase
645 const isV6 = index.catalogVersion === undefined
646
647 for (const source of index.sources ?? []) {
648 const langs = source.languages?.length ? source.languages : ['all']
649 const icon = source.thumbnail
650 ? (/^https?:\/\//i.test(source.thumbnail) ? source.thumbnail : `${iconBase}/assets/${source.thumbnail}`)
651 : ''
652 const installUrl = source.path
653 ? (isV6
654 ? `suwatte://runner?url=${listUrl}&runner=${source.path}`
655 : `suwatte://AddSourceFromList?list=${listUrl}&source=${source.path}`)
656 : undefined
657 for (const rawLang of langs) {
658 const lang = normalizeLang(rawLang)
659 const key = `${source.name}::${lang}`
660 if (seen.has(key)) continue
661 seen.add(key)
662 sites.push({ name: source.name, lang, icon, url: source.website ?? '', rating: 'safe', installUrl })
663 }
664 }
665
666 return { sites, listUrl }
667}
668
669function toRepoDataKotatsu(index: KotatsuIndex): RepoSite[] {
670 const seen = new Set<string>()
671 const sites: RepoSite[] = []
672
673 for (const site of index.sites) {
674 const lang = normalizeLang(site.lang)
675 const key = `${site.name}::${lang}::${site.url}`
676 if (seen.has(key)) continue
677 seen.add(key)
678 const rating: Rating = site.contentType.includes('HENTAI') ? 'nsfw' : 'safe'
679 sites.push({ name: site.name, lang, icon: site.icon, url: site.url, rating, contentType: site.contentType, isBroken: site.isBroken || undefined })
680 }
681
682 return sites
683}
684
685function isSoraRepoIndex(json: unknown): json is SoraRepoIndex {
686 return !!json && typeof json === 'object' && Array.isArray((json as SoraRepoIndex).repos)
687}
688
689function normalizeSoraLang(language: string | undefined): string {
690 const stripped = (language ?? '').replace(/\s*\([^)]*\)\s*$/, '').trim()
691 if (stripped.toLowerCase().startsWith('multi')) return 'all'
692 return normalizeLang(stripped)
693}
694
695function toRepoDataSoraModules(modules: SoraModule[]): RepoSite[] {
696 const seen = new Set<string>()
697 const sites: RepoSite[] = []
698
699 for (const mod of modules) {
700 const name = mod.wotaku_sourceName ?? mod.sourceName
701 const langs = mod.wotaku_language?.length ? mod.wotaku_language : [mod.language]
702 const scriptUrl = mod.scriptUrl ?? mod.scriptURL
703 const installUrl = scriptUrl?.replace(/\.js$/i, '.json')
704 for (const rawLang of langs) {
705 const lang = normalizeSoraLang(rawLang)
706 const key = `${name}::${lang}::${installUrl ?? ''}`
707 if (seen.has(key)) continue
708 seen.add(key)
709 sites.push({
710 name,
711 lang,
712 icon: mod.iconUrl ?? mod.iconURL ?? '',
713 url: mod.baseUrl ?? '',
714 rating: 'safe',
715 contentType: mod.wotaku_type?.[0],
716 streamType: mod.wotaku_streamType?.[0],
717 quality: mod.wotaku_quality?.[0],
718 installUrl: installUrl ? `sora://module?url=${installUrl}` : undefined
719 })
720 }
721 }
722
723 sites.sort((a, b) => a.name.localeCompare(b.name))
724 return sites
725}
726
727async function loadSoraRepoIndex(indexUrl: string, index: SoraRepoIndex): Promise<{ sites: RepoSite[]; authorRepos: SoraAuthorRepo[]; sitesByAuthor: Record<string, RepoData> }> {
728 const seen = new Set<string>()
729 const sites: RepoSite[] = []
730 const authorRepos: SoraAuthorRepo[] = []
731 const sitesByAuthor: Record<string, RepoData> = {}
732
733 const entries = index.repos.filter(repo => repo.path && !repo.error)
734 const fileUrls = entries.map(repo => new URL(repo.path!, indexUrl).toString())
735 const moduleLists = await Promise.all(fileUrls.map(url => fetchIndex(url)))
736
737 entries.forEach((repo, i) => {
738 const modules = moduleLists[i]
739 const authorSites = Array.isArray(modules) ? toRepoDataSoraModules(modules as SoraModule[]) : []
740 const fileUrl = fileUrls[i]
741 sitesByAuthor[fileUrl] = { sites: authorSites }
742 authorRepos.push({ label: repo.name, repoUrl: repo.source?.replace(/\.git$/, ''), indexUrl: fileUrl })
743 for (const site of authorSites) {
744 const key = `${site.name}::${site.lang}::${site.installUrl ?? ''}`
745 if (seen.has(key)) continue
746 seen.add(key)
747 sites.push(site)
748 }
749 })
750
751 authorRepos.sort((a, b) => a.label.localeCompare(b.label))
752 sites.sort((a, b) => a.name.localeCompare(b.name))
753 return { sites, authorRepos, sitesByAuthor }
754}
755
756function isEchoExtensionList(json: unknown): json is EchoExtension[] {
757 if (!Array.isArray(json) || json.length === 0) return false
758 const first = json[0] as Record<string, unknown>
759 return typeof first.updateUrl === 'string' && typeof first.subtitle === 'string' && !('lang' in first) && !('baseUrl' in first)
760}
761
762function parseEchoRepo(updateUrl: string): { host: string; owner: string; repo: string; repoUrl: string; ownerUrl: string } | undefined {
763 const githubMatch = updateUrl.match(/^https:\/\/api\.github\.com\/repos\/([^/]+)\/([^/]+)\/releases$/)
764 if (githubMatch) {
765 const [, owner, repo] = githubMatch
766 return { host: 'github.com', owner, repo, repoUrl: `https://github.com/${owner}/${repo}`, ownerUrl: `https://github.com/${owner}` }
767 }
768
769 const gitlabMatch = updateUrl.match(/^https:\/\/(gitlab\.com)\/api\/v4\/projects\/([^/]+)\/releases\b/)
770 if (gitlabMatch) {
771 const [, host, encodedPath] = gitlabMatch
772 const path = decodeURIComponent(encodedPath)
773 const owner = path.slice(0, path.lastIndexOf('/'))
774 const repo = path.slice(path.lastIndexOf('/') + 1)
775 if (!owner || !repo) return undefined
776 return { host, owner, repo, repoUrl: `https://${host}/${path}`, ownerUrl: `https://${host}/${owner}` }
777 }
778
779 return undefined
780}
781
782function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] {
783 const seen = new Set<string>()
784 const sites: RepoSite[] = []
785
786 for (const ext of extensions) {
787 const key = `${ext.id}::${ext.updateUrl}`
788 if (seen.has(key)) continue
789 seen.add(key)
790 const repo = parseEchoRepo(ext.updateUrl)
791 sites.push({
792 name: ext.name,
793 lang: 'all',
794 icon: ext.iconUrl ?? '',
795 url: ext.url ?? repo?.repoUrl ?? '',
796 rating: 'safe',
797 contentType: ext.type,
798 installUrl: repo?.repoUrl
799 })
800 }
801
802 sites.sort((a, b) => a.name.localeCompare(b.name))
803 return sites
804}
805
806function loadEchoExtensionList(indexUrl: string, extensions: EchoExtension[]): { sites: RepoSite[]; authorRepos: EchoAuthorRepo[]; sitesByAuthor: Record<string, RepoData> } {
807 const byAuthor = new Map<string, { label: string; ownerUrl?: string; exts: EchoExtension[] }>()
808 for (const ext of extensions) {
809 const repo = parseEchoRepo(ext.updateUrl)
810 const key = repo ? `${repo.host}:${repo.owner}` : 'Unknown'
811 const bucket = byAuthor.get(key)
812 if (bucket) bucket.exts.push(ext)
813 else byAuthor.set(key, { label: repo?.owner ?? 'Unknown', ownerUrl: repo?.ownerUrl, exts: [ext] })
814 }
815
816 const authorRepos: EchoAuthorRepo[] = []
817 const sitesByAuthor: Record<string, RepoData> = {}
818 for (const [key, { label, ownerUrl, exts }] of byAuthor) {
819 const authorIndexUrl = `${indexUrl}#${key}`
820 sitesByAuthor[authorIndexUrl] = { sites: toRepoDataEchoExtensions(exts) }
821 authorRepos.push({ label, repoUrl: ownerUrl, indexUrl: authorIndexUrl })
822 }
823
824 authorRepos.sort((a, b) => a.label.localeCompare(b.label))
825 return { sites: toRepoDataEchoExtensions(extensions), authorRepos, sitesByAuthor }
826}
827
828function toRepoDataLNReader(plugins: LNReaderPlugin[]): RepoSite[] {
829 const seen = new Set<string>()
830 const sites: RepoSite[] = []
831
832 for (const plugin of plugins) {
833 const lang = normalizeLang(plugin.lang)
834 const key = `${plugin.name}::${lang}`
835 if (seen.has(key)) continue
836 seen.add(key)
837 sites.push({ name: plugin.name, lang, icon: plugin.iconUrl ?? '', url: plugin.url, rating: 'safe' })
838 }
839
840 return sites
841}
842
843const CONTENT_WARNING_RATING: Record<string, Rating> = {
844 CONTENT_WARNING_NSFW: 'nsfw',
845 CONTENT_WARNING_MIXED: 'suggestive',
846 CONTENT_WARNING_SAFE: 'safe'
847}
848
849function toRepoDataMihonNew(index: MihonIndex): RepoSite[] {
850 const seen = new Set<string>()
851 const sites: RepoSite[] = []
852
853 for (const ext of index.extensionList.extensions) {
854 const icon = ext.resources.iconUrl
855 const rating = CONTENT_WARNING_RATING[ext.contentWarning] ?? 'safe'
856
857 for (const source of ext.sources) {
858 const key = `${source.name}::${source.language}::${source.homeUrl}`
859 if (seen.has(key)) continue
860 seen.add(key)
861 sites.push({ name: source.name, lang: source.language, icon, url: source.homeUrl, rating })
862 }
863 }
864
865 sites.sort((a, b) => a.name.localeCompare(b.name))
866 return sites
867}
868
869async function toRepoData(indexUrl: string, json: unknown): Promise<RepoData> {
870 const iconBase = indexUrl.slice(0, indexUrl.lastIndexOf('/'))
871 let sites: RepoSite[]
872 let suwatteV6: boolean | undefined
873 let suwatteListUrl: string | undefined
874
875 if (
876 json && typeof json === 'object' && !Array.isArray(json)
877 && 'extensionList' in (json as Record<string, unknown>)
878 ) {
879 sites = toRepoDataMihonNew(json as MihonIndex)
880 return { sites }
881 }
882
883 if (Array.isArray(json)) {
884 const first = json[0] as Record<string, unknown> | undefined
885 if (first && 'bookSourceUrl' in first) {
886 sites = toRepoDataLegado(json as LegadoBookSource[])
887 } else if (first && 'manifestVersion' in first) {
888 sites = toRepoDataHayase(json as HayaseExtension[])
889 } else if (first && 'iconUrl' in first && 'site' in first) {
890 sites = toRepoDataLNReader(json as LNReaderPlugin[])
891 } else if (first && 'sources' in first) {
892 sites = toRepoDataMihon(iconBase, json as MihonExtension[])
893 } else if (first && 'pkg' in first && 'apk' in first) {
894 sites = toRepoDataIReader(json as IReaderSource[])
895 } else if (first && 'iconUrl' in first && 'baseUrl' in first) {
896 sites = toRepoDataMangayomi(json as MangayomiSource[])
897 } else {
898 sites = toRepoDataAidokuLegacy(iconBase, json as AidokuLegacySource[])
899 }
900 } else if (Array.isArray((json as CloudstreamRepo).pluginLists)) {
901 sites = await toRepoDataCloudstream(json as CloudstreamRepo)
902 } else if ((json as AidokuIndex).sources?.length && 'iconURL' in (json as AidokuIndex).sources[0]) {
903 sites = toRepoDataAidoku(iconBase, json as AidokuIndex)
904 } else if ((json as SuwatteCatalogIndex).sources?.length && 'thumbnail' in (json as SuwatteCatalogIndex).sources[0]) {
905 const result = toRepoDataSuwatte(iconBase, json as SuwatteCatalogIndex)
906 sites = result.sites
907 suwatteListUrl = result.listUrl
908 suwatteV6 = (json as SuwatteCatalogIndex).catalogVersion === undefined
909 } else if (Array.isArray((json as KotatsuIndex).sites)) {
910 sites = toRepoDataKotatsu(json as KotatsuIndex)
911 } else {
912 sites = toRepoDataPaperback(iconBase, json as PaperbackIndex)
913 }
914 sites.sort((a, b) => a.name.localeCompare(b.name))
915 return { sites, suwatteV6, suwatteListUrl }
916}
917
918export interface ExtensionRepoData {
919 sites: Record<string, RepoData>
920 soraAuthors: Record<string, SoraAuthorRepo[]>
921 echoAuthors: Record<string, EchoAuthorRepo[]>
922 repoLists: Record<string, RepoListEntry[]>
923}
924
925export declare const data: ExtensionRepoData
926
927export default {
928 watch: ['../**/*.md'],
929 async load(): Promise<ExtensionRepoData> {
930 const urls = collectIndexUrls()
931 const listUrls = collectRepoListUrls()
932 const listUrlSet = new Set(listUrls)
933 const sites: Record<string, RepoData> = {}
934 const soraAuthors: Record<string, SoraAuthorRepo[]> = {}
935 const echoAuthors: Record<string, EchoAuthorRepo[]> = {}
936 const repoLists: Record<string, RepoListEntry[]> = {}
937 await Promise.all(listUrls.map(async listUrl => {
938 const json = await fetchIndex(listUrl)
939 if (!isCloudstreamRepoList(json)) {
940 repoLists[listUrl] = []
941 return
942 }
943 const indexUrls = [...new Set(json.map(item => typeof item === 'string' ? item : item.url))]
944 const repoJsons = await Promise.all(indexUrls.map(url => fetchIndex(url)))
945 const entries: RepoListEntry[] = indexUrls.map((indexUrl, i) => ({
946 label: repoListLabel(indexUrl, repoJsons[i]),
947 indexUrl,
948 repoUrl: inferRepoUrl(indexUrl)
949 }))
950 entries.sort((a, b) => a.label.localeCompare(b.label))
951 repoLists[listUrl] = entries
952 await Promise.all(indexUrls.map(async (indexUrl, i) => {
953 if (indexUrl in sites) return
954 sites[indexUrl] = await toRepoData(indexUrl, repoJsons[i])
955 }))
956 }))
957 await Promise.all(urls.map(async url => {
958 if (listUrlSet.has(url)) return
959 if (url in sites) return
960 const json = await fetchIndex(url)
961 if (isSoraRepoIndex(json)) {
962 const result = await loadSoraRepoIndex(url, json)
963 sites[url] = { sites: result.sites }
964 soraAuthors[url] = result.authorRepos
965 Object.assign(sites, result.sitesByAuthor)
966 return
967 }
968 if (isEchoExtensionList(json)) {
969 const result = loadEchoExtensionList(url, json)
970 sites[url] = { sites: result.sites }
971 echoAuthors[url] = result.authorRepos
972 Object.assign(sites, result.sitesByAuthor)
973 return
974 }
975 sites[url] = await toRepoData(url, json)
976 }))
977 return { sites, soraAuthors, echoAuthors, repoLists }
978 }
979}
docs/ext/extensionRepos/aidoku.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('aidoku')
9 }
10}
docs/ext/extensionRepos/aniyomi.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('aniyomi')
9 }
10}
docs/ext/extensionRepos/attrs.ts added +16
@@ -0,0 +1,16 @@
1export function parseExtRepoAttrs(text: string): Record<string, string> {
2 const match = text.match(/\{([^}]*)\}/)
3 if (!match) return {}
4 const attrs: Record<string, string> = {}
5 for (const token of match[1].split(/[\s,]+/).filter(Boolean)) {
6 const eq = token.indexOf('=')
7 if (eq < 0) {
8 attrs[token] = 'true'
9 continue
10 }
11 const key = token.slice(0, eq)
12 const value = token.slice(eq + 1)
13 if (key && value) attrs[key] = value.replace(/^["']|["']$/g, '')
14 }
15 return attrs
16}
docs/ext/extensionRepos/cloudstreamrepo.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('cloudstreamrepo')
9 }
10}
docs/ext/extensionRepos/echo.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('echo')
9 }
10}
docs/ext/extensionRepos/hayase.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('hayase')
9 }
10}
docs/ext/extensionRepos/kotatsu.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('kotatsu')
9 }
10}
docs/ext/extensionRepos/legado.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('legado')
9 }
10}
docs/ext/extensionRepos/lnreader.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('lnreader')
9 }
10}
docs/ext/extensionRepos/mangayomi.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('mangayomi')
9 }
10}
docs/ext/extensionRepos/manual.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('manual')
9 }
10}
docs/ext/extensionRepos/mihon.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('mihon')
9 }
10}
docs/ext/extensionRepos/paperback.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('paperback')
9 }
10}
docs/ext/extensionRepos/parsers.ts added +952
@@ -0,0 +1,952 @@
1import type {
2 Rating,
3 RepoSite
4} from '../../.vitepress/theme/components/extrepo/types'
5
6interface MihonIndexSource {
7 id: string
8 name: string
9 language: string
10 homeUrl: string
11 mirrorUrls?: string[]
12}
13
14interface MihonIndexExtension {
15 name: string
16 packageName: string
17 resources: {
18 apkUrl: string
19 iconUrl: string
20 jarUrl: string
21 }
22 extensionLib: string
23 versionCode: string
24 versionName: string
25 contentWarning: string
26 sources: MihonIndexSource[]
27}
28
29interface MihonIndex {
30 name: string
31 badgeLabel: string
32 signingKey: string
33 contact?: {
34 website?: string
35 discord?: string
36 }
37 extensionList: {
38 extensions: MihonIndexExtension[]
39 }
40}
41
42export interface RepoData {
43 sites: RepoSite[]
44 suwatteV6?: boolean
45 suwatteListUrl?: string
46}
47
48interface MihonSource {
49 name: string
50 lang: string
51 baseUrl: string
52}
53
54interface MihonExtension {
55 pkg: string
56 nsfw?: number
57 sources?: MihonSource[]
58}
59
60interface AidokuSource {
61 name: string
62 iconURL: string
63 languages?: string[]
64 contentRating?: number
65 baseURL: string
66}
67
68interface AidokuIndex {
69 sources: AidokuSource[]
70}
71
72interface AidokuLegacySource {
73 name: string
74 icon: string
75 lang: string
76 nsfw?: number
77}
78
79interface PaperbackSource {
80 id: string
81 name: string
82 icon: string
83 language?: string
84 contentRating?: string
85 websiteBaseURL?: string
86}
87
88interface PaperbackIndex {
89 sources: PaperbackSource[]
90 builtWith?: { toolchain?: string }
91}
92
93interface CloudstreamRepo {
94 name?: string
95 pluginLists: string[]
96}
97
98interface CloudstreamRepoListItem {
99 url: string
100 verified?: boolean
101}
102
103export interface RepoListEntry {
104 label: string
105 indexUrl: string
106 repoUrl?: string
107}
108
109interface CloudstreamPlugin {
110 name: string
111 iconUrl?: string
112 language?: string
113}
114
115interface HayaseExtension {
116 name: string
117 icon?: string
118 languages?: string[]
119}
120
121interface LegadoBookSource {
122 bookSourceName: string
123 bookSourceUrl: string
124 bookSourceGroup?: string
125}
126
127interface LNReaderPlugin {
128 name: string
129 lang: string
130 url: string
131 iconUrl?: string
132}
133
134interface MangayomiSource {
135 name: string
136 lang: string
137 baseUrl: string
138 iconUrl?: string
139 isNsfw?: boolean
140}
141
142interface IReaderSource {
143 pkg: string
144 apk: string
145 name: string
146 lang: string
147 nsfw?: boolean
148}
149
150interface SuwatteCatalogSource {
151 name: string
152 website?: string
153 languages?: string[]
154 thumbnail?: string
155 path?: string
156}
157
158interface SuwatteCatalogIndex {
159 listUrl?: string
160 catalogVersion?: number
161 sources: SuwatteCatalogSource[]
162}
163
164interface KotatsuSite {
165 name: string
166 lang: string
167 url: string
168 icon: string
169 contentType: string
170 isBroken: boolean
171}
172
173interface KotatsuIndex {
174 sites: KotatsuSite[]
175}
176
177interface EchoExtension {
178 id: string
179 type: string
180 name: string
181 subtitle?: string
182 iconUrl?: string
183 url?: string
184 updateUrl: string
185}
186
187export interface EchoAuthorRepo {
188 label: string
189 repoUrl?: string
190 indexUrl: string
191}
192
193const FETCH_TIMEOUT_MS = 15000
194const FETCH_CONCURRENCY = 10
195
196export type FetchJson = (url: string) => Promise<unknown | undefined>
197
198export async function fetchJsonHttp(url: string): Promise<unknown | undefined> {
199 for (let attempt = 0; attempt < 2; attempt++) {
200 const ctrl = new AbortController()
201 const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS)
202 try {
203 const res = await fetch(url, { signal: ctrl.signal })
204 if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
205 return (await res.json()) as unknown
206 } catch {
207 if (attempt === 1) return undefined
208 } finally {
209 clearTimeout(timer)
210 }
211 }
212 return undefined
213}
214
215async function mapLimit<T, R>(
216 items: T[],
217 limit: number,
218 fn: (item: T, i: number) => Promise<R>
219): Promise<R[]> {
220 const out: R[] = new Array(items.length)
221 let next = 0
222 const workers = Array.from(
223 { length: Math.min(limit, items.length) },
224 async () => {
225 while (next < items.length) {
226 const i = next++
227 out[i] = await fn(items[i], i)
228 }
229 }
230 )
231 await Promise.all(workers)
232 return out
233}
234
235function isCloudstreamRepoList(
236 json: unknown
237): json is Array<string | CloudstreamRepoListItem> {
238 if (!Array.isArray(json) || json.length === 0) return false
239 return json.every((item) => {
240 if (typeof item === 'string') return /^https?:\/\//.test(item)
241 if (item && typeof item === 'object') {
242 const rec = item as Record<string, unknown>
243 if (
244 'name' in rec || 'lang' in rec || 'baseUrl' in rec || 'baseURL' in rec
245 ) return false
246 return typeof rec.url === 'string' && /^https?:\/\//.test(rec.url)
247 }
248 return false
249 })
250}
251
252function inferRepoUrl(rawUrl: string): string | undefined {
253 try {
254 const u = new URL(rawUrl)
255 const parts = u.pathname.split('/').filter(Boolean)
256 if (u.hostname === 'raw.githubusercontent.com' && parts.length >= 2) {
257 return `https://github.com/${parts[0]}/${parts[1]}`
258 }
259 const dashRaw = u.pathname.indexOf('/-/raw/')
260 if (dashRaw > 0) return `${u.origin}${u.pathname.slice(0, dashRaw)}`
261 const rawSeg = parts.indexOf('raw')
262 if (rawSeg > 1) return `${u.origin}/${parts.slice(0, rawSeg).join('/')}`
263 } catch {
264 return undefined
265 }
266 return undefined
267}
268
269function inferLabel(rawUrl: string): string {
270 const repoUrl = inferRepoUrl(rawUrl)
271 if (repoUrl) {
272 try {
273 const parts = new URL(repoUrl).pathname.split('/').filter(Boolean)
274 if (parts.length >= 2) {
275 return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`
276 }
277 if (parts.length === 1) return decodeURIComponent(parts[0])
278 } catch {
279 // fall through below
280 }
281 }
282 try {
283 const parts = new URL(rawUrl).pathname.split('/').filter(Boolean)
284 return decodeURIComponent(
285 parts[parts.length - 2] ?? parts[parts.length - 1] ?? rawUrl
286 )
287 } catch {
288 return rawUrl
289 }
290}
291
292function repoListLabel(indexUrl: string, repoJson: unknown): string {
293 if (repoJson && typeof repoJson === 'object' && !Array.isArray(repoJson)) {
294 const name = (repoJson as { name?: unknown }).name
295 if (typeof name === 'string' && name.trim() !== '') return name.trim()
296 }
297 return inferLabel(indexUrl)
298}
299
300function ratingFromLevel(level: number): Rating {
301 if (level >= 2) return 'nsfw'
302 if (level >= 1) return 'suggestive'
303 return 'safe'
304}
305
306const LANG_ALIASES: Record<string, string> = {
307 jp: 'ja',
308 english: 'en',
309 'bahasa indonesia': 'id',
310 español: 'es',
311 français: 'fr',
312 polski: 'pl',
313 português: 'pt',
314 'tiếng việt': 'vi',
315 türkçe: 'tr',
316 русский: 'ru',
317 українська: 'uk',
318 ไทย: 'th',
319 العربية: 'ar',
320 chinese: 'zh',
321 japanese: 'ja',
322 korean: 'ko',
323 french: 'fr',
324 german: 'de',
325 greek: 'el',
326 indonesian: 'id',
327 italian: 'it',
328 spanish: 'es',
329 turkish: 'tr',
330 polish: 'pl',
331 russian: 'ru',
332 portuguese: 'pt',
333 arabic: 'ar',
334 tamil: 'ta',
335 ukrainian: 'uk',
336 vietnamese: 'vi',
337 thai: 'th',
338 hindi: 'hi',
339 malay: 'ms',
340 serbian: 'sr'
341}
342
343const LANG_SUBSTRING_ALIASES: [RegExp, string][] = [
344 [/日语原版/, 'ja'],
345 [/中文|汉语|漢語|轻小说/, 'zh'],
346 [/日本語/, 'ja'],
347 [/한국어|조선말/, 'ko']
348]
349
350const langCache = new Map<string, string>()
351
352function normalizeLang(lang: string): string {
353 const hit = langCache.get(lang)
354 if (hit !== undefined) return hit
355 const cleaned = lang.replace(/[\u200E\u200F]/g, '').trim()
356 let out: string
357 if (cleaned === '') out = 'all'
358 else {
359 const exact = LANG_ALIASES[cleaned.toLowerCase()]
360 if (exact) out = exact
361 else {
362 out = cleaned.toLowerCase()
363 for (const [re, code] of LANG_SUBSTRING_ALIASES) {
364 if (re.test(cleaned)) {
365 out = code
366 break
367 }
368 }
369 if (out === 'multi') out = 'all'
370 }
371 }
372 if (langCache.size > 2000) langCache.clear()
373 langCache.set(lang, out)
374 return out
375}
376
377function sortSites(sites: RepoSite[]): RepoSite[] {
378 return sites.sort((a, b) => a.name.localeCompare(b.name))
379}
380
381function addSite(
382 seen: Set<string>,
383 key: string,
384 sites: RepoSite[],
385 site: RepoSite
386): void {
387 if (seen.has(key)) return
388 seen.add(key)
389 sites.push(site)
390}
391
392function toRepoDataMihon(
393 iconBase: string,
394 extensions: MihonExtension[]
395): RepoSite[] {
396 const seen = new Set<string>()
397 const sites: RepoSite[] = []
398 for (const ext of extensions) {
399 const icon = `${iconBase}/icon/${ext.pkg}.png`
400 for (const source of ext.sources ?? []) {
401 addSite(
402 seen,
403 `${source.name}::${source.lang}::${source.baseUrl}`,
404 sites,
405 {
406 name: source.name ?? ext.pkg,
407 lang: source.lang ?? 'all',
408 icon,
409 url: source.baseUrl ?? '',
410 rating: ext.nsfw === 1 ? 'nsfw' : 'safe'
411 }
412 )
413 }
414 }
415 return sites
416}
417
418function toRepoDataAidoku(iconBase: string, index: AidokuIndex): RepoSite[] {
419 const seen = new Set<string>()
420 const sites: RepoSite[] = []
421 for (const source of index.sources ?? []) {
422 const icon = `${iconBase}/${source.iconURL}`
423 const rating = ratingFromLevel(source.contentRating ?? 0)
424 const langs = source.languages?.length ? source.languages : ['all']
425 for (const rawLang of langs) {
426 const lang = normalizeLang(rawLang)
427 addSite(seen, `${source.name}::${lang}::${source.baseURL}`, sites, {
428 name: source.name,
429 lang,
430 icon,
431 url: source.baseURL,
432 rating
433 })
434 }
435 }
436 return sites
437}
438
439function toRepoDataPaperback(
440 iconBase: string,
441 index: PaperbackIndex
442): RepoSite[] {
443 const seen = new Set<string>()
444 const sites: RepoSite[] = []
445 const iconDir = index.builtWith?.toolchain?.startsWith('0.8')
446 ? 'includes'
447 : 'static'
448 for (const source of index.sources ?? []) {
449 const lang = normalizeLang(source.language ?? 'all')
450 const key = `${source.id}::${lang}`
451 if (seen.has(key)) continue
452 seen.add(key)
453 const icon = `${iconBase}/${source.id}/${iconDir}/${source.icon}`
454 const rating: Rating = source.contentRating === 'ADULT'
455 ? 'nsfw'
456 : source.contentRating === 'MATURE'
457 ? 'suggestive'
458 : 'safe'
459 sites.push({
460 name: source.name,
461 lang,
462 icon,
463 url: source.websiteBaseURL ?? '',
464 rating
465 })
466 }
467 return sites
468}
469
470function normalizeGoogleFaviconUrl(url: string): string {
471 return url.replace('%size%', '64')
472}
473
474async function toRepoDataCloudstream(
475 repo: CloudstreamRepo,
476 fetchJson: FetchJson
477): Promise<RepoSite[]> {
478 const seen = new Set<string>()
479 const sites: RepoSite[] = []
480 const lists = await mapLimit(
481 repo.pluginLists,
482 FETCH_CONCURRENCY,
483 url => fetchJson(url)
484 )
485 for (const list of lists) {
486 if (!Array.isArray(list)) continue
487 for (const plugin of list as CloudstreamPlugin[]) {
488 if (seen.has(plugin.name)) continue
489 seen.add(plugin.name)
490 const lang = normalizeLang(plugin.language ?? 'all')
491 const icon = plugin.iconUrl
492 ? normalizeGoogleFaviconUrl(plugin.iconUrl)
493 : ''
494 sites.push({ name: plugin.name, lang, icon, url: '', rating: 'safe' })
495 }
496 }
497 return sites
498}
499
500function toRepoDataAidokuLegacy(
501 iconBase: string,
502 sources: AidokuLegacySource[]
503): RepoSite[] {
504 const seen = new Set<string>()
505 const sites: RepoSite[] = []
506 for (const source of sources) {
507 const lang = normalizeLang(source.lang)
508 addSite(seen, `${source.name}::${lang}`, sites, {
509 name: source.name,
510 lang,
511 icon: `${iconBase}/icons/${source.icon}`,
512 url: '',
513 rating: ratingFromLevel(source.nsfw ?? 0)
514 })
515 }
516 return sites
517}
518
519function toRepoDataHayase(extensions: HayaseExtension[]): RepoSite[] {
520 const seen = new Set<string>()
521 const sites: RepoSite[] = []
522 for (const ext of extensions) {
523 const langs = ext.languages?.length ? ext.languages : ['all']
524 for (const rawLang of langs) {
525 const lang = normalizeLang(rawLang)
526 addSite(seen, `${ext.name}::${lang}`, sites, {
527 name: ext.name,
528 lang,
529 icon: ext.icon ?? '',
530 url: '',
531 rating: 'safe'
532 })
533 }
534 }
535 return sites
536}
537
538function toRepoDataLegado(sources: LegadoBookSource[]): RepoSite[] {
539 const seen = new Set<string>()
540 const sites: RepoSite[] = []
541 for (const source of sources) {
542 const lang = normalizeLang(source.bookSourceGroup ?? 'all')
543 addSite(seen, `${source.bookSourceName}::${lang}`, sites, {
544 name: source.bookSourceName,
545 lang,
546 icon: '',
547 url: source.bookSourceUrl,
548 rating: 'safe'
549 })
550 }
551 return sites
552}
553
554function toRepoDataMangayomi(sources: MangayomiSource[]): RepoSite[] {
555 const seen = new Set<string>()
556 const sites: RepoSite[] = []
557 for (const source of sources) {
558 const lang = normalizeLang(source.lang)
559 addSite(seen, `${source.name}::${lang}`, sites, {
560 name: source.name,
561 lang,
562 icon: source.iconUrl ?? '',
563 url: source.baseUrl,
564 rating: source.isNsfw ? 'nsfw' : 'safe'
565 })
566 }
567 return sites
568}
569
570function toRepoDataIReader(sources: IReaderSource[]): RepoSite[] {
571 const seen = new Set<string>()
572 const sites: RepoSite[] = []
573 for (const source of sources) {
574 const lang = normalizeLang(source.lang)
575 addSite(seen, `${source.name}::${lang}`, sites, {
576 name: source.name,
577 lang,
578 icon: '',
579 url: '',
580 rating: source.nsfw ? 'nsfw' : 'safe'
581 })
582 }
583 return sites
584}
585
586function toRepoDataSuwatte(
587 iconBase: string,
588 index: SuwatteCatalogIndex
589): { sites: RepoSite[]; listUrl: string } {
590 const seen = new Set<string>()
591 const sites: RepoSite[] = []
592 const listUrl = index.listUrl ?? iconBase
593 const isV6 = index.catalogVersion === undefined
594 for (const source of index.sources ?? []) {
595 const langs = source.languages?.length ? source.languages : ['all']
596 const icon = source.thumbnail
597 ? (/^https?:\/\//i.test(source.thumbnail)
598 ? source.thumbnail
599 : `${iconBase}/assets/${source.thumbnail}`)
600 : ''
601 const installUrl = source.path
602 ? (isV6
603 ? `suwatte://runner?url=${listUrl}&runner=${source.path}`
604 : `suwatte://AddSourceFromList?list=${listUrl}&source=${source.path}`)
605 : undefined
606 for (const rawLang of langs) {
607 const lang = normalizeLang(rawLang)
608 addSite(seen, `${source.name}::${lang}`, sites, {
609 name: source.name,
610 lang,
611 icon,
612 url: source.website ?? '',
613 rating: 'safe',
614 installUrl
615 })
616 }
617 }
618 return { sites, listUrl }
619}
620
621function toRepoDataKotatsu(index: KotatsuIndex): RepoSite[] {
622 const seen = new Set<string>()
623 const sites: RepoSite[] = []
624 for (const site of index.sites) {
625 const lang = normalizeLang(site.lang ?? 'all')
626 const contentType = site.contentType ?? ''
627 const rating: Rating = contentType.includes('HENTAI') ? 'nsfw' : 'safe'
628 addSite(seen, `${site.name}::${lang}::${site.url}`, sites, {
629 name: site.name ?? 'Unknown',
630 lang,
631 icon: site.icon,
632 url: site.url ?? '',
633 rating,
634 contentType,
635 isBroken: site.isBroken || undefined
636 })
637 }
638 return sites
639}
640
641function isEchoExtensionList(json: unknown): json is EchoExtension[] {
642 if (!Array.isArray(json) || json.length === 0) return false
643 const first = json[0] as Record<string, unknown>
644 return typeof first.updateUrl === 'string' &&
645 typeof first.subtitle === 'string' && !('lang' in first) &&
646 !('baseUrl' in first)
647}
648
649function parseEchoRepo(
650 updateUrl: string
651): {
652 host: string
653 owner: string
654 repo: string
655 repoUrl: string
656 ownerUrl: string
657} | undefined {
658 const githubMatch = updateUrl.match(
659 /^https:\/\/api\.github\.com\/repos\/([^/]+)\/([^/]+)\/releases$/
660 )
661 if (githubMatch) {
662 const [, owner, repo] = githubMatch
663 return {
664 host: 'github.com',
665 owner,
666 repo,
667 repoUrl: `https://github.com/${owner}/${repo}`,
668 ownerUrl: `https://github.com/${owner}`
669 }
670 }
671 const gitlabMatch = updateUrl.match(
672 /^https:\/\/(gitlab\.com)\/api\/v4\/projects\/([^/]+)\/releases\b/
673 )
674 if (gitlabMatch) {
675 const [, host, encodedPath] = gitlabMatch
676 const path = decodeURIComponent(encodedPath)
677 const owner = path.slice(0, path.lastIndexOf('/'))
678 const repo = path.slice(path.lastIndexOf('/') + 1)
679 if (!owner || !repo) return undefined
680 return {
681 host,
682 owner,
683 repo,
684 repoUrl: `https://${host}/${path}`,
685 ownerUrl: `https://${host}/${owner}`
686 }
687 }
688 return undefined
689}
690
691function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] {
692 const seen = new Set<string>()
693 const sites: RepoSite[] = []
694 for (const ext of extensions) {
695 if (seen.has(`${ext.id}::${ext.updateUrl}`)) continue
696 seen.add(`${ext.id}::${ext.updateUrl}`)
697 const repo = parseEchoRepo(ext.updateUrl)
698 sites.push({
699 name: ext.name,
700 lang: 'all',
701 icon: ext.iconUrl ?? '',
702 url: ext.url ?? repo?.repoUrl ?? '',
703 rating: 'safe',
704 contentType: ext.type,
705 installUrl: repo?.repoUrl
706 })
707 }
708 return sortSites(sites)
709}
710
711function loadEchoExtensionList(
712 indexUrl: string,
713 extensions: EchoExtension[]
714): {
715 sites: RepoSite[]
716 authorRepos: EchoAuthorRepo[]
717 sitesByAuthor: Record<string, RepoData>
718} {
719 const byAuthor = new Map<
720 string,
721 { label: string; ownerUrl?: string; exts: EchoExtension[] }
722 >()
723 for (const ext of extensions) {
724 const repo = parseEchoRepo(ext.updateUrl)
725 const key = repo ? `${repo.host}:${repo.owner}` : 'Unknown'
726 const bucket = byAuthor.get(key)
727 if (bucket) bucket.exts.push(ext)
728 else {byAuthor.set(key, {
729 label: repo?.owner ?? 'Unknown',
730 ownerUrl: repo?.ownerUrl,
731 exts: [ext]
732 })}
733 }
734 const authorRepos: EchoAuthorRepo[] = []
735 const sitesByAuthor: Record<string, RepoData> = {}
736 for (const [key, { label, ownerUrl, exts }] of byAuthor) {
737 const authorIndexUrl = `${indexUrl}#${key}`
738 sitesByAuthor[authorIndexUrl] = { sites: toRepoDataEchoExtensions(exts) }
739 authorRepos.push({ label, repoUrl: ownerUrl, indexUrl: authorIndexUrl })
740 }
741 authorRepos.sort((a, b) => a.label.localeCompare(b.label))
742 return {
743 sites: toRepoDataEchoExtensions(extensions),
744 authorRepos,
745 sitesByAuthor
746 }
747}
748
749function toRepoDataLNReader(plugins: LNReaderPlugin[]): RepoSite[] {
750 const seen = new Set<string>()
751 const sites: RepoSite[] = []
752 for (const plugin of plugins) {
753 const lang = normalizeLang(plugin.lang)
754 addSite(seen, `${plugin.name}::${lang}`, sites, {
755 name: plugin.name,
756 lang,
757 icon: plugin.iconUrl ?? '',
758 url: plugin.url,
759 rating: 'safe'
760 })
761 }
762 return sites
763}
764
765const CONTENT_WARNING_RATING: Record<string, Rating> = {
766 CONTENT_WARNING_NSFW: 'nsfw',
767 CONTENT_WARNING_MIXED: 'suggestive',
768 CONTENT_WARNING_SAFE: 'safe'
769}
770
771function toRepoDataMihonNew(index: MihonIndex): RepoSite[] {
772 const seen = new Set<string>()
773 const sites: RepoSite[] = []
774 for (const ext of index.extensionList.extensions) {
775 const icon = ext.resources.iconUrl
776 const rating = CONTENT_WARNING_RATING[ext.contentWarning] ?? 'safe'
777 for (const source of ext.sources) {
778 addSite(
779 seen,
780 `${source.name}::${source.language}::${source.homeUrl}`,
781 sites,
782 {
783 name: source.name ?? 'Unknown',
784 lang: source.language ?? 'all',
785 icon,
786 url: source.homeUrl ?? '',
787 rating
788 }
789 )
790 }
791 }
792 return sortSites(sites)
793}
794
795async function toRepoData(
796 indexUrl: string,
797 json: unknown,
798 fetchJson: FetchJson
799): Promise<RepoData> {
800 const iconBase = indexUrl.slice(0, indexUrl.lastIndexOf('/'))
801 let sites: RepoSite[]
802 let suwatteV6: boolean | undefined
803 let suwatteListUrl: string | undefined
804
805 if (
806 json && typeof json === 'object' && !Array.isArray(json) &&
807 'extensionList' in (json as Record<string, unknown>)
808 ) {
809 return { sites: toRepoDataMihonNew(json as MihonIndex) }
810 }
811
812 if (Array.isArray(json)) {
813 const first = json[0] as Record<string, unknown> | undefined
814 if (first && 'bookSourceUrl' in first) {
815 sites = toRepoDataLegado(json as LegadoBookSource[])
816 } else if (first && 'manifestVersion' in first) {
817 sites = toRepoDataHayase(json as HayaseExtension[])
818 } else if (first && 'iconUrl' in first && 'site' in first) {
819 sites = toRepoDataLNReader(json as LNReaderPlugin[])
820 } else if (first && 'sources' in first) {
821 sites = toRepoDataMihon(iconBase, json as MihonExtension[])
822 } else if (first && 'pkg' in first && 'apk' in first) {
823 sites = toRepoDataIReader(json as IReaderSource[])
824 } else if (first && 'iconUrl' in first && 'baseUrl' in first) {
825 sites = toRepoDataMangayomi(json as MangayomiSource[])
826 } else {
827 sites = toRepoDataAidokuLegacy(iconBase, json as AidokuLegacySource[])
828 }
829 } else if (Array.isArray((json as CloudstreamRepo).pluginLists)) {
830 sites = await toRepoDataCloudstream(json as CloudstreamRepo, fetchJson)
831 } else if (
832 (json as AidokuIndex).sources?.length &&
833 'iconURL' in (json as AidokuIndex).sources[0]
834 ) {
835 sites = toRepoDataAidoku(iconBase, json as AidokuIndex)
836 } else if (
837 (json as SuwatteCatalogIndex).sources?.length &&
838 'thumbnail' in (json as SuwatteCatalogIndex).sources[0]
839 ) {
840 const result = toRepoDataSuwatte(iconBase, json as SuwatteCatalogIndex)
841 sites = result.sites
842 suwatteListUrl = result.listUrl
843 suwatteV6 = (json as SuwatteCatalogIndex).catalogVersion === undefined
844 } else if (Array.isArray((json as KotatsuIndex).sites)) {
845 sites = toRepoDataKotatsu(json as KotatsuIndex)
846 } else {
847 sites = toRepoDataPaperback(iconBase, json as PaperbackIndex)
848 }
849 return { sites: sortSites(sites), suwatteV6, suwatteListUrl }
850}
851
852export interface ExtensionRepoData {
853 sites: Record<string, RepoData>
854 echoAuthors: Record<string, EchoAuthorRepo[]>
855 repoLists: Record<string, RepoListEntry[]>
856}
857
858export async function assembleSchemeData(
859 indexUrls: string[],
860 listUrls: string[],
861 fetchJson: FetchJson
862): Promise<ExtensionRepoData> {
863 const listUrlSet = new Set(listUrls)
864 const sites: Record<string, RepoData> = {}
865 const echoAuthors: Record<string, EchoAuthorRepo[]> = {}
866 const repoLists: Record<string, RepoListEntry[]> = {}
867 const pendingByAuthor: Record<string, RepoData> = {}
868
869 const listJsons = await mapLimit(
870 listUrls,
871 FETCH_CONCURRENCY,
872 url => fetchJson(url)
873 )
874 const listIndexGroups: {
875 indexUrls: string[]
876 repoJsons: unknown[]
877 failed: boolean
878 }[] = await Promise.all(listJsons.map(async (json) => {
879 if (json === undefined) {
880 return { indexUrls: [], repoJsons: [], failed: true }
881 }
882 if (!isCloudstreamRepoList(json)) {
883 return { indexUrls: [], repoJsons: [], failed: false }
884 }
885 const indexUrls = [
886 ...new Set(
887 json.map(item => typeof item === 'string' ? item : item.url)
888 )
889 ]
890 const repoJsons = await mapLimit(
891 indexUrls,
892 FETCH_CONCURRENCY,
893 url => fetchJson(url)
894 )
895 return { indexUrls, repoJsons, failed: false }
896 }))
897 listUrls.forEach((listUrl, li) => {
898 const { indexUrls, repoJsons, failed } = listIndexGroups[li]
899 if (failed) return
900 if (indexUrls.length === 0) {
901 repoLists[listUrl] = []
902 return
903 }
904 const entries: RepoListEntry[] = indexUrls.map((indexUrl, i) => ({
905 label: repoListLabel(indexUrl, repoJsons[i]),
906 indexUrl,
907 repoUrl: inferRepoUrl(indexUrl)
908 }))
909 entries.sort((a, b) => a.label.localeCompare(b.label))
910 repoLists[listUrl] = entries
911 })
912 const listRepoPairs = listIndexGroups.filter(g => !g.failed).flatMap(g =>
913 g.indexUrls.map((url, i) => ({ url, json: g.repoJsons[i] })).filter(p =>
914 p.json !== undefined
915 )
916 )
917 const listRepoResults = await mapLimit(
918 listRepoPairs,
919 FETCH_CONCURRENCY,
920 async ({ url, json }) => ({
921 url,
922 data: await toRepoData(url, json, fetchJson)
923 })
924 )
925 for (const { url, data } of listRepoResults) {
926 if (!(url in sites)) sites[url] = data
927 }
928
929 const remaining = indexUrls.filter(url =>
930 !listUrlSet.has(url) && !(url in sites)
931 )
932 const jsons = await mapLimit(
933 remaining,
934 FETCH_CONCURRENCY,
935 url => fetchJson(url)
936 )
937 for (let i = 0; i < remaining.length; i++) {
938 const url = remaining[i]
939 const json = jsons[i]
940 if (json === undefined) continue
941 if (isEchoExtensionList(json)) {
942 const result = loadEchoExtensionList(url, json)
943 sites[url] = { sites: result.sites }
944 echoAuthors[url] = result.authorRepos
945 Object.assign(pendingByAuthor, result.sitesByAuthor)
946 continue
947 }
948 sites[url] = await toRepoData(url, json, fetchJson)
949 }
950 Object.assign(sites, pendingByAuthor)
951 return { sites, echoAuthors, repoLists }
952}
docs/ext/extensionRepos/shared.ts added +178
@@ -0,0 +1,178 @@
1import {
2 existsSync,
3 mkdirSync,
4 readdirSync,
5 readFileSync,
6 renameSync,
7 statSync,
8 writeFileSync
9} from 'node:fs'
10import { dirname, join } from 'node:path'
11import { fileURLToPath } from 'node:url'
12import { parseExtRepoAttrs } from './attrs'
13import { assembleSchemeData, type ExtensionRepoData } from './parsers'
14
15export type { ExtensionRepoData } from './parsers'
16
17const IGNORED_DIRS = new Set(['node_modules', '.vitepress', '.git'])
18const FETCH_TIMEOUT_MS = 15000
19const CACHE_TTL_MS = 6 * 60 * 60 * 1000
20
21const EXT_DIR = dirname(fileURLToPath(import.meta.url))
22const DOCS_DIR = join(EXT_DIR, '..', '..')
23const CACHE_DIR = join(EXT_DIR, '..', '..', '.vitepress/cache/extension-repos')
24let cacheDirReady = false
25
26function findMarkdownFiles(dir: string): string[] {
27 const files: string[] = []
28 for (const entry of readdirSync(dir, { withFileTypes: true })) {
29 if (entry.isDirectory()) {
30 if (!IGNORED_DIRS.has(entry.name)) {
31 files.push(...findMarkdownFiles(join(dir, entry.name)))
32 }
33 } else if (entry.name.endsWith('.md')) {
34 files.push(join(dir, entry.name))
35 }
36 }
37 return files
38}
39
40// Single scan of all md files, collecting urls for one scheme only.
41function collectScheme(
42 scheme: string
43): { indexUrls: string[]; listUrls: string[] } {
44 const indexUrls = new Set<string>()
45 const listUrls = new Set<string>()
46 const blockRe = /:::\s*extrepo([^\n]*)\n([\s\S]*?)\n\s*:::/g
47 const rowRe =
48 /^\s*-\s*(raw|manga|anime|novel|data)\s*:\s*(https?:\/\/\S+)\s*$/i
49 const headingRe = /^\s*==\s+.+$/
50 const buildRe = /^\s*--\s+.+$/
51
52 function flushEntry(
53 plainRaws: string[],
54 variantUrls: string[],
55 buildRaws: string[],
56 dataUrls: string[]
57 ): void {
58 for (const url of variantUrls) indexUrls.add(url)
59 for (const url of buildRaws) indexUrls.add(url)
60 for (const url of dataUrls) indexUrls.add(url)
61 if (dataUrls.length === 0) {
62 for (const url of plainRaws) indexUrls.add(url)
63 }
64 }
65
66 for (const file of findMarkdownFiles(DOCS_DIR)) {
67 const src = readFileSync(file, 'utf-8')
68 let block: RegExpExecArray | null
69 blockRe.lastIndex = 0
70 while ((block = blockRe.exec(src))) {
71 const headerAttrs = parseBlockAttrs(block[1])
72 if ((headerAttrs.scheme || 'mihon') !== scheme) continue
73 if (headerAttrs.from) listUrls.add(headerAttrs.from)
74 let plainRaws: string[] = []
75 let variantUrls: string[] = []
76 let buildRaws: string[] = []
77 let dataUrls: string[] = []
78 let inEntry = false
79 let inBuild = false
80 for (const line of block[2].split('\n')) {
81 if (headingRe.test(line)) {
82 if (inEntry) flushEntry(plainRaws, variantUrls, buildRaws, dataUrls)
83 plainRaws = []
84 variantUrls = []
85 buildRaws = []
86 dataUrls = []
87 inEntry = true
88 inBuild = false
89 continue
90 }
91 if (buildRe.test(line)) {
92 inBuild = true
93 continue
94 }
95 const row = rowRe.exec(line)
96 if (row && inEntry) {
97 const key = row[1].toLowerCase()
98 const url = row[2].trim()
99 if (key === 'data') dataUrls.push(url)
100 else if (key === 'raw') (inBuild ? buildRaws : plainRaws).push(url)
101 else variantUrls.push(url)
102 }
103 }
104 if (inEntry) flushEntry(plainRaws, variantUrls, buildRaws, dataUrls)
105 }
106 }
107 return { indexUrls: [...indexUrls], listUrls: [...listUrls] }
108}
109
110function parseBlockAttrs(header: string): { scheme?: string; from?: string } {
111 const attrs = parseExtRepoAttrs(header)
112 return { scheme: attrs.scheme, from: attrs.from }
113}
114
115function cachePathFor(url: string): string {
116 return join(CACHE_DIR, `${Buffer.from(url).toString('base64url')}.json`)
117}
118
119const inflight = new Map<string, Promise<unknown>>()
120
121async function fetchOnce(url: string): Promise<unknown> {
122 const cachePath = cachePathFor(url)
123 if (
124 existsSync(cachePath) &&
125 Date.now() - statSync(cachePath).mtimeMs < CACHE_TTL_MS
126 ) {
127 return JSON.parse(readFileSync(cachePath, 'utf-8'))
128 }
129 const ctrl = new AbortController()
130 const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS)
131 try {
132 const res = await fetch(url, { signal: ctrl.signal })
133 if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
134 const json = await res.json()
135 if (!cacheDirReady) {
136 mkdirSync(CACHE_DIR, { recursive: true })
137 cacheDirReady = true
138 }
139 const tmp = `${cachePath}.${process.pid}.tmp`
140 writeFileSync(tmp, JSON.stringify(json))
141 renameSync(tmp, cachePath)
142 return json
143 } finally {
144 clearTimeout(timer)
145 }
146}
147
148function fetchIndex(url: string): Promise<unknown> {
149 const hit = inflight.get(url)
150 if (hit) return hit
151 const p = (async () => {
152 for (let attempt = 0; attempt < 2; attempt++) {
153 try {
154 return await fetchOnce(url)
155 } catch (err) {
156 if (attempt === 1) {
157 const cachePath = cachePathFor(url)
158 if (existsSync(cachePath)) {
159 return JSON.parse(readFileSync(cachePath, 'utf-8'))
160 }
161 console.warn(
162 `[extrepo] failed to fetch ${url}: ${(err as Error).message}`
163 )
164 return []
165 }
166 }
167 }
168 })() as Promise<unknown>
169 inflight.set(url, p)
170 return p
171}
172
173export async function loadScheme(
174 scheme: string
175): Promise<ExtensionRepoData> {
176 const { indexUrls, listUrls } = collectScheme(scheme)
177 return assembleSchemeData(indexUrls, listUrls, fetchIndex)
178}
docs/ext/extensionRepos/suwatte.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('suwatte')
9 }
10}
docs/ext/index.md +1 −1
@@ -32,7 +32,7 @@ og:
3232
3333## Cross-app Support
3434::: scrapetable
35- Anymex : (Mihon), (Aniyomi), (Mangayomi), (Kotatsu), (Sora), (Cloudstream), (LNReader);
35- Anymex : (Mihon), (Aniyomi), (Mangayomi), (Kotatsu), (Cloudstream), (LNReader);
3636- Cloudstream : (Cloudstream), (Aniyomi);
3737- Dantotsu : (Mihon), (Aniyomi), (LNreader);
3838- Futon : (Kotatsu), (Mihon);
docs/ext/ios.md +1 −10
@@ -1,6 +1,6 @@
11---
22title: iOS Apps Extension Repos
3customDescription: Extension Repos & Guides for Aidoku, Sora & Suwatte
3customDescription: Extension Repos & Guides for Aidoku, Paperback & Suwatte
44feedback: no
55og:
66 image: /embed/ios.png
@@ -139,15 +139,6 @@ og:
139139You can install v0.8 extensions in the v0.9 Paperback client, but you can't install v0.9 extensions in the v0.8 client.
140140:::
141141
142## Sora
143
144::: extrepo {scheme=sora}
145
146== Sources
147- raw: https://kotatsu-83g.pages.dev/sora/index.json
148
149:::
150
151142## Suwatte
152143
153144::: extrepo {scheme=suwatte}
docs/ext/mihon.md +1 −1
@@ -26,7 +26,7 @@ og:
2626
2727## Manga
2828
29::: extrepo {scheme=mihon}
29::: extrepo {scheme=mihon,manual}
3030
3131== Keiyoushi
3232- url: https://keiyoushi.github.io/
unocss.config.ts +3
@@ -79,6 +79,9 @@ const safelist = [
7979 'i-lucide:message-circle',
8080 'i-lucide:copy',
8181 'i-lucide:check',
82 'i-lucide:x',
83 'i-lucide:loader-circle',
84 'i-lucide:refresh-cw',
8285 'i-lucide:settings',
8386 'i-lucide:download',
8487 'i-lucide:chevron-down',