refactor message listeners && fix moment card url not linking the video page

* Refactor messageListeners and add utils module to simply use api

* chore: add previously deleted annotation

* refactor: message listeners (#447)

* Refactor API imports and update API endpoints

* Fix variable naming in FavoritesPop and Favorites components

* Fix variable naming inconsistency in getHistoryList function

* Fix API parameter naming conventions

* Refactor API_AUTH afterHandle functions

* Add API documentation links  and add function to be the api item

* Refactor API body and params

* Remove unused getAccessKey function in auth.ts

---------

Co-authored-by: pengyunfei <pengyunfei@360.cn>
Co-authored-by: Hakadao <a578457889743@gmail.com>

* refactor: API imports and update API endpoints (#460)

* Refactor API imports and update API endpoints

* Fix variable naming in FavoritesPop and Favorites components

* Fix variable naming inconsistency in getHistoryList function

* Fix API parameter naming conventions

* Refactor API_AUTH afterHandle functions

* Add API documentation links  and add function to be the api item

* Refactor API body and params

* Remove unused getAccessKey function in auth.ts

* Add message definition constants

---------

Co-authored-by: pengyunfei <pengyunfei@360.cn>
Co-authored-by: Hakadao <a578457889743@gmail.com>

* refactor: Add cSpell words and update API calls

* Fix API method case and add day parameter to ranking API

* feat(Settings): add bilibili settings entry

* chore(Settings): hide the bilibili settings temporary

* feat: support firefox(REAL) (#500)

* refactor: new rule support `Chromium` and `Firefox`

* refactor: add default `priority`

* fix: `message.bilibili.com` not working

* fix: `show.bilibili.com` not working

* fix: 修复一些子站的问题

* 添加了一些其他的子站

* fix(VideoCard): bug fixes (#316) (#319) (#320)

* fix(VideoCard): fix double page open on author's name click (#315)

* fix(VideoCard): ensure clicking on bangumi name or avatar goes to the right page

* feat(Settings): add an "always show top bar logo" setting (#219)

* feat(Settings): add discord link to about page

* feat(Settings): redesign settings panel

* style(Settings): adjust the block ads position

* feat(Settings): add credits section on about page

* chore(Settings): add ChatGPT to the credits section

* feat(Settings): redesign settings panel

* style: decrease the content opacity in light mode
decrease the opacity in light mode to ensure the text can be seen clearly

* refactor: remove the "backdrop-glass" shortcut

* refactor: rename `--bew-filter-glass` to  `--bew-filter-glass-1`

* feat: add performance settings

* chore: remove the credits section

* feat(TopBar): add top bar icon badges config

* feat(VideoCard): implement adaptive width in horizontal mode

* feat(Home): implement grid layout switcher

* feat(Dock): redesign dock

* style: adjust dock styles

* style: add edge glow effect in some dialogs

* fix(Dock): active color incorrect when hovering dock item in dark mode

* chore: update version number

* feat(manifest): add extension id when in firefox

* refactor(rules.json): reduce redundant code

---------

Co-authored-by: starknt <1431880400@qq.com>

* chore: firefox-extension build

* Merge branch 'dev' into refactor-message-listeners

* refactor: Refactor API imports and update API endpoints

* fix(MomentsPop): moment card url not linking the video page

* chore: update version number

---------

Co-authored-by: pengyunfei <pengyunfei@360.cn>
Co-authored-by: Jimmy Chow <jimmychow@192.168.10.102>
Co-authored-by: cloudflypeng <44285412+cloudflypeng@users.noreply.github.com>
Co-authored-by: starknt <1431880400@qq.com>
Co-authored-by: 梦念逍遥 <2589141604@qq.com>
This commit is contained in:
Hakadao
2024-04-11 21:07:06 +08:00
committed by GitHub
parent 36960da9f8
commit 20d157abdf
37 changed files with 907 additions and 663 deletions

View File

@@ -6,6 +6,7 @@ import emitter from '~/utils/mitt'
import { settings } from '~/logic'
import type { Media as FavoriteItem, FavoritesResult } from '~/models/video/favorite'
import type { List as CategoryItem, FavoritesCategoryResult } from '~/models/video/favoriteCategory'
import API from '~/background/msg.define'
const { t } = useI18n()
@@ -74,8 +75,8 @@ function initPageAction() {
async function getFavoriteCategories() {
await browser.runtime
.sendMessage({
contentScriptQuery: 'getFavoriteCategories',
mid: getUserID(),
contentScriptQuery: API.FAVORITE.GET_FAVORITE_CATEGORIES,
up_mid: getUserID(),
})
.then((res: FavoritesCategoryResult) => {
if (res.code === 0) {
@@ -99,19 +100,19 @@ async function getFavoriteCategories() {
* @param keyword
*/
async function getFavoriteResources(
mediaId: number,
pageNum: number,
media_id: number,
pn: number,
keyword = '' as string,
) {
if (pageNum === 1)
if (pn === 1)
isFullPageLoading.value = true
isLoading.value = true
try {
const res: FavoritesResult = await browser.runtime
.sendMessage({
contentScriptQuery: 'getFavoriteResources',
mediaId,
pageNum,
contentScriptQuery: API.FAVORITE.GET_FAVORITE_RESOURCES,
media_id,
pn,
keyword,
})
@@ -158,9 +159,9 @@ function jumpToLoginPage() {
function handleUnfavorite(favoriteResource: FavoriteResource) {
browser.runtime.sendMessage({
contentScriptQuery: 'patchDelFavoriteResources',
contentScriptQuery: API.FAVORITE.PATCH_DEL_FAVORITE_RESOURCES,
resources: `${favoriteResource.id}:${favoriteResource.type}`,
mediaId: selectedCategory.value?.id,
media_id: selectedCategory.value?.id,
csrf: getCSRF(),
}).then((res) => {
if (res.code === 0)

View File

@@ -7,6 +7,7 @@ import { calcCurrentTime } from '~/utils/dataFormatter'
import { Business } from '~/models/video/history'
import type { List as HistoryItem, HistoryResult } from '~/models/video/history'
import type { List as HistorySearchItem, HistorySearchResult } from '~/models/video/historySearch'
import API from '~/background/msg.define'
const { t } = useI18n()
@@ -57,9 +58,9 @@ function getHistoryList() {
isLoading.value = true
browser.runtime
.sendMessage({
contentScriptQuery: 'getHistoryList',
contentScriptQuery: API.HISTORY.GET_HISTORY_LIST,
type: 'all',
viewAt:
view_at:
historyList.length > 0
? historyList[historyList.length - 1].view_at
: 0,
@@ -85,7 +86,7 @@ function searchHistoryList() {
isLoading.value = true
browser.runtime
.sendMessage({
contentScriptQuery: 'searchHistoryList',
contentScriptQuery: API.HISTORY.SEARCH_HISTORY_LIST,
pn: currentPageNum.value++,
keyword: keyword.value,
})
@@ -119,7 +120,7 @@ function handleSearch() {
function deleteHistoryItem(index: number, historyItem: HistoryItem) {
browser.runtime
.sendMessage({
contentScriptQuery: 'deleteHistoryItem',
contentScriptQuery: API.HISTORY.DELETE_HISTORY_ITEM,
kid: `${historyItem.history.business}_${historyItem.history.oid}`,
csrf: getCSRF(),
})
@@ -169,7 +170,7 @@ function getHistoryItemCover(item: HistoryItem) {
function getHistoryPauseStatus() {
browser.runtime
.sendMessage({
contentScriptQuery: 'getHistoryPauseStatus',
contentScriptQuery: API.HISTORY.GET_HISTORY_PAUSE_STATUS,
})
.then((res) => {
if (res.code === 0)
@@ -180,7 +181,7 @@ function getHistoryPauseStatus() {
function setHistoryPauseStatus(isPause: boolean) {
browser.runtime
.sendMessage({
contentScriptQuery: 'setHistoryPauseStatus',
contentScriptQuery: API.HISTORY.SET_HISTORY_PAUSE_STATUS,
csrf: getCSRF(),
switch: isPause,
})
@@ -193,7 +194,7 @@ function setHistoryPauseStatus(isPause: boolean) {
function clearAllHistory() {
browser.runtime
.sendMessage({
contentScriptQuery: 'clearAllHistory',
contentScriptQuery: API.HISTORY.CLEAR_ALL_HISTORY,
csrf: getCSRF(),
})
.then((res) => {

View File

@@ -2,6 +2,7 @@
import type { Ref } from 'vue'
import type { GridLayout } from '~/logic'
import type { DataItem as MomentItem, MomentResult } from '~/models/moment/moment'
import API from '~/background/msg.define'
const props = defineProps<{
gridLayout: GridLayout
@@ -82,10 +83,10 @@ async function getFollowedUsersVideos() {
isLoading.value = true
try {
const response: MomentResult = await browser.runtime.sendMessage({
contentScriptQuery: 'getMoments',
contentScriptQuery: API.MOMENT.GET_MOMENTS,
type: 'video',
offset: offset.value,
updateBaseline: updateBaseline.value,
update_baseline: updateBaseline.value,
})
if (response.code === -101) {

View File

@@ -8,6 +8,7 @@ import type { Item as VideoItem, forYouResult } from '~/models/video/forYou'
import type { GridLayout } from '~/logic'
import { accessKey, settings } from '~/logic'
import { LanguageType } from '~/enums/appEnums'
import API from '~/background/msg.define'
import { TVAppKey, getTvSign } from '~/utils/authProvider'
const props = defineProps<{
@@ -132,8 +133,8 @@ async function getRecommendVideos() {
isLoading.value = true
try {
const response: forYouResult = await browser.runtime.sendMessage({
contentScriptQuery: 'getRecommendVideos',
refreshIdx: refreshIdx.value++,
contentScriptQuery: API.VIDEO.GET_RECOMMEND_VIDEOS,
fresh_idx: refreshIdx.value++,
})
if (!response.data) {
@@ -172,10 +173,10 @@ async function getAppRecommendVideos() {
isLoading.value = true
try {
const response: AppForYouResult = await browser.runtime.sendMessage({
contentScriptQuery: 'getAppRecommendVideos',
accessKey: accessKey.value,
sLocale: settings.value.language !== LanguageType.Mandarin_CN ? 'zh-Hant_TW' : 'zh-Hans_CN',
cLocale: settings.value.language !== LanguageType.Mandarin_CN ? 'zh-Hant_TW' : 'zh-Hans_CN',
contentScriptQuery: API.VIDEO.GET_APP_RECOMMEND_VIDEOS,
access_key: accessKey.value,
s_locale: settings.value.language !== LanguageType.Mandarin_CN ? 'zh-Hant_TW' : 'zh-Hans_CN',
c_locale: settings.value.language !== LanguageType.Mandarin_CN ? 'zh-Hant_TW' : 'zh-Hans_CN',
appkey: TVAppKey.appkey,
idx: appVideoList.length > 0 ? appVideoList[appVideoList.length - 1].idx : 1,
})
@@ -266,7 +267,7 @@ function handleDislike() {
}
browser.runtime.sendMessage({
contentScriptQuery: 'dislikeVideo',
contentScriptQuery: API.VIDEO.DISLIKE_VIDEO,
...params,
sign: getTvSign(params),
})
@@ -296,7 +297,7 @@ function handleUndoDislike(video: AppVideoItem) {
}
browser.runtime.sendMessage({
contentScriptQuery: 'undoDislikeVideo',
contentScriptQuery: API.VIDEO.UNDO_DISLIKE_VIDEO,
...params,
sign: getTvSign(params),
}).then((res) => {

View File

@@ -6,6 +6,7 @@ import type { List as RankingPgcItem, RankingPgcResult } from '~/models/video/ra
import type { GridLayout } from '~/logic'
import { settings } from '~/logic'
import emitter from '~/utils/mitt'
import API from '~/background/msg.define'
const props = defineProps<{
gridLayout: GridLayout
@@ -129,7 +130,7 @@ function getRankingVideos() {
emit('beforeLoading')
isLoading.value = true
browser.runtime.sendMessage({
contentScriptQuery: 'getRankingVideos',
contentScriptQuery: API.RANKING.GET_RANKING_VIDEOS,
rid: activatedRankingType.value.rid,
type: 'type' in activatedRankingType.value ? activatedRankingType.value.type : 'all',
}).then((response: RankingResult) => {
@@ -147,8 +148,8 @@ function getRankingPgc() {
PgcList.length = 0
isLoading.value = true
browser.runtime.sendMessage({
contentScriptQuery: 'getRankingPgc',
seasonType: activatedRankingType.value.seasonType,
contentScriptQuery: API.RANKING.GET_RANKING_PGC,
season_type: activatedRankingType.value.seasonType,
}).then((response: RankingPgcResult) => {
if (response.code === 0)
Object.assign(PgcList, response.result.list)

View File

@@ -2,6 +2,7 @@
import type { Ref } from 'vue'
import type { GridLayout } from '~/logic'
import type { DataItem as MomentItem, MomentResult } from '~/models/moment/moment'
import API from '~/background/msg.define'
const props = defineProps<{
gridLayout: GridLayout
@@ -86,10 +87,10 @@ async function getFollowedUsersVideos() {
isLoading.value = true
try {
const response: MomentResult = await browser.runtime.sendMessage({
contentScriptQuery: 'getMoments',
contentScriptQuery: API.MOMENT.GET_MOMENTS,
type: 'pgc',
offset: offset.value,
updateBaseline: updateBaseline.value,
update_baseline: updateBaseline.value,
})
if (response.code === -101) {

View File

@@ -2,6 +2,7 @@
import type { Ref } from 'vue'
import type { GridLayout } from '~/logic'
import type { TrendingResult, List as VideoItem } from '~/models/video/trending'
import API from '~/background/msg.define'
const props = defineProps<{
gridLayout: GridLayout
@@ -66,7 +67,7 @@ async function getTrendingVideos() {
isLoading.value = true
try {
const response: TrendingResult = await browser.runtime.sendMessage({
contentScriptQuery: 'getPopularVideos',
contentScriptQuery: API.VIDEO.GET_POPULAR_VIDEOS,
pn: pn.value++,
ps: 30,
})

View File

@@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n'
import { getCSRF, openLinkToNewTab, removeHttpFromUrl } from '~/utils/main'
import { calcCurrentTime } from '~/utils/dataFormatter'
import type { List as VideoItem, WatchLaterResult } from '~/models/video/watchLater'
import API from '~/background/msg.define'
const { t } = useI18n()
@@ -35,7 +36,7 @@ function getAllWatchLaterList() {
watchLaterList.length = 0
browser.runtime
.sendMessage({
contentScriptQuery: 'getAllWatchLaterList',
contentScriptQuery: API.WATCHLATER.GET_ALL_WATCHLATER_LIST,
})
.then((res: WatchLaterResult) => {
if (res.code === 0)
@@ -48,7 +49,7 @@ function getAllWatchLaterList() {
function deleteWatchLaterItem(index: number, aid: number) {
browser.runtime
.sendMessage({
contentScriptQuery: 'removeFromWatchLater',
contentScriptQuery: API.WATCHLATER.REMOVE_FROM_WATCHLATER,
aid,
csrf: getCSRF(),
})
@@ -65,7 +66,7 @@ function handleClearAllWatchLater() {
if (result) {
isLoading.value = true
browser.runtime.sendMessage({
contentScriptQuery: 'clearAllWatchLater',
contentScriptQuery: API.WATCHLATER.CLEAR_ALL_WATCHLATER,
csrf: getCSRF(),
}).then((res) => {
if (res.code === 0)
@@ -83,7 +84,7 @@ function handleRemoveWatchedVideos() {
if (result) {
browser.runtime
.sendMessage({
contentScriptQuery: 'removeFromWatchLater',
contentScriptQuery: API.WATCHLATER.REMOVE_FROM_WATCHLATER,
viewed: true,
csrf: getCSRF(),
})