Skip to content

Commit fdc0109

Browse files
committed
feat: show copied status
1 parent df81199 commit fdc0109

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

packages/userscript/src/main.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,28 @@ function main() {
3232
divider.className = 'Navigation__NavMenuDivider'
3333
container.appendChild(divider)
3434

35+
const copyHtml = `${iconCopy}Copy`
36+
const copiedHtml = `${iconCopy}Copied`
3537
const copyButton = <HTMLAnchorElement>firstItem.cloneNode(true)
3638
copyButton.removeAttribute('href')
37-
copyButton.innerHTML = `${iconCopy}Copy`
38-
copyButton.addEventListener('click', () => copyToText())
39+
copyButton.innerHTML = copyHtml
40+
copyButton.addEventListener('click', () => {
41+
const items = getConversation()
42+
if (items.length === 0) {
43+
// eslint-disable-next-line no-alert
44+
alert('No conversation found. Please send a message first.')
45+
return
46+
}
47+
48+
const text = conversationToText(items)
49+
copyToClipboard(text)
50+
51+
copyButton.innerHTML = copiedHtml
52+
setTimeout(() => {
53+
copyButton.innerHTML = copyHtml
54+
copyButton.classList.remove('copied')
55+
}, 3000)
56+
})
3957
container.appendChild(copyButton)
4058

4159
const htmlButton = <HTMLAnchorElement>firstItem.cloneNode(true)
@@ -46,18 +64,6 @@ function main() {
4664
})
4765
}
4866

49-
function copyToText() {
50-
const items = getConversation()
51-
if (items.length === 0) {
52-
// eslint-disable-next-line no-alert
53-
alert('No conversation found. Please send a message first.')
54-
return
55-
}
56-
57-
const text = conversationToText(items)
58-
copyToClipboard(text)
59-
}
60-
6167
function exportToHtml() {
6268
const items = getConversation()
6369
if (items.length === 0) {

0 commit comments

Comments
 (0)