From 29d910d06e924d8b53e66e0d7b2f3c66e9d63222 Mon Sep 17 00:00:00 2001 From: lifeadventurer Date: Mon, 17 Jun 2024 22:05:47 +0800 Subject: [PATCH] Feat: Copied to clipboard notice and close #37 --- fortune_generator/js/fortune.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/fortune_generator/js/fortune.js b/fortune_generator/js/fortune.js index 085624f..2fdd4f4 100644 --- a/fortune_generator/js/fortune.js +++ b/fortune_generator/js/fortune.js @@ -304,6 +304,7 @@ function copyResultImageToClipboard() { backgroundColor: backgroundColor, // Set background color dynamically }).then(blob => { navigator.clipboard.write([new ClipboardItem({ [blob.type]: blob })]); + showCopiedNotice(); $title.parent().remove(); }).catch(error => { console.error('Error converting result page to image:', error); @@ -314,4 +315,27 @@ function copyResultImageToClipboard() { } } +function showCopiedNotice() { + const notice = $('
', { + text: 'Copied to clipboard!', + css: { + position: 'fixed', + bottom: '20px', + right: '20px', + padding: '10px 20px', + backgroundColor: 'rgba(0, 0, 0, 0.7)', + color: '#fff', + borderRadius: '5px', + zIndex: 1000, + } + }); + + $('body').append(notice); + + setTimeout(() => { + notice.fadeOut(300, () => { + notice.remove(); + }); + }, 3000); +} init_page();