Only fetch crates list on pages with playpens
This commit is contained in:
parent
bdb37ec117
commit
cae8a8ffe2
|
@ -18,13 +18,23 @@ function playpen_text(playpen) {
|
||||||
(function codeSnippets() {
|
(function codeSnippets() {
|
||||||
// Hide Rust code lines prepended with a specific character
|
// Hide Rust code lines prepended with a specific character
|
||||||
var hiding_character = "#";
|
var hiding_character = "#";
|
||||||
var request = fetch("https://play.rust-lang.org/meta/crates", {
|
|
||||||
|
var playpens = Array.from(document.querySelectorAll(".playpen"));
|
||||||
|
if (playpens.length > 0) {
|
||||||
|
fetch("https://play.rust-lang.org/meta/crates", {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': "application/json",
|
'Content-Type': "application/json",
|
||||||
},
|
},
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(response => {
|
||||||
|
// get list of crates available in the rust playground
|
||||||
|
let playground_crates = response.crates.map(item => item["id"]);
|
||||||
|
playpens.forEach(block => handle_crate_list_update(block, playground_crates));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function handle_crate_list_update(playpen_block, playground_crates) {
|
function handle_crate_list_update(playpen_block, playground_crates) {
|
||||||
// update the play buttons after receiving the response
|
// update the play buttons after receiving the response
|
||||||
|
@ -274,17 +284,6 @@ function playpen_text(playpen) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
request
|
|
||||||
.then(function (response) { return response.json(); })
|
|
||||||
.then(function (response) {
|
|
||||||
// get list of crates available in the rust playground
|
|
||||||
let playground_crates = response.crates.map(function (item) { return item["id"]; });
|
|
||||||
Array.from(document.querySelectorAll(".playpen")).forEach(function (block) {
|
|
||||||
handle_crate_list_update(block, playground_crates);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(function themes() {
|
(function themes() {
|
||||||
|
|
Loading…
Reference in New Issue