-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontent_script.ts
39 lines (34 loc) · 1.06 KB
/
content_script.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type { BaseConverter } from './converters/base'
import { ChatGPTConverter } from './converters/chatgpt/convert'
import { ShareGPTConverter } from './converters/sharegpt/convert'
import type { ConvertInstructionRequest, ConvertInstructions, ConvertResult } from './schema'
const ConvertLists: BaseConverter[] = [new ChatGPTConverter(), new ShareGPTConverter()]
const tryConvert = (command: ConvertInstructions): ConvertResult => {
try {
for (const converter of ConvertLists) {
if (converter.isActive) {
const content = command === 'CONVERT' ? converter.convert() : converter.currentFileName
return {
success: true,
content,
}
}
}
} catch (e) {
return {
success: false,
error: `${e}`,
}
}
return {
success: false,
error: 'no convert found',
}
}
// get popup2content info
chrome.runtime.onMessage.addListener((request: ConvertInstructionRequest, sender, sendResponse) => {
const convertResult = tryConvert(request.command)
sendResponse({
result: convertResult,
})
})