Add CSS override for banner (#3933)

* Add css override for banner

* remove merge conflict
This commit is contained in:
Jack Gerrits 2024-10-23 17:26:53 -04:00 committed by GitHub
parent bf407d99b4
commit e772951146
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 28 additions and 21 deletions

View File

@ -1,29 +1,36 @@
// When body is ready // When body is ready
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', async function() {
// TODO: Please find a better way to override the button text in a better way...
// Set a timer for 3 seconds to wait for the button to be rendered.
setTimeout(async function() {
// Fetch version list const styles = `
// https://raw.githubusercontent.com/microsoft/autogen/refs/heads/main/docs/switcher.json #bd-header-version-warning {
const response = await fetch('https://raw.githubusercontent.com/microsoft/autogen/refs/heads/main/docs/switcher.json'); display: none !important;
const data = await response.json(); }
`;
// Find the entry where preferred is true // Fetch version list
const preferred = data.find(entry => entry.preferred); // https://raw.githubusercontent.com/microsoft/autogen/refs/heads/main/docs/switcher.json
if (preferred) { const response = await fetch('https://raw.githubusercontent.com/microsoft/autogen/refs/heads/main/docs/switcher.json');
// Get current rendered version const data = await response.json();
const currentVersion = DOCUMENTATION_OPTIONS.VERSION;
const urlVersionPath = DOCUMENTATION_OPTIONS.theme_switcher_version_match; // Find the entry where preferred is true
// The version compare library seems to not like the dev suffix without - so we're going to do an exact match and hide the banner if so const preferred = data.find(entry => entry.preferred);
// For the "dev" version which is always latest we don't want to consider hiding the banner if (preferred) {
if ((currentVersion === preferred.version) && (urlVersionPath !== "dev")) { // Get current rendered version
// Hide the banner with id bd-header-version-warning const currentVersion = DOCUMENTATION_OPTIONS.VERSION;
document.getElementById('bd-header-version-warning').style.display = 'none'; const urlVersionPath = DOCUMENTATION_OPTIONS.theme_switcher_version_match;
return; // The version compare library seems to not like the dev suffix without - so we're going to do an exact match and hide the banner if so
} // For the "dev" version which is always latest we don't want to consider hiding the banner
if ((currentVersion === preferred.version) && (urlVersionPath !== "dev")) {
// Hide the banner with id bd-header-version-warning
const styleSheet = document.createElement("style");
styleSheet.textContent = styles;
document.head.appendChild(styleSheet);
return;
} }
}
// TODO: Please find a better way to override the button text...
setTimeout(async function() {
// Get the button with class "pst-button-link-to-stable-version". There is only one. // Get the button with class "pst-button-link-to-stable-version". There is only one.
var button = document.querySelector('.pst-button-link-to-stable-version'); var button = document.querySelector('.pst-button-link-to-stable-version');
if (!button) { if (!button) {