@@ -70,6 +70,22 @@ export class PopupMarker extends Marker {
7070 return true ;
7171 }
7272
73+ static copyToClipboard = ( text ) => {
74+ if ( navigator ?. clipboard ?. writeText ) {
75+ navigator . clipboard . writeText ( text )
76+ . catch ( e => console . error ( e ) ) ;
77+ console . log ( "Copied new!" ) ;
78+ } else {
79+ function listener ( e ) {
80+ e . clipboardData . setData ( "text/plain" , text ) ;
81+ e . preventDefault ( ) ;
82+ }
83+ document . addEventListener ( "copy" , listener ) ;
84+ document . execCommand ( "copy" ) ;
85+ document . removeEventListener ( "copy" , listener ) ;
86+ console . log ( "Copied old!" ) ;
87+ }
88+ }
7389 static blockClipboardFormat = ( pos , isHires ) => isHires ? `${ pos . x } ${ pos . y } ${ pos . z } ` : `${ pos . x } ${ pos . z } ` ;
7490 static chunkClipboardFormat = ( pos , isHires ) => isHires ? `${ pos . x } ${ pos . y } ${ pos . z } ` : `${ pos . x } ${ pos . z } ` ;
7591 static regionClipboardFormat = pos => `r.${ pos . x } .${ pos . y } .mca`
@@ -102,7 +118,7 @@ export class PopupMarker extends Marker {
102118 this . element . innerHTML = `
103119 <div class="group"
104120 data-tooltip="${ i18n . t ( "blockTooltip.clipboard" ) } "
105- onclick="navigator.clipboard.writeText ('${ PopupMarker . blockClipboardFormat ( this . position , true ) } ')" >
121+ onclick="BlueMap.PopupMarker.copyToClipboard ('${ PopupMarker . blockClipboardFormat ( this . position , true ) } ')" >
106122 <div class="label">${ i18n . t ( "blockTooltip.block" ) } :</div>
107123 <div class="content">
108124 <div class="entry"><span class="label">x: </span><span class="value">${ this . position . x } </span></div>
@@ -115,7 +131,7 @@ export class PopupMarker extends Marker {
115131 this . element . innerHTML = `
116132 <div class="group"
117133 data-tooltip="${ i18n . t ( "blockTooltip.clipboard" ) } "
118- onclick="navigator.clipboard.writeText ('${ PopupMarker . blockClipboardFormat ( this . position , false ) } ')" >
134+ onclick="BlueMap.PopupMarker.copyToClipboard ('${ PopupMarker . blockClipboardFormat ( this . position , false ) } ')" >
119135 <div class="label">${ i18n . t ( "blockTooltip.position" ) } :</div>
120136 <div class="content">
121137 <div class="entry"><span class="label">x: </span><span class="value">${ this . position . x } </span></div>
@@ -135,7 +151,7 @@ export class PopupMarker extends Marker {
135151 <hr>
136152 <div class="group"
137153 data-tooltip="${ i18n . t ( "blockTooltip.clipboard" ) } "
138- onclick="navigator.clipboard.writeText ('${ PopupMarker . chunkClipboardFormat ( chunkCoords , true ) } ')" >
154+ onclick="BlueMap.PopupMarker.copyToClipboard ('${ PopupMarker . chunkClipboardFormat ( chunkCoords , true ) } ')" >
139155 <div class="label">${ i18n . t ( "blockTooltip.chunk" ) } :</div>
140156 <div class="content">
141157 <div class="entry"><span class="label">x: </span><span class="value">${ chunkCoords . x } </span></div>
@@ -149,7 +165,7 @@ export class PopupMarker extends Marker {
149165 <hr>
150166 <div class="group"
151167 data-tooltip="${ i18n . t ( "blockTooltip.clipboard" ) } "
152- onclick="navigator.clipboard.writeText ('${ PopupMarker . chunkClipboardFormat ( chunkCoords , false ) } ')" >
168+ onclick="BlueMap.PopupMarker.copyToClipboard ('${ PopupMarker . chunkClipboardFormat ( chunkCoords , false ) } ')" >
153169 <div class="label">${ i18n . t ( "blockTooltip.chunk" ) } :</div>
154170 <div class="content">
155171 <div class="entry"><span class="label">x: </span><span class="value">${ chunkCoords . x } </span></div>
@@ -163,7 +179,7 @@ export class PopupMarker extends Marker {
163179 <hr>
164180 <div class="group"
165181 data-tooltip="${ i18n . t ( "blockTooltip.clipboard" ) } "
166- onclick="navigator.clipboard.writeText ('${ PopupMarker . regionClipboardFormat ( regionCoords ) } ')" >
182+ onclick="BlueMap.PopupMarker.copyToClipboard ('${ PopupMarker . regionClipboardFormat ( regionCoords ) } ')" >
167183 <div class="label">${ i18n . t ( "blockTooltip.region.region" ) } :</div>
168184 <div class="content">
169185 <div class="entry"><span class="label">x: </span><span class="value">${ regionCoords . x } </span></div>
0 commit comments