@@ -2,21 +2,19 @@ import {clippie} from 'clippie';
22import { showTemporaryTooltip } from '../modules/tippy.ts' ;
33import { convertImage } from '../utils.ts' ;
44import { GET } from '../modules/fetch.ts' ;
5+ import { registerGlobalEventFunc } from '../modules/observer.ts' ;
56
67const { i18n} = window . config ;
78
89export function initCopyContent ( ) {
9- const btn = document . querySelector ( '#copy-content' ) ;
10- if ( ! btn || btn . classList . contains ( 'disabled' ) ) return ;
11-
12- btn . addEventListener ( 'click' , async ( ) => {
13- if ( btn . classList . contains ( 'is-loading' ) ) return ;
10+ registerGlobalEventFunc ( 'click' , 'onCopyContentButtonClick' , async ( btn : HTMLInputElement ) => {
11+ if ( btn . classList . contains ( 'disabled' ) || btn . classList . contains ( 'is-loading' ) ) return ;
1412 let content ;
1513 let isRasterImage = false ;
1614 const link = btn . getAttribute ( 'data-link' ) ;
1715
1816 // when data-link is present, we perform a fetch. this is either because
19- // the text to copy is not in the DOM or it is an image which should be
17+ // the text to copy is not in the DOM, or it is an image which should be
2018 // fetched to copy in full resolution
2119 if ( link ) {
2220 btn . classList . add ( 'is-loading' , 'loading-icon-2px' ) ;
@@ -40,7 +38,7 @@ export function initCopyContent() {
4038 content = Array . from ( lineEls , ( el ) => el . textContent ) . join ( '' ) ;
4139 }
4240
43- // try copy original first, if that fails and it's an image, convert it to png
41+ // try copy original first, if that fails, and it's an image, convert it to png
4442 const success = await clippie ( content ) ;
4543 if ( success ) {
4644 showTemporaryTooltip ( btn , i18n . copy_success ) ;
0 commit comments