async function parseCargoFeatures(url) { let response = await fetch(url); let page = await response.text(); let start = page.lastIndexOf("[features]"); if (start !== -1) { let section = page.slice(start + "[features]".length).split("\n["); let features = section[0].trim().replace(/"/ig, "\"").split("\n"); return features.map((item) => { let [name, flags] = item.split("="); flags = flags.trim().replace(/"/ig, ""); return [name, flags]; }); } else { return []; } } document.addEventListener("DOMContentLoaded", async () => { let ul = document.querySelector(".landing-search-form-nav>ul"); if (ul.children.length === 3) { let sourceLink = document.querySelector(".landing-search-form-nav>ul>li:nth-child(2)>a"); let features = await parseCargoFeatures(sourceLink.href + "Cargo.toml"); let html = `

This crate has no feature flag.

`; if (features.length > 0) { let tbody = features.map(([name, flags]) => { return ` ${name} = ${flags} ` }).join(""); html = `${tbody}
`; } sourceLink.parentElement.insertAdjacentHTML("beforebegin", `
  • Feature flags
  • `); } });