@@ -26,7 +26,7 @@ function highlight() {
26
26
if ( link ) {
27
27
let target = link . parentElement ;
28
28
target . classList . add ( "rse-active" ) ;
29
- target . scrollIntoView ( { behavior : "auto" , block : "nearest" } ) ;
29
+ target . scrollIntoView ( { behavior : "auto" , block : "nearest" } ) ;
30
30
}
31
31
}
32
32
} ) ;
@@ -64,6 +64,7 @@ document.addEventListener("DOMContentLoaded", () => {
64
64
highlight ( ) ;
65
65
} ) ;
66
66
67
+ // Using separate event listener to avoid network requesting latency for feature flags menu enhancement.
67
68
document . addEventListener ( "DOMContentLoaded" , async ( ) => {
68
69
let menus = document . querySelector ( "form>.pure-menu-list:not(.pure-menu-right)" ) ;
69
70
if ( ! menus ) return ;
@@ -77,14 +78,24 @@ document.addEventListener("DOMContentLoaded", async () => {
77
78
}
78
79
} ) ;
79
80
80
- // Using separate event listener to avoid network requesting latency for feature flags menu enhancement.
81
81
document . addEventListener ( "DOMContentLoaded" , async ( ) => {
82
82
let menus = document . querySelector ( "form>.pure-menu-list:not(.pure-menu-right)" ) ;
83
83
if ( ! menus ) return ;
84
84
85
+ // Since this PR (https://github.com/rust-lang/docs.rs/pull/1527) merged,
86
+ // the latest version path has changed:
87
+ // from https://docs.rs/tokio/1.14.0/tokio/ to https://docs.rs/tokio/latest/tokio/
88
+ //
89
+ // If we parse the crate version from url is 'latest',
90
+ // we should reparse it from the DOM to get the correct value.
91
+ if ( crateVersion === 'latest' ) {
92
+ let versionText = document . querySelector ( 'nav.sidebar > div.block.version > p' ) . textContent ;
93
+ crateVersion = versionText . split ( ' ' ) [ 1 ] ;
94
+ }
95
+
85
96
// Exclude /crate/** pages
86
97
if ( menus . children . length >= 3 && ! location . pathname . includes ( "/crate/" ) ) {
87
- chrome . runtime . sendMessage ( { crateName, action : "crate:check" } , crate => {
98
+ chrome . runtime . sendMessage ( { crateName, action : "crate:check" } , crate => {
88
99
if ( crate ) {
89
100
insertAddToExtensionElement ( getState ( crate . version ) ) ;
90
101
} else {
@@ -153,7 +164,7 @@ function insertAddToExtensionElement(state) {
153
164
li . onclick = ( ) => {
154
165
// Toggle search index added state
155
166
if ( state === "latest" ) {
156
- chrome . runtime . sendMessage ( { crateName, action : "crate:remove" } , response => {
167
+ chrome . runtime . sendMessage ( { crateName, action : "crate:remove" } , response => {
157
168
insertAddToExtensionElement ( getState ( undefined ) ) ;
158
169
} ) ;
159
170
} else {
@@ -199,7 +210,7 @@ function insertAddToExtensionElement(state) {
199
210
if ( menu . querySelector ( "#rse-here" ) ) {
200
211
menu . querySelector ( "#rse-here" ) . onclick = ( ) => {
201
212
let url = chrome . runtime . getURL ( "manage/crates.html" ) ;
202
- chrome . runtime . sendMessage ( { action : "open-url" , url} ) ;
213
+ chrome . runtime . sendMessage ( { action : "open-url" , url } ) ;
203
214
} ;
204
215
}
205
216
}
@@ -208,7 +219,7 @@ window.addEventListener("message", function (event) {
208
219
if ( event . source === window &&
209
220
event . data &&
210
221
event . data . direction === "rust-search-extension" ) {
211
- chrome . runtime . sendMessage ( { action : "crate:add" , ...event . data . message } ,
222
+ chrome . runtime . sendMessage ( { action : "crate:add" , ...event . data . message } ,
212
223
( response ) => {
213
224
if ( response ) {
214
225
insertAddToExtensionElement ( getState ( event . data . message . crateVersion ) ) ;
0 commit comments