forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.tsx
More file actions
57 lines (51 loc) · 1.28 KB
/
popup.tsx
File metadata and controls
57 lines (51 loc) · 1.28 KB
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
import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
const Popup = function () {
const [count, setCount] = useState(0);
const [currentURL, setCurrentURL] = useState<string>();
useEffect(() => {
chrome.action.setBadgeText({ text: count.toString() });
}, [count]);
useEffect(() => {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
setCurrentURL(tabs[0].url);
});
}, []);
const changeBackground = () => {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const tab = tabs[0];
if (tab.id) {
chrome.tabs.sendMessage(
tab.id,
{
color: '#555555',
},
(msg) => {
// eslint-disable-next-line no-console
console.log('result message:', msg);
},
);
}
});
};
return (
<>
<ul style={{ minWidth: '700px' }}>
<li>Current URL: {currentURL}</li>
<li>Current Time: {new Date().toLocaleTimeString()}</li>
</ul>
<button type="button" onClick={() => setCount(count + 1)} style={{ marginRight: '5px' }}>
count up
</button>
<button type="button" onClick={changeBackground}>
change background
</button>
</>
);
};
ReactDOM.render(
<React.StrictMode>
<Popup />
</React.StrictMode>,
document.getElementById('root'),
);