You've already forked bilibili-subtitle
fix
This commit is contained in:
@@ -108,52 +108,6 @@ class ExtensionMessage {
|
||||
this.portIdToPort.delete(id)
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Note: Return true when sending a response asynchronously.
|
||||
*/
|
||||
// chrome.runtime.onMessage.addListener((event: MessageData, sender: chrome.runtime.MessageSender, sendResponse: (result: any) => void) => {
|
||||
// this.debug((sender.tab != null) ? `tab ${sender.tab.url ?? ''} => ` : 'extension => ', event)
|
||||
|
||||
// // check event target
|
||||
// if (event.target !== MESSAGE_TARGET_EXTENSION) return
|
||||
|
||||
// const method = this.methods?.[event.method]
|
||||
// if (method != null) {
|
||||
// method(event.params, {
|
||||
// from: event.from,
|
||||
// event,
|
||||
// sender,
|
||||
// }).then(data => sendResponse({
|
||||
// success: true,
|
||||
// code: 200,
|
||||
// data,
|
||||
// })).catch(err => {
|
||||
// console.error(err)
|
||||
// let message
|
||||
// if (err instanceof Error) {
|
||||
// message = err.message
|
||||
// } else if (typeof err === 'string') {
|
||||
// message = err
|
||||
// } else {
|
||||
// message = 'error: ' + JSON.stringify(err)
|
||||
// }
|
||||
// sendResponse({
|
||||
// success: false,
|
||||
// code: 500,
|
||||
// message,
|
||||
// })
|
||||
// })
|
||||
// return true
|
||||
// } else {
|
||||
// console.error('Unknown method:', event.method)
|
||||
// sendResponse({
|
||||
// success: false,
|
||||
// code: 501,
|
||||
// message: 'Unknown method: ' + event.method,
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
broadcastMessageExact = async (tabIds: number[], target: string, method: string, params?: any) => {
|
||||
|
@@ -75,25 +75,6 @@ class InjectMessage {
|
||||
this.portMessageHandler!.startListen()
|
||||
this.portMessageHandler!.init('inject')
|
||||
this.methods = methods
|
||||
// listen message from app
|
||||
// startListening({}).then(e => {
|
||||
// const { postMessage, listenMessage, destroy } = e
|
||||
// this.postMessageToApp = postMessage
|
||||
// listenMessage((method, params, sendResponse) => {
|
||||
// this.messageHandler({
|
||||
// from: 'app',
|
||||
// target: MESSAGE_TARGET_INJECT,
|
||||
// method,
|
||||
// params,
|
||||
// }, null, sendResponse)
|
||||
// })
|
||||
// }).catch(console.error)
|
||||
|
||||
/**
|
||||
* listen message from extension
|
||||
* Attention: return true if you need to sendResponse asynchronously
|
||||
*/
|
||||
// chrome.runtime.onMessage.addListener(this.messageHandler)
|
||||
}
|
||||
|
||||
sendExtension = async <T = any>(method: string, params?: any): Promise<T> => {
|
||||
|
@@ -92,65 +92,6 @@ const useMessageService = (methods?: {
|
||||
return pmh
|
||||
}
|
||||
}, [messageHandler, port])
|
||||
|
||||
// connect to inject
|
||||
// useEffect(() => {
|
||||
// let destroyFunc: (() => void) | undefined
|
||||
|
||||
// const serverObject = {
|
||||
// server: window.parent, // openedWindow / window.parent / window.opener;
|
||||
// origin: '*', // target-window's origin or *
|
||||
// }
|
||||
// const options = {}
|
||||
// callServer(serverObject, options).then(e => {
|
||||
// const { postMessage, listenMessage, destroy } = e
|
||||
// postInjectMessage = postMessage
|
||||
// destroyFunc = destroy
|
||||
|
||||
// listenMessage((method, params, sendResponse) => {
|
||||
// debug('inject => ', method, params)
|
||||
|
||||
// const success = messageHandler(method, params, {
|
||||
// from: 'inject',
|
||||
// event: {
|
||||
// method,
|
||||
// params,
|
||||
// },
|
||||
// })
|
||||
// sendResponse({
|
||||
// success,
|
||||
// code: success ? 200 : 500
|
||||
// })
|
||||
// })
|
||||
|
||||
// debug('message ready')
|
||||
// }).catch(console.error)
|
||||
|
||||
// return () => {
|
||||
// destroyFunc?.()
|
||||
// }
|
||||
// }, [messageHandler])
|
||||
|
||||
// const extensionMessageCallback = useCallback((event: MessageData, sender: chrome.runtime.MessageSender, sendResponse: (response?: any) => void) => {
|
||||
// debug((sender.tab != null) ? `tab ${sender.tab.url??''} => ` : 'extension => ', JSON.stringify(event))
|
||||
|
||||
// // check event target
|
||||
// if (!event || event.target !== MESSAGE_TARGET_APP) return
|
||||
|
||||
// messageHandler(event.method, event.params, {
|
||||
// from: 'extension',
|
||||
// event,
|
||||
// sender,
|
||||
// })
|
||||
// }, [messageHandler])
|
||||
|
||||
// // listen for message
|
||||
// useEffect(() => {
|
||||
// chrome.runtime.onMessage.addListener(extensionMessageCallback)
|
||||
// return () => {
|
||||
// chrome.runtime.onMessage.removeListener(extensionMessageCallback)
|
||||
// }
|
||||
// }, [extensionMessageCallback])
|
||||
}
|
||||
|
||||
export default useMessageService
|
||||
|
Reference in New Issue
Block a user