gitbook.events.bind("page.change", function() {
let runCodeLinks = $("p:contains('тествате примера онлайн:') a");
for (let link of runCodeLinks) {
if (typeof(link.href) == "string" && link.href.startsWith("https://repl.it/")) {
// A repl.it link is found --> check for code box above it
let codeBox = $(link).parent().prev();
if (codeBox.is("pre")) {
// A code box is found just before the code link --> inject the [Run] button
let runButton = $("Run");
let loadingBox = $("Loading …");
runButton.click(function() {
// Replace the code box with the embedded REPL box
loadingBox.show();
let replBox = $('');
replBox.attr("src", link.href + "?lite=true");
replBox.on("load", function(event) {
loadingBox.hide();
});
if (codeBox.next().is("iframe")) {
// We have already the iframe with the Repl.it -> first remove it
codeBox.next().remove();
}
codeBox.after(replBox);
return false;
});
codeBox.prepend(runButton);
codeBox.prepend(loadingBox);
// Delete the original REPL hyperlink from the DOM
$(link).parent().remove();
}
}
}
});