From 1d90292cb4d10363f2d245d02ad0b4b1d4b72fc9 Mon Sep 17 00:00:00 2001 From: Hakadao Date: Tue, 2 Apr 2024 19:07:45 +0800 Subject: [PATCH] refactor: Add cSpell words and update API calls --- .vscode/settings.json | 5 ++++- src/background/msg.define.ts | 2 +- src/components/SearchBar/SearchBar.vue | 3 ++- src/components/VideoCard/VideoCard.vue | 7 ++++--- src/contentScripts/views/Favorites/Favorites.vue | 7 ++++--- src/contentScripts/views/History/History.vue | 13 +++++++------ .../views/Home/components/Following.vue | 3 ++- src/contentScripts/views/Home/components/ForYou.vue | 5 +++-- .../views/Home/components/Ranking.vue | 5 +++-- .../views/Home/components/SubscribedSeries.vue | 3 ++- .../views/Home/components/Trending.vue | 3 ++- src/contentScripts/views/WatchLater/WatchLater.vue | 9 +++++---- 12 files changed, 39 insertions(+), 26 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 14808a24..6dbb6575 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,8 @@ { - "cSpell.words": ["Vitesse"], + "cSpell.words": [ + "Vitesse", + "WATCHLATER" + ], "typescript.tsdk": "node_modules/typescript/lib", "vite.autoStart": false, "editor.codeActionsOnSave": { diff --git a/src/background/msg.define.ts b/src/background/msg.define.ts index 3e660acb..e4a06817 100644 --- a/src/background/msg.define.ts +++ b/src/background/msg.define.ts @@ -61,7 +61,7 @@ enum WATCHLATER { SAVE_TO_WATCHLATER = 'saveToWatchLater', REMOVE_FROM_WATCHLATER = 'removeFromWatchLater', GET_ALL_WATCHLATER_LIST = 'getAllWatchLaterList', - CLEAR_ALL_HISTORY = 'clearAllWatchLater', + CLEAR_ALL_WATCHLATER = 'clearAllWatchLater', } const API = { diff --git a/src/components/SearchBar/SearchBar.vue b/src/components/SearchBar/SearchBar.vue index 74a48b7b..c0387361 100644 --- a/src/components/SearchBar/SearchBar.vue +++ b/src/components/SearchBar/SearchBar.vue @@ -8,6 +8,7 @@ import { getSearchHistory, removeSearchHistory, } from './searchHistoryProvider' +import API from '~/background/msg.define' defineProps<{ darkenOnFocus?: boolean @@ -53,7 +54,7 @@ function handleInput() { if (keyword.value.length > 0) { browser.runtime .sendMessage({ - contentScriptQuery: 'getSearchSuggestion', + contentScriptQuery: API.SEARCH.GET_SEARCH_SUGGESTION, term: keyword.value, }) .then((res: SuggestionResponse) => { diff --git a/src/components/VideoCard/VideoCard.vue b/src/components/VideoCard/VideoCard.vue index f0f8a828..6d0f788b 100644 --- a/src/components/VideoCard/VideoCard.vue +++ b/src/components/VideoCard/VideoCard.vue @@ -3,6 +3,7 @@ import { getCSRF, removeHttpFromUrl } from '~/utils/main' import { calcCurrentTime, calcTimeSince, numFormatter } from '~/utils/dataFormatter' import type { VideoPreviewResult } from '~/models/video/videoPreview' import { settings } from '~/logic' +import API from '~/background/msg.define' interface Props { id: number @@ -89,7 +90,7 @@ watch(() => isHover.value, (newValue) => { if (props.showPreview) { if (newValue && !previewVideoUrl.value && props.cid) { browser.runtime.sendMessage({ - contentScriptQuery: 'getVideoPreview', + contentScriptQuery: API.VIDEO.GET_VIDEO_PREVIEW, bvid: props.bvid, cid: props.cid, }).then((res: VideoPreviewResult) => { @@ -103,7 +104,7 @@ watch(() => isHover.value, (newValue) => { function toggleWatchLater() { if (!isInWatchLater.value) { browser.runtime.sendMessage({ - contentScriptQuery: 'saveToWatchLater', + contentScriptQuery: API.WATCHLATER.SAVE_TO_WATCHLATER, aid: props.id, csrf: getCSRF(), }) @@ -114,7 +115,7 @@ function toggleWatchLater() { } else { browser.runtime.sendMessage({ - contentScriptQuery: 'removeFromWatchLater', + contentScriptQuery: API.WATCHLATER.REMOVE_FROM_WATCHLATER, aid: props.id, csrf: getCSRF(), }) diff --git a/src/contentScripts/views/Favorites/Favorites.vue b/src/contentScripts/views/Favorites/Favorites.vue index 43ce5bd4..f9f677ab 100644 --- a/src/contentScripts/views/Favorites/Favorites.vue +++ b/src/contentScripts/views/Favorites/Favorites.vue @@ -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,7 +75,7 @@ function initPageAction() { async function getFavoriteCategories() { await browser.runtime .sendMessage({ - contentScriptQuery: 'getFavoriteCategories', + contentScriptQuery: API.FAVORITE.GET_FAVORITE_CATEGORIES, up_mid: getUserID(), }) .then((res: FavoritesCategoryResult) => { @@ -109,7 +110,7 @@ async function getFavoriteResources( try { const res: FavoritesResult = await browser.runtime .sendMessage({ - contentScriptQuery: 'getFavoriteResources', + contentScriptQuery: API.FAVORITE.GET_FAVORITE_RESOURCES, media_id, pn, keyword, @@ -158,7 +159,7 @@ function jumpToLoginPage() { function handleUnfavorite(favoriteResource: FavoriteResource) { browser.runtime.sendMessage({ - contentScriptQuery: 'patchDelFavoriteResources', + contentScriptQuery: API.FAVORITE.PATCH_DEL_FAVORITE_RESOURCES, resources: `${favoriteResource.id}:${favoriteResource.type}`, media_id: selectedCategory.value?.id, csrf: getCSRF(), diff --git a/src/contentScripts/views/History/History.vue b/src/contentScripts/views/History/History.vue index 9f5b91e5..863c6068 100644 --- a/src/contentScripts/views/History/History.vue +++ b/src/contentScripts/views/History/History.vue @@ -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,7 +58,7 @@ function getHistoryList() { isLoading.value = true browser.runtime .sendMessage({ - contentScriptQuery: 'getHistoryList', + contentScriptQuery: API.HISTORY.GET_HISTORY_LIST, type: 'all', view_at: historyList.length > 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) => { diff --git a/src/contentScripts/views/Home/components/Following.vue b/src/contentScripts/views/Home/components/Following.vue index d8296c35..58793303 100644 --- a/src/contentScripts/views/Home/components/Following.vue +++ b/src/contentScripts/views/Home/components/Following.vue @@ -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,7 +83,7 @@ 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, update_baseline: updateBaseline.value, diff --git a/src/contentScripts/views/Home/components/ForYou.vue b/src/contentScripts/views/Home/components/ForYou.vue index 0bfe78bd..0a2fca48 100644 --- a/src/contentScripts/views/Home/components/ForYou.vue +++ b/src/contentScripts/views/Home/components/ForYou.vue @@ -7,6 +7,7 @@ import type { GridLayout } from '~/logic' import { accessKey, settings } from '~/logic' import { LanguageType } from '~/enums/appEnums' import { TVAppKey } from '~/utils/authProvider' +import API from '~/background/msg.define' const props = defineProps<{ gridLayout: GridLayout @@ -103,7 +104,7 @@ async function getRecommendVideos() { isLoading.value = true try { const response: forYouResult = await browser.runtime.sendMessage({ - contentScriptQuery: 'getRecommendVideos', + contentScriptQuery: API.VIDEO.GET_RECOMMEND_VIDEOS, fresh_idx: refreshIdx.value++, }) @@ -143,7 +144,7 @@ async function getAppRecommendVideos() { isLoading.value = true try { const response: AppForYouResult = await browser.runtime.sendMessage({ - contentScriptQuery: 'getAppRecommendVideos', + 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', diff --git a/src/contentScripts/views/Home/components/Ranking.vue b/src/contentScripts/views/Home/components/Ranking.vue index f1508d22..4b1b3286 100644 --- a/src/contentScripts/views/Home/components/Ranking.vue +++ b/src/contentScripts/views/Home/components/Ranking.vue @@ -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,7 +148,7 @@ function getRankingPgc() { PgcList.length = 0 isLoading.value = true browser.runtime.sendMessage({ - contentScriptQuery: 'getRankingPgc', + contentScriptQuery: API.RANKING.GET_RANKING_PGC, season_type: activatedRankingType.value.seasonType, }).then((response: RankingPgcResult) => { if (response.code === 0) diff --git a/src/contentScripts/views/Home/components/SubscribedSeries.vue b/src/contentScripts/views/Home/components/SubscribedSeries.vue index 07fada91..f4f5537f 100644 --- a/src/contentScripts/views/Home/components/SubscribedSeries.vue +++ b/src/contentScripts/views/Home/components/SubscribedSeries.vue @@ -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,7 +87,7 @@ 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, update_baseline: updateBaseline.value, diff --git a/src/contentScripts/views/Home/components/Trending.vue b/src/contentScripts/views/Home/components/Trending.vue index 95a193e6..e6d50a78 100644 --- a/src/contentScripts/views/Home/components/Trending.vue +++ b/src/contentScripts/views/Home/components/Trending.vue @@ -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, }) diff --git a/src/contentScripts/views/WatchLater/WatchLater.vue b/src/contentScripts/views/WatchLater/WatchLater.vue index f6211e7e..db466024 100644 --- a/src/contentScripts/views/WatchLater/WatchLater.vue +++ b/src/contentScripts/views/WatchLater/WatchLater.vue @@ -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(), })