mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
refactor: reorganize files and adjust variable names
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
import { setupAnimeAPIs } from './anime'
|
||||
import { setupAuthAPIs } from './auth'
|
||||
import { setupVideosAPIs } from './videos'
|
||||
import { setupUserAPIs } from './user'
|
||||
import { setupSearchAPIs } from './search'
|
||||
import { setupNotificationsAPIs } from './notifications'
|
||||
import { setupMomentsAPIs } from './moments'
|
||||
import { setupHistoryAPIs } from './history'
|
||||
import { setupFavoritesAPIs } from './favorites'
|
||||
|
||||
export const setupAllAPIs = () => {
|
||||
setupAuthAPIs()
|
||||
setupVideosAPIs()
|
||||
setupUserAPIs()
|
||||
setupSearchAPIs()
|
||||
setupNotificationsAPIs()
|
||||
setupMomentsAPIs()
|
||||
setupHistoryAPIs()
|
||||
setupFavoritesAPIs()
|
||||
setupAnimeAPIs()
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import type { Tabs } from 'webextension-polyfill'
|
||||
import browser from 'webextension-polyfill'
|
||||
// import { onMessage, sendMessage } from 'webext-bridge'
|
||||
import { resetCss } from './resetWebsiteStyle'
|
||||
import { setupAllAPIs } from './apis'
|
||||
import { setupAllMsgLstnrs } from './messageListeners'
|
||||
|
||||
browser.runtime.onInstalled.addListener((): void => {
|
||||
// eslint-disable-next-line no-console
|
||||
@@ -128,5 +128,5 @@ browser.tabs.onUpdated.addListener((tabId: number, changInfo: Tabs.OnUpdatedChan
|
||||
}
|
||||
})
|
||||
|
||||
// Setup APIs
|
||||
setupAllAPIs()
|
||||
// Setup all message listeners
|
||||
setupAllMsgLstnrs()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
// import { getUserID } from '~/utils'
|
||||
|
||||
export const setupAnimeAPIs = () => {
|
||||
export const setupAnimeMsgLstnr = () => {
|
||||
browser.runtime.onConnect.addListener(() => {
|
||||
browser.runtime.onMessage.addListener((message) => {
|
||||
// get popular anime list
|
||||
@@ -1,6 +1,6 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const setupAuthAPIs = () => {
|
||||
export const setupAuthMsgLstnr = () => {
|
||||
browser.runtime.onConnect.addListener(() => {
|
||||
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
if (message.contentScriptQuery === 'getAccessKey') {
|
||||
@@ -1,6 +1,6 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const setupFavoritesAPIs = () => {
|
||||
export const setupFavoriteMsgLstnr = () => {
|
||||
browser.runtime.onConnect.addListener(() => {
|
||||
browser.runtime.onMessage.addListener((message) => {
|
||||
// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/fav/info.md#%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E7%94%A8%E6%88%B7%E5%88%9B%E5%BB%BA%E7%9A%84%E6%89%80%E6%9C%89%E6%94%B6%E8%97%8F%E5%A4%B9%E4%BF%A1%E6%81%AF
|
||||
@@ -1,6 +1,6 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const setupHistoryAPIs = () => {
|
||||
export const setupHistoryMsgLstnr = () => {
|
||||
browser.runtime.onConnect.addListener(() => {
|
||||
browser.runtime.onMessage.addListener((message) => {
|
||||
// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/history&toview/history.md#%E8%8E%B7%E5%8F%96%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95%E5%88%97%E8%A1%A8_web%E7%AB%AF
|
||||
23
src/background/messageListeners/index.ts
Normal file
23
src/background/messageListeners/index.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { setupAnimeMsgLstnr } from './anime'
|
||||
import { setupAuthMsgLstnr } from './auth'
|
||||
import { setupVideoMsgLstnr } from './video'
|
||||
import { setupUserMsgLstnr } from './user'
|
||||
import { setupSearchMsgLstnr } from './search'
|
||||
import { setupNotificationMsgLstnr } from './notification'
|
||||
import { setupMomentMsgLstnr } from './moment'
|
||||
import { setupHistoryMsgLstnr } from './history'
|
||||
import { setupFavoriteMsgLstnr } from './favorite'
|
||||
import { setupWatchLaterMsgLstnr } from './watchLater'
|
||||
|
||||
export const setupAllMsgLstnrs = () => {
|
||||
setupAuthMsgLstnr()
|
||||
setupVideoMsgLstnr()
|
||||
setupUserMsgLstnr()
|
||||
setupSearchMsgLstnr()
|
||||
setupNotificationMsgLstnr()
|
||||
setupMomentMsgLstnr()
|
||||
setupHistoryMsgLstnr()
|
||||
setupFavoriteMsgLstnr()
|
||||
setupAnimeMsgLstnr()
|
||||
setupWatchLaterMsgLstnr()
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const setupMomentsAPIs = () => {
|
||||
export const setupMomentMsgLstnr = () => {
|
||||
browser.runtime.onConnect.addListener(() => {
|
||||
browser.runtime.onMessage.addListener((message) => {
|
||||
if (message.contentScriptQuery === 'getNewMomentsCount') {
|
||||
@@ -1,6 +1,6 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const setupNotificationsAPIs = () => {
|
||||
export const setupNotificationMsgLstnr = () => {
|
||||
browser.runtime.onConnect.addListener(() => {
|
||||
browser.runtime.onMessage.addListener((message) => {
|
||||
if (message.contentScriptQuery === 'getUnreadMsg') {
|
||||
@@ -1,6 +1,6 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const setupSearchAPIs = () => {
|
||||
export const setupSearchMsgLstnr = () => {
|
||||
browser.runtime.onConnect.addListener(() => {
|
||||
browser.runtime.onMessage.addListener((message) => {
|
||||
if (message.contentScriptQuery === 'getSearchSuggestion') {
|
||||
@@ -1,6 +1,6 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const setupUserAPIs = () => {
|
||||
export const setupUserMsgLstnr = () => {
|
||||
browser.runtime.onConnect.addListener(() => {
|
||||
browser.runtime.onMessage.addListener((message) => {
|
||||
if (message.contentScriptQuery === 'getUserInfo') {
|
||||
@@ -1,6 +1,6 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const setupVideosAPIs = () => {
|
||||
export const setupVideoMsgLstnr = () => {
|
||||
browser.runtime.onConnect.addListener(() => {
|
||||
browser.runtime.onMessage.addListener((message) => {
|
||||
// #region APP端api,遺棄
|
||||
@@ -88,34 +88,6 @@ export const setupVideosAPIs = () => {
|
||||
.then(data => data)
|
||||
.catch(error => console.error(error))
|
||||
}
|
||||
// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/history&toview/toview.md#%E8%A7%86%E9%A2%91%E6%B7%BB%E5%8A%A0%E7%A8%8D%E5%90%8E%E5%86%8D%E7%9C%8B
|
||||
else if (message.contentScriptQuery === 'saveToWatchLater') {
|
||||
const url = 'https://api.bilibili.com/x/v2/history/toview/add'
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams({
|
||||
csrf: message.csrf,
|
||||
aid: message.aid,
|
||||
}),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => data)
|
||||
.catch(error => console.error(error))
|
||||
}
|
||||
// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/history&toview/toview.md#%E5%88%A0%E9%99%A4%E7%A8%8D%E5%90%8E%E5%86%8D%E7%9C%8B%E8%A7%86%E9%A2%91
|
||||
else if (message.contentScriptQuery === 'removeFromWatchLater') {
|
||||
const url = 'https://api.bilibili.com/x/v2/history/toview/del'
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams({
|
||||
csrf: message.csrf,
|
||||
aid: message.aid,
|
||||
}),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => data)
|
||||
.catch(error => console.error(error))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
36
src/background/messageListeners/watchLater.ts
Normal file
36
src/background/messageListeners/watchLater.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import browser from 'webextension-polyfill'
|
||||
|
||||
export const setupWatchLaterMsgLstnr = () => {
|
||||
browser.runtime.onConnect.addListener(() => {
|
||||
browser.runtime.onMessage.addListener((message) => {
|
||||
// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/history&toview/toview.md#%E8%A7%86%E9%A2%91%E6%B7%BB%E5%8A%A0%E7%A8%8D%E5%90%8E%E5%86%8D%E7%9C%8B
|
||||
if (message.contentScriptQuery === 'saveToWatchLater') {
|
||||
const url = 'https://api.bilibili.com/x/v2/history/toview/add'
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams({
|
||||
csrf: message.csrf,
|
||||
aid: message.aid,
|
||||
}),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => data)
|
||||
.catch(error => console.error(error))
|
||||
}
|
||||
// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/history&toview/toview.md#%E5%88%A0%E9%99%A4%E7%A8%8D%E5%90%8E%E5%86%8D%E7%9C%8B%E8%A7%86%E9%A2%91
|
||||
else if (message.contentScriptQuery === 'removeFromWatchLater') {
|
||||
const url = 'https://api.bilibili.com/x/v2/history/toview/del'
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams({
|
||||
csrf: message.csrf,
|
||||
aid: message.aid,
|
||||
}),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => data)
|
||||
.catch(error => console.error(error))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user