-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.tsx
70 lines (63 loc) · 1.67 KB
/
popup.tsx
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { useEffect, useState } from "react"
import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"
function IndexPopup() {
const [currentTab, setCurrentTab] = useState(null)
useEffect(() => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
setCurrentTab(tabs[0])
})
}, [])
const [apiToken] = useStorage("apiToken")
const handleScrapePostClick = () => {
console.log("inside handleClick")
console.log("This is the tab", currentTab)
sendToContentScript({ name: "grabData", body: "request hello" }).then(
(data) => {
console.log("this is the data", data)
}
)
//chrome.tabs.sendMessage(currentTab.id, { type: "grabData" })
console.log("endof handleScrapePostClick")
}
return (
<div
style={{
padding: 16
}}>
<h2>
Welcome to Socialmark{" "}
<a href="https://www.plasmo.com" target="_blank">
Socialmark
</a>{" "}
Extension!
</h2>
<p>ApiToken:{
apiToken == undefined ? "undefined" : apiToken
}</p>
{apiToken ? (
<>
<button onClick={handleScrapePostClick}>Upload Saved Posts</button>
</>
) : (
<>
<h3>Please enter your api token in the extension options</h3>
<a href="/options.html" target="_blank">
Extension Options
</a>
</>
)}
<br />
<br />
Your Token:
{apiToken ? (
" Saved"
) : (
<a href="/options.html" target="_blank">
Enter Here
</a>
)}{" "}
</div>
)
}
export default IndexPopup