Skip to content

Commit 121b62b

Browse files
committed
Fix webp copying
1 parent a7e18b9 commit 121b62b

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

web_src/js/features/copycontent.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import {convertImage} from '../utils.js';
44

55
const {i18n} = window.config;
66

7-
async function doCopy(content, btn) {
8-
const success = await clippie(content);
9-
showTemporaryTooltip(btn, success ? i18n.copy_success : i18n.copy_error);
10-
}
11-
127
export function initCopyContent() {
138
const btn = document.getElementById('copy-content');
149
if (!btn || btn.classList.contains('disabled')) return;
@@ -43,15 +38,14 @@ export function initCopyContent() {
4338
content = Array.from(lineEls).map((el) => el.textContent).join('');
4439
}
4540

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);
5549
} else {
5650
showTemporaryTooltip(btn, i18n.copy_error);
5751
}

0 commit comments

Comments
 (0)