INNER CODE UNIT · TypeScript
handleMessage
RyanYipeng/SyncCaster · apps/extension/src/content-scripts/index.ts:40
async function handleMessage(message: { type: string; data?: unknown }) {
switch (message.type) {
case 'COLLECT_CONTENT': return await collectContent();
case 'COLLECT_CONTENT_CANONICAL': return await collectContentCanonical();
case 'COLLECT_CONTENT_LEGACY': return await collectContent();
case 'FILL_AND_PUBLISH': return await fillAndPublish(message.data as { platform: string; payload: unknown });
case 'PING': return { pong: true };
case 'CHECK_LOGIN': return await detectLoginState();
case 'START_LOGIN_POLLING':
startLoginPolling((state) => chrome.runtime.sendMessage({ type: 'LOGIN_SUCCESS', data: state }));
return { started: true };
default: throw new Error('Unknown message type: ' + message.type);
}
}
/**
* 从原始 DOM 提取公式的 LaTeX
*/