[16] change background image dependant upon branch (#2127)
parent
faee45fcea
commit
88350a180b
After Width: | Height: | Size: 1.5 MiB |
After Width: | Height: | Size: 1.4 MiB |
@ -1,32 +1,31 @@
|
|||||||
// custom.js
|
|
||||||
|
|
||||||
// Function to check if the current URL contains "nightly" or "develop" and adjust styles accordingly
|
|
||||||
function checkURLForBranch() {
|
function checkURLForBranch() {
|
||||||
const currentURL = window.location.href;
|
const currentURL = window.location.href;
|
||||||
|
|
||||||
// Helper function to update style and text
|
// Select elements for background and text changes
|
||||||
function updateTheme(headerColor, tabsColor, textContent) {
|
const headerAndTabs = document.querySelectorAll(".md-header, .md-tabs");
|
||||||
const header = document.querySelector(".md-header");
|
const ellipsisSpan = document.querySelector(".md-ellipsis"); // Select ellipsisSpan
|
||||||
const tabs = document.querySelector(".md-tabs");
|
|
||||||
const ellipsisSpan = document.querySelector(".md-ellipsis");
|
|
||||||
|
|
||||||
if (header && tabs) { // Check if elements exist
|
if (headerAndTabs.length > 0) {
|
||||||
header.style.backgroundColor = headerColor;
|
let backgroundImage = "https://raw.githubusercontent.com/Kometa-Team/Kometa/nightly/docs/assets/background.jpg";
|
||||||
tabs.style.backgroundColor = tabsColor;
|
let ellipsisText = ""; // Initialize ellipsisText
|
||||||
}
|
|
||||||
|
|
||||||
if (ellipsisSpan) { // Check if element exists
|
if (currentURL.includes("en/nightly")) {
|
||||||
ellipsisSpan.textContent = textContent;
|
backgroundImage = "https://raw.githubusercontent.com/Kometa-Team/Kometa/nightly/docs/assets/backgroundnightly.jpg";
|
||||||
|
ellipsisText = "Kometa Nightly Wiki"; // Set text for Nightly
|
||||||
|
} else if (currentURL.includes("en/develop")) {
|
||||||
|
backgroundImage = "https://raw.githubusercontent.com/Kometa-Team/Kometa/nightly/docs/assets/backgrounddevelop.jpg";
|
||||||
|
ellipsisText = "Kometa Develop Wiki"; // Set text for Develop
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Change theme based on URL segment
|
headerAndTabs.forEach(element => {
|
||||||
if (currentURL.includes("en/nightly")) {
|
element.style.backgroundImage = `url(${backgroundImage})`;
|
||||||
updateTheme("#262dbd", "#262dbd", "Kometa Nightly Wiki");
|
});
|
||||||
} else if (currentURL.includes("en/develop")) {
|
|
||||||
updateTheme("#ffa724", "#ffa724", "Kometa Develop Wiki");
|
// Update ellipsisSpan text only if it exists
|
||||||
|
if (ellipsisSpan) {
|
||||||
|
ellipsisSpan.textContent = ellipsisText;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the function on page load
|
|
||||||
window.addEventListener("load", checkURLForBranch);
|
window.addEventListener("load", checkURLForBranch);
|
Loading…
Reference in new issue