let [_, crateVersion, crateName] = location.pathname.slice(1).split("/"); // A crate version which added to the extension. let currentCrateVersion = undefined; document.addEventListener("DOMContentLoaded", async () => { let ul = document.querySelector(".landing-search-form-nav>ul"); let childrenNumber = ul.children.length; if (childrenNumber >= 3) { await insertFeatureFlagsElement(childrenNumber); chrome.runtime.sendMessage({crateName, action: "check"}, crate => { if (crate) { currentCrateVersion = crate.version; } insertAddToExtensionElement(); }); } }); async function insertFeatureFlagsElement(number) { let sourceLink = document.querySelector(`.landing-search-form-nav>ul>li:nth-child(${number - 1})>a`); let response = await fetch(sourceLink.href + "Cargo.toml"); let features = await parseCargoFeatures(await response.text()); let html = `
This crate has no feature flag.
${name}
Add this crate to Rust Search Extension then you can search it in the address bar.
`; let iconAttributes = `class="fa fa-fw fa-plus-circle" style="color:#121212"`; if (state === "latest") { content = `You already added this crate (v${currentCrateVersion}). Click again to remove it.
`; iconAttributes = `class="fa fa-fw fa-check-circle" style="color:green"`; } else if (state === "outdated") { content = `You current version v${currentCrateVersion} is outdated. Click to update to the v${crateVersion}.
`; iconAttributes = `class="fa fa-fw fa-arrow-circle-up" style="color:#e57300"`; } li.innerHTML = `