1
- function formatCrateName ( crateTitleAndVersion ) {
2
- const stringParts = crateTitleAndVersion . split ( " " , 2 ) ;
3
- return stringParts [ 0 ] + ' = "' + stringParts [ 1 ] + '"' ;
4
- }
5
-
6
1
( function ( ) {
7
2
const clipboard = document . getElementById ( "clipboard" ) ;
8
3
if ( clipboard ) {
@@ -14,23 +9,17 @@ function formatCrateName(crateTitleAndVersion) {
14
9
clipboard . innerHTML = resetClipboardIcon ;
15
10
}
16
11
17
- function copyTextHandler ( ) {
18
- const crateTitleAndVersion = document . getElementById ( "crate-title" ) ;
19
- // On rustdoc pages, we use `textTransform: uppercase`, which copies as uppercase.
20
- // To avoid that, reset the styles temporarily.
21
- const oldTransform = crateTitleAndVersion . style . textTransform ;
22
- crateTitleAndVersion . style . textTransform = "none" ;
23
- const temporaryInput = document . createElement ( "input" ) ;
12
+ async function copyTextHandler ( ) {
13
+ const metadata = JSON . parse ( document . getElementById ( "crate-metadata" ) . innerText )
24
14
15
+ const temporaryInput = document . createElement ( "input" ) ;
25
16
temporaryInput . type = "text" ;
26
- temporaryInput . value = formatCrateName ( crateTitleAndVersion . innerText ) ;
17
+ temporaryInput . value = ` ${ metadata . name } = " ${ metadata . version } "` ;
27
18
28
19
document . body . append ( temporaryInput ) ;
29
20
temporaryInput . select ( ) ;
30
21
document . execCommand ( "copy" ) ;
31
-
32
22
temporaryInput . remove ( ) ;
33
- crateTitleAndVersion . style . textTransform = oldTransform ;
34
23
35
24
clipboard . textContent = "✓" ;
36
25
if ( resetClipboardTimeout !== null ) {
0 commit comments