@@ -4,11 +4,6 @@ import {convertImage} from '../utils.js';
4
4
5
5
const { i18n} = window . config ;
6
6
7
- async function doCopy ( content , btn ) {
8
- const success = await clippie ( content ) ;
9
- showTemporaryTooltip ( btn , success ? i18n . copy_success : i18n . copy_error ) ;
10
- }
11
-
12
7
export function initCopyContent ( ) {
13
8
const btn = document . getElementById ( 'copy-content' ) ;
14
9
if ( ! btn || btn . classList . contains ( 'disabled' ) ) return ;
@@ -43,15 +38,14 @@ export function initCopyContent() {
43
38
content = Array . from ( lineEls ) . map ( ( el ) => el . textContent ) . join ( '' ) ;
44
39
}
45
40
46
- try {
47
- await doCopy ( content , btn ) ;
48
- } catch {
49
- if ( isImage ) { // convert image to png as last-resort as some browser only support png copy
50
- try {
51
- await doCopy ( await convertImage ( content , 'image/png' ) , btn ) ;
52
- } catch {
53
- showTemporaryTooltip ( btn , i18n . copy_error ) ;
54
- }
41
+ // try copy original first, if that fails and it's an image, convert it to png
42
+ const success = await clippie ( content ) ;
43
+ if ( success ) {
44
+ showTemporaryTooltip ( btn , i18n . copy_success ) ;
45
+ } else {
46
+ if ( isImage ) {
47
+ const success = await clippie ( await convertImage ( content , 'image/png' ) ) ;
48
+ showTemporaryTooltip ( btn , success ? i18n . copy_success : i18n . copy_error ) ;
55
49
} else {
56
50
showTemporaryTooltip ( btn , i18n . copy_error ) ;
57
51
}
0 commit comments