Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nto dev
  • Loading branch information
MengNianxiaoyao committed Apr 18, 2024
2 parents d636c22 + a28d1ef commit f650507
Show file tree
Hide file tree
Showing 14 changed files with 380 additions and 341 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
# The branch where the project source code resides
# 项目源代码所在的分支
- main
- dev
paths-ignore:
# Changes involving the following path files will not trigger the workflow
# 涉及以下路径文件的更改不会触发工作流
Expand Down
17 changes: 9 additions & 8 deletions src/background/messageListeners/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import API_USER from './user'
import API_VIDEO from './video'
import API_WATCHLATER from './watchLater'

// Merge all API objects into one
const FullAPI = Object.assign({}, API_AUTH, API_ANIME, API_HISTORY, API_FAVORITE, API_MOMENT, API_NOTIFICATION, API_RANKING, API_SEARCH, API_USER, API_VIDEO, API_WATCHLATER)
// Create a message listener for each API
const handleMessage = apiListenerFactory(FullAPI)

export function setupAllMsgLstnrs() {
browser.runtime.onConnect.removeListener(handleConnect)
browser.runtime.onConnect.addListener(handleConnect)
}

function handleConnect() {
// Merge all API objects into one
const FullAPI = Object.assign({}, API_AUTH, API_ANIME, API_HISTORY, API_FAVORITE, API_MOMENT, API_NOTIFICATION, API_RANKING, API_SEARCH, API_USER, API_VIDEO, API_WATCHLATER)
// Create a message listener for each API
const handleMessage = apiListenerFactory(FullAPI)
browser.runtime.onMessage.removeListener(handleMessage)
browser.runtime.onMessage.addListener(handleMessage)
}
function handleConnect() {
browser.runtime.onMessage.removeListener(handleMessage)
browser.runtime.onMessage.addListener(handleMessage)
}
23 changes: 6 additions & 17 deletions src/background/messageListeners/moment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,19 @@ const API_MOMENT: APIMAP = {
params: {},
afterHandle: AHS.J_D,
},
getTopBarNewMoments: {
url: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new',
getTopBarMoments: {
url: 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/nav',
_fetch: {
method: 'get',
},
params: {
uid: '',
type_list: '268435455',
type: 'video',
update_baseline: '',
offset: '',
},
afterHandle: AHS.J_D,
},
getTopbarHistoryMoments: {
url: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_history',
_fetch: {
method: 'get',
},
params: {
uid: '',
type_list: '268435455',
offset_dynamic_id: '',
},
afterHandle: AHS.J_D,
},
getTopbarLiveMoments: {
getTopBarLiveMoments: {
url: 'https://api.live.bilibili.com/xlive/web-ucenter/v1/xfetter/FeedList',
_fetch: {
method: 'get',
Expand Down
5 changes: 2 additions & 3 deletions src/background/msg.define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ enum HISTORY {
}
enum MOMENT {
GET_TOP_BAR_NEW_MOMENTS_COUNT = 'getTopBarNewMomentsCount',
GET_TOP_BAR_NEW_MOMENTS = 'getTopBarNewMoments',
GET_TOP_BAR_HISTORY_MOMENTS = 'getTopbarHistoryMoments',
GET_TOP_BAR_LIVE_MOMENTS = 'getTopbarLiveMoments',
GET_TOP_BAR_MOMENTS = 'getTopBarMoments',
GET_TOP_BAR_LIVE_MOMENTS = 'getTopBarLiveMoments',
GET_MOMENTS = 'getMoments',
}
enum NOTIFICATION {
Expand Down
2 changes: 1 addition & 1 deletion src/background/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function apiListenerFactory(API_MAP: APIMAP) {
const contentScriptQuery = message.contentScriptQuery
// 检测是否有contentScriptQuery
if (!contentScriptQuery || !API_MAP[contentScriptQuery])
return console.error('no contentScriptQuery')
return console.error(`Cannot find this contentScriptQuery: ${contentScriptQuery}`)
if (API_MAP[contentScriptQuery] instanceof Function)
return (API_MAP[contentScriptQuery] as APIFunction)(message, sender, sendResponse)

Expand Down
4 changes: 2 additions & 2 deletions src/components/TopBar/TopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const notifications = useDelayedHover({
const moments = useDelayedHover({
enter: () => {
showMomentsPop.value = true
momentsPopRef.value && momentsPopRef.value.initData()
momentsPopRef.value && momentsPopRef.value.checkIfHasNewMomentsThenUpdateMoments()
},
leave: () => showMomentsPop.value = false,
})
Expand Down Expand Up @@ -383,7 +383,7 @@ defineExpose({

<Transition name="slide-in">
<ChannelsPop
v-if="showChannelsPop"
v-show="showChannelsPop"
class="bew-popover"
pos="!left-0 !top-70px"
transform="!translate-x-0"
Expand Down
49 changes: 24 additions & 25 deletions src/components/TopBar/components/HistoryPop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { useI18n } from 'vue-i18n'
import type { Ref } from 'vue'
import { onMounted, reactive, ref, watch } from 'vue'
import { useDateFormat } from '@vueuse/core'
import type { HistoryItem } from '../types'
import { HistoryType } from '../types'
import { isHomePage, removeHttpFromUrl, smoothScrollToTop } from '~/utils/main'
import { calcCurrentTime } from '~/utils/dataFormatter'
import { Business } from '~/models/history/history'
import type { List as HistoryItem, HistoryResult } from '~/models/history/history'
import API from '~/background/msg.define'
const { t } = useI18n()
Expand Down Expand Up @@ -39,7 +40,7 @@ const noMoreContent = ref<boolean>(false)
const livePage = ref<number>(1)
const historysWrap = ref<HTMLElement>() as Ref<HTMLElement>
watch(activatedTab, (newVal: number, oldVal: number) => {
watch(activatedTab, (newVal: number | undefined, oldVal: number | undefined) => {
if (newVal === oldVal)
return
Expand All @@ -48,20 +49,18 @@ watch(activatedTab, (newVal: number, oldVal: number) => {
smoothScrollToTop(historysWrap.value, 300)
if (newVal === 0) {
getHistoryList(HistoryType.Archive)
getHistoryList(Business.ARCHIVE)
}
else if (newVal === 1) {
livePage.value = 1
getHistoryList(HistoryType.Live)
getHistoryList(Business.LIVE)
}
else if (newVal === 2) {
getHistoryList(HistoryType.Article)
getHistoryList(Business.ARTICLE)
}
})
}, { immediate: true })
onMounted(() => {
getHistoryList(HistoryType.Archive)
if (historysWrap.value) {
historysWrap.value.addEventListener('scroll', () => {
// When you scroll to the bottom, they will automatically
Expand All @@ -74,19 +73,19 @@ onMounted(() => {
) {
if (activatedTab.value === 0 && !noMoreContent.value) {
getHistoryList(
HistoryType.Archive,
Business.ARCHIVE,
historys[historys.length - 1].view_at,
)
}
else if (activatedTab.value === 1 && !noMoreContent.value) {
getHistoryList(
HistoryType.Live,
Business.LIVE,
historys[historys.length - 1].view_at,
)
}
else if (activatedTab.value === 2 && !noMoreContent.value) {
getHistoryList(
HistoryType.Article,
Business.ARTICLE,
historys[historys.length - 1].view_at,
)
}
Expand All @@ -112,43 +111,43 @@ function onClickTab(tabId: number) {
* @return {string} url
*/
function getHistoryUrl(item: HistoryItem) {
if (item.uri)
return item.uri
// Video
if (activatedTab.value === 0) {
if (item.history.business === HistoryType.PGC)
return removeHttpFromUrl(item.uri)
if (item.history.business === HistoryType.Archive && item?.videos && item.videos > 0)
if (item.history.business === Business.ARCHIVE) {
if (item?.videos && item.videos > 0)
return `//www.bilibili.com/video/${item.history.bvid}?p=${item.history.page}`
return `//www.bilibili.com/video/${item.history.bvid}`
}
// Live
else if (activatedTab.value === 1) {
else if (item.history.business === Business.LIVE) {
return `//live.bilibili.com/${item.history.oid}`
}
// Article
else if (activatedTab.value === 2) {
else if (item.history.business === Business.ARTICLE || item.history.business === Business.ARTICLE_LIST) {
if (item.history.cid === 0)
return `//www.bilibili.com/read/cv${item.history.oid}`
else
return `//www.bilibili.com/read/cv${item.history.cid}`
}
return ''
}
/**
* Get history list
* @param {HistoryType} type
* @param {number} view_at Last viewed timestamp
* @param type
* @param view_at Last viewed timestamp
*/
function getHistoryList(type: HistoryType, view_at = 0 as number) {
function getHistoryList(type: Business, view_at = 0 as number) {
isLoading.value = true
browser.runtime
.sendMessage({
contentScriptQuery: API.HISTORY.GET_HISTORY_LIST,
type,
view_at,
})
.then((res) => {
.then((res: HistoryResult) => {
if (res.code === 0) {
if (Array.isArray(res.data.list) && res.data.list.length > 0)
historys.push(...res.data.list)
Expand Down Expand Up @@ -325,7 +324,7 @@ function getHistoryList(type: HistoryType, view_at = 0 as number) {
m="1"
rounded="$bew-radius-half"
>
Offline
OFFLINE
</div>
</div>
</template>
Expand Down Expand Up @@ -367,7 +366,7 @@ function getHistoryList(type: HistoryType, view_at = 0 as number) {
gap-1
m="l-2"
><tabler:live-photo />
Live
LIVE
</span>
</div>
<p text="$bew-text-2 sm">
Expand Down
Loading

0 comments on commit f650507

Please sign in to comment.