mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Merge branch 'preview-fixes'
This commit is contained in:
commit
2c74f4fe19
@ -7,7 +7,15 @@ import { getVue2Data, matchUrlPattern, retrieveImageUrl } from '@/core/utils'
|
|||||||
import { formatTitle, getTitleVariablesFromDate } from '@/core/utils/title'
|
import { formatTitle, getTitleVariablesFromDate } from '@/core/utils/title'
|
||||||
import { feedsUrls } from '@/core/utils/urls'
|
import { feedsUrls } from '@/core/utils/urls'
|
||||||
import { Options } from '.'
|
import { Options } from '.'
|
||||||
|
import { useScopedConsole } from '@/core/utils/log'
|
||||||
|
|
||||||
|
const isSameImage = (imageUrl: string, otherUrl: string) => {
|
||||||
|
try {
|
||||||
|
return new URL(imageUrl).pathname === new URL(otherUrl).pathname
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
export const setupFeedImageExporter: ComponentEntry<Options> = async ({
|
export const setupFeedImageExporter: ComponentEntry<Options> = async ({
|
||||||
settings: { options },
|
settings: { options },
|
||||||
}) => {
|
}) => {
|
||||||
@ -21,12 +29,13 @@ export const setupFeedImageExporter: ComponentEntry<Options> = async ({
|
|||||||
text: '导出图片',
|
text: '导出图片',
|
||||||
action: async () => {
|
action: async () => {
|
||||||
const imageUrls: { url: string; extension: string }[] = []
|
const imageUrls: { url: string; extension: string }[] = []
|
||||||
|
const console = useScopedConsole('导出图片')
|
||||||
dqa(
|
dqa(
|
||||||
card.element,
|
card.element,
|
||||||
'.main-content .img-content, .bili-album__preview__picture__img, .bili-album .preview__picture__img, .bili-dyn-gallery__image img, .bili-album__watch__track__item img',
|
'.main-content .img-content, .bili-album__preview__picture__img, .bili-album .preview__picture__img, .bili-dyn-gallery__image img, .bili-album__watch__track__item img',
|
||||||
).forEach((img: HTMLImageElement | HTMLDivElement) => {
|
).forEach((img: HTMLImageElement | HTMLDivElement) => {
|
||||||
const urlData = retrieveImageUrl(img)
|
const urlData = retrieveImageUrl(img)
|
||||||
if (urlData && !imageUrls.some(({ url }) => url === urlData.url)) {
|
if (urlData && !imageUrls.some(({ url }) => isSameImage(url, urlData.url))) {
|
||||||
imageUrls.push(urlData)
|
imageUrls.push(urlData)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -34,6 +43,7 @@ export const setupFeedImageExporter: ComponentEntry<Options> = async ({
|
|||||||
Toast.info('此条动态没有检测到任何图片.', '导出图片')
|
Toast.info('此条动态没有检测到任何图片.', '导出图片')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
console.log({ imageUrls })
|
||||||
const toast = Toast.info('下载中...', '导出图片')
|
const toast = Toast.info('下载中...', '导出图片')
|
||||||
let downloadedCount = 0
|
let downloadedCount = 0
|
||||||
|
|
||||||
|
|||||||
@ -18,14 +18,11 @@
|
|||||||
<div class="lists">
|
<div class="lists">
|
||||||
选择快速收藏夹:
|
选择快速收藏夹:
|
||||||
<VDropdown
|
<VDropdown
|
||||||
v-model="selectedFavorite"
|
v-model="selectedFavoriteList"
|
||||||
:items="lists.map(it => it.title)"
|
:items="list"
|
||||||
:key-mapper="it => it"
|
:key-mapper="it => it.id"
|
||||||
>
|
@change="saveFavoriteList"
|
||||||
<template #item="{ item }">
|
/>
|
||||||
{{ item }}
|
|
||||||
</template>
|
|
||||||
</VDropdown>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="lists-tip" :class="{ show: listShowing }">右键点击快速收藏可再次打开</div>
|
<div class="lists-tip" :class="{ show: listShowing }">右键点击快速收藏可再次打开</div>
|
||||||
</div>
|
</div>
|
||||||
@ -42,6 +39,20 @@ import { VDropdown } from '@/ui'
|
|||||||
import { DisplayMode, Options } from './options'
|
import { DisplayMode, Options } from './options'
|
||||||
|
|
||||||
const { options } = getComponentSettings('quickFavorite')
|
const { options } = getComponentSettings('quickFavorite')
|
||||||
|
interface RawFavoriteListItem {
|
||||||
|
id: number
|
||||||
|
title: string
|
||||||
|
fav_state: number
|
||||||
|
}
|
||||||
|
interface FavoriteListItem {
|
||||||
|
id: number
|
||||||
|
displayName: string
|
||||||
|
}
|
||||||
|
const EmptyFavoriteList: FavoriteListItem = {
|
||||||
|
id: 0,
|
||||||
|
displayName: '<未选择>',
|
||||||
|
}
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
components: {
|
components: {
|
||||||
VDropdown,
|
VDropdown,
|
||||||
@ -50,13 +61,12 @@ export default Vue.extend({
|
|||||||
const { displayMode } = getComponentSettings<Options>('outerWatchlater').options
|
const { displayMode } = getComponentSettings<Options>('outerWatchlater').options
|
||||||
return {
|
return {
|
||||||
aid: unsafeWindow.aid,
|
aid: unsafeWindow.aid,
|
||||||
favoriteTitle: '',
|
|
||||||
isFavorite: false,
|
isFavorite: false,
|
||||||
tipText: '',
|
tipText: '',
|
||||||
tipShowing: false,
|
tipShowing: false,
|
||||||
tipHandle: 0,
|
tipHandle: 0,
|
||||||
lists: [],
|
list: [],
|
||||||
selectedFavorite: '<未选择>',
|
selectedFavoriteList: EmptyFavoriteList,
|
||||||
listShowing: false,
|
listShowing: false,
|
||||||
displayMode,
|
displayMode,
|
||||||
}
|
}
|
||||||
@ -70,21 +80,6 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
selectedFavorite(value: string) {
|
|
||||||
if (this.lists.length === 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const { lists } = this as {
|
|
||||||
lists: { title: string; id: number }[]
|
|
||||||
}
|
|
||||||
const list = lists.find(it => it.title === value)
|
|
||||||
if (list) {
|
|
||||||
options.favoriteFolderID = list.id
|
|
||||||
this.syncFavoriteState()
|
|
||||||
} else {
|
|
||||||
console.error('list not found in selectedFavorite(value)')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async listShowing(value: boolean) {
|
async listShowing(value: boolean) {
|
||||||
if (value) {
|
if (value) {
|
||||||
document.addEventListener('click', e => {
|
document.addEventListener('click', e => {
|
||||||
@ -94,29 +89,63 @@ export default Vue.extend({
|
|||||||
this.listShowing = false
|
this.listShowing = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (this.lists.length === 0) {
|
if (this.list.length === 0) {
|
||||||
try {
|
this.loadFavoriteList()
|
||||||
const json = await getJsonWithCredentials(
|
|
||||||
`https://api.bilibili.com/medialist/gateway/base/created?pn=1&ps=100&up_mid=${getUID()}&is_space=0`,
|
|
||||||
)
|
|
||||||
if (json.code !== 0) {
|
|
||||||
throw new Error(`获取收藏夹列表失败: ${json.message}`)
|
|
||||||
}
|
|
||||||
this.lists = lodash.get(json, 'data.list', [])
|
|
||||||
} catch (error) {
|
|
||||||
logError(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.syncFavoriteState()
|
this.loadSavedList()
|
||||||
addComponentListener('quickFavorite.displayMode', (value: DisplayMode) => {
|
addComponentListener('quickFavorite.displayMode', (value: DisplayMode) => {
|
||||||
this.displayMode = value
|
this.displayMode = value
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async loadFavoriteList() {
|
||||||
|
try {
|
||||||
|
const json = await getJsonWithCredentials(
|
||||||
|
`https://api.bilibili.com/medialist/gateway/base/created?pn=1&ps=100&up_mid=${getUID()}&is_space=0`,
|
||||||
|
)
|
||||||
|
if (json.code !== 0) {
|
||||||
|
throw new Error(`获取收藏夹列表失败: ${json.message}`)
|
||||||
|
}
|
||||||
|
const list: RawFavoriteListItem[] = lodash.get(json, 'data.list', [])
|
||||||
|
this.list = list.map(it => ({ id: it.id, displayName: it.title }))
|
||||||
|
} catch (error) {
|
||||||
|
logError(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async loadSavedList() {
|
||||||
|
try {
|
||||||
|
const json = await getJsonWithCredentials(
|
||||||
|
`https://api.bilibili.com/x/v3/fav/folder/created/list-all?type=2&rid=${
|
||||||
|
this.aid
|
||||||
|
}&up_mid=${getUID()}`,
|
||||||
|
)
|
||||||
|
if (json.code !== 0) {
|
||||||
|
throw new Error(`获取收藏状态失败: ${json.message}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const list: RawFavoriteListItem[] = lodash.get(json, 'data.list', [])
|
||||||
|
const favoriteFolder = list.find(it => it.id === options.favoriteFolderID)
|
||||||
|
if (favoriteFolder === undefined) {
|
||||||
|
options.favoriteFolderID = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.isFavorite = Boolean(favoriteFolder.fav_state)
|
||||||
|
this.selectedFavoriteList = {
|
||||||
|
id: favoriteFolder.id,
|
||||||
|
displayName: favoriteFolder.title,
|
||||||
|
} as FavoriteListItem
|
||||||
|
} catch (error) {
|
||||||
|
logError(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveFavoriteList(list: FavoriteListItem) {
|
||||||
|
options.favoriteFolderID = list.id
|
||||||
|
this.syncFavoriteState()
|
||||||
|
},
|
||||||
async syncFavoriteState() {
|
async syncFavoriteState() {
|
||||||
if (options.favoriteFolderID === 0 || !this.aid) {
|
if (options.favoriteFolderID === 0 || !this.aid) {
|
||||||
return
|
return
|
||||||
@ -135,14 +164,16 @@ export default Vue.extend({
|
|||||||
'data.list',
|
'data.list',
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
const quickList = list.find(it => it.id === options.favoriteFolderID)
|
const favoriteFolder = list.find(it => it.id === options.favoriteFolderID)
|
||||||
if (quickList === undefined) {
|
if (favoriteFolder === undefined) {
|
||||||
options.favoriteFolderID = 0
|
options.favoriteFolderID = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.isFavorite = Boolean(quickList.fav_state)
|
this.isFavorite = Boolean(favoriteFolder.fav_state)
|
||||||
this.favoriteTitle = quickList.title
|
this.selectedFavoriteList = {
|
||||||
this.selectedFavorite = quickList.title
|
id: favoriteFolder.id,
|
||||||
|
displayName: favoriteFolder.title,
|
||||||
|
} as FavoriteListItem
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError(error)
|
logError(error)
|
||||||
}
|
}
|
||||||
@ -182,8 +213,8 @@ export default Vue.extend({
|
|||||||
this.isFavorite = !this.isFavorite
|
this.isFavorite = !this.isFavorite
|
||||||
this.showTip(
|
this.showTip(
|
||||||
this.isFavorite
|
this.isFavorite
|
||||||
? `已添加至收藏夹: ${this.favoriteTitle}`
|
? `已添加至收藏夹: ${this.selectedFavoriteList.displayName}`
|
||||||
: `已移出收藏夹: ${this.favoriteTitle}`,
|
: `已移出收藏夹: ${this.selectedFavoriteList.displayName}`,
|
||||||
)
|
)
|
||||||
// await this.syncFavoriteState()
|
// await this.syncFavoriteState()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user