Skip to content

Commit 3fae3a2

Browse files
committed
rename runtime messages
1 parent 878dbc6 commit 3fae3a2

File tree

7 files changed

+38
-29
lines changed

7 files changed

+38
-29
lines changed

src/contents/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const auth = async () => {
1212
const code = new URLSearchParams(window.location.search).get("code")
1313
if (!code) return
1414
await chrome.runtime.sendMessage({
15-
type: "generateToken",
15+
type: "chatgpt-to-notion_generateToken",
1616
body: { code }
1717
})
1818
}

src/contents/autoSave.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const callback = async (mutations: MutationRecord[]) => {
100100
const generateHeadings = true
101101

102102
const { conflictingPageId } = await chrome.runtime.sendMessage({
103-
type: "checkSaveConflict",
103+
type: "chatgpt-to-notion_checkSaveConflict",
104104
body: {
105105
title,
106106
database
@@ -114,7 +114,7 @@ const callback = async (mutations: MutationRecord[]) => {
114114
conflictingPageId
115115
}
116116
const res = await chrome.runtime.sendMessage({
117-
type: "autoSave",
117+
type: "chatgpt-to-notion_autoSave",
118118
body: parsedReq
119119
})
120120
saving = false

src/contents/fetchFullPage.ts

+22-21
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,29 @@ export const config: PlasmoContentScript = {
55
}
66

77
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
8-
if (message.type === "fetchFullChat") {
9-
const matches = document.querySelectorAll(".group.w-full")
10-
const chat = Array.from(matches)
8+
if (message.type === "fetchFullChat") sendResponse(fetchFullChat())
9+
})
1110

12-
const rawPrompts = chat.filter((el, index) => index % 2 === 0)
13-
const rawAnswers = chat.filter((el, index) => index % 2 === 1)
11+
const fetchFullChat = () => {
12+
const matches = document.querySelectorAll(".group.w-full")
13+
const chat = Array.from(matches)
1414

15-
const prompts = rawPrompts.map(
16-
(el) => el.querySelector(".whitespace-pre-wrap")?.textContent
17-
)
18-
const answers = rawAnswers.map(
19-
(el) =>
20-
(
21-
el.querySelector(".markdown") ??
22-
el.querySelector(".dark.text-orange-500")
23-
)?.innerHTML
24-
)
15+
const rawPrompts = chat.filter((el, index) => index % 2 === 0)
16+
const rawAnswers = chat.filter((el, index) => index % 2 === 1)
2517

26-
const url = window.location.href
27-
const title = document.title
18+
const prompts = rawPrompts.map(
19+
(el) => el.querySelector(".whitespace-pre-wrap")?.textContent
20+
)
21+
const answers = rawAnswers.map(
22+
(el) =>
23+
(
24+
el.querySelector(".markdown") ??
25+
el.querySelector(".dark.text-orange-500")
26+
)?.innerHTML
27+
)
2828

29-
const res = { prompts, answers, url, title }
30-
sendResponse(res)
31-
}
32-
})
29+
const url = window.location.href
30+
const title = document.title
31+
32+
return { prompts, answers, url, title }
33+
}

src/contents/popup.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export const config: PlasmoContentScript = {
1414
matches: ["https://chat.openai.com/*"]
1515
}
1616

17+
chrome.runtime.onMessage.addListener((message) => {
18+
if (message.type === "chatgpt-to-notion_alert") alert(message.body)
19+
})
20+
1721
export const getStyle: PlasmoGetStyle = () => {
1822
const style = document.createElement("style")
1923
style.textContent = styleText

src/popup/DatabaseSettings.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function DatabaseSettingsPopup() {
4141
const refreshDatabase = async () => {
4242
setRefreshing(true)
4343
const db: DatabaseObjectResponse = await chrome.runtime.sendMessage({
44-
type: "getDB",
44+
type: "chatgpt-to-notion_getDB",
4545
body: {
4646
id: databases[selectedDB].id
4747
}

src/popup/SavePopup.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default function SavePopup() {
7575

7676
const database = db!
7777
const checkRes = await chrome.runtime.sendMessage({
78-
type: "checkSaveConflict",
78+
type: "chatgpt-to-notion_checkSaveConflict",
7979
body: {
8080
title,
8181
database
@@ -116,7 +116,7 @@ export default function SavePopup() {
116116
}
117117
const parsedReq = await parseSave(req)
118118
const res = await chrome.runtime.sendMessage({
119-
type: "saveChat",
119+
type: "chatgpt-to-notion_saveChat",
120120
body: {
121121
...parsedReq,
122122
conflictingPageId,

src/popup/SettingsPopup.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { DatabaseObjectResponse } from "@notionhq/client/build/src/api-endpoints"
2-
import { useState } from "react"
2+
import { useEffect, useState } from "react"
33

44
import { useStorage } from "@plasmohq/storage/hook"
55

@@ -30,14 +30,18 @@ function SettingsPopup() {
3030
[]
3131
)
3232

33+
useEffect(() => {
34+
console.log(databases)
35+
}, [databases])
36+
3337
const [authenticated] = useStorage("authenticated", false)
3438

3539
const refreshSearch = useDebounce(
3640
async () => {
3741
setDbError(null)
3842
setFetching(true)
3943
const response = await chrome.runtime.sendMessage({
40-
type: "search",
44+
type: "chatgpt-to-notion_search",
4145
body: {
4246
query
4347
}

0 commit comments

Comments
 (0)