@@ -23,39 +23,34 @@ function locale() {
2323 return document . querySelector ( 'html' ) . lang ;
2424}
2525
26- function loadShim ( polyfill ) {
27- return new Promise ( ( resolve , reject ) => {
28- const shim = document . createElement ( 'script' ) ;
29- shim . src = polyfill ;
30- shim . addEventListener ( 'load' , ( ) => resolve ( true ) ) ;
31- shim . addEventListener ( 'error' , ( ) => resolve ( false ) ) ;
32- document . head . appendChild ( shim ) ;
33- } ) ;
34- }
35-
3626function isFile ( id ) {
3727 return / ^ [ 0 - 9 a - f A - F ] { 10 , 16 } $ / . test ( id ) ;
3828}
3929
40- function copyToClipboard ( str ) {
41- const aux = document . createElement ( 'input' ) ;
42- aux . setAttribute ( 'value' , str ) ;
43- aux . contentEditable = true ;
44- aux . readOnly = true ;
45- document . body . appendChild ( aux ) ;
46- if ( navigator . userAgent . match ( / i p h o n e | i p a d | i p o d / i) ) {
47- const range = document . createRange ( ) ;
48- range . selectNodeContents ( aux ) ;
49- const sel = getSelection ( ) ;
50- sel . removeAllRanges ( ) ;
51- sel . addRange ( range ) ;
52- aux . setSelectionRange ( 0 , str . length ) ;
53- } else {
54- aux . select ( ) ;
30+ async function copyToClipboard ( str ) {
31+ try {
32+ await navigator . clipboard . writeText ( str ) ;
33+ } catch {
34+ // Older browsers or the clipboard API fails because of a missing permission
35+ const aux = document . createElement ( 'input' ) ;
36+ aux . setAttribute ( 'value' , str ) ;
37+ aux . contentEditable = true ;
38+ aux . readOnly = true ;
39+ document . body . appendChild ( aux ) ;
40+ if ( navigator . userAgent . match ( / i p h o n e | i p a d | i p o d / i) ) {
41+ const range = document . createRange ( ) ;
42+ range . selectNodeContents ( aux ) ;
43+ const sel = getSelection ( ) ;
44+ sel . removeAllRanges ( ) ;
45+ sel . addRange ( range ) ;
46+ aux . setSelectionRange ( 0 , str . length ) ;
47+ } else {
48+ aux . select ( ) ;
49+ }
50+ const result = document . execCommand ( 'copy' ) ;
51+ document . body . removeChild ( aux ) ;
52+ return result ;
5553 }
56- const result = document . execCommand ( 'copy' ) ;
57- document . body . removeChild ( aux ) ;
58- return result ;
5954}
6055
6156const LOCALIZE_NUMBERS = ! ! (
@@ -287,7 +282,6 @@ module.exports = {
287282 copyToClipboard,
288283 arrayToB64,
289284 b64ToArray,
290- loadShim,
291285 isFile,
292286 openLinksInNewTab,
293287 browserName,
0 commit comments