add branch detection background image changes

This commit is contained in:
Yozora XCII 2024-06-17 13:29:43 +01:00 committed by meisnate12
parent c13e173658
commit c80cc7d107
4 changed files with 35 additions and 27 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

@ -1,6 +1,3 @@
---
title: Home
---
# #
<style> <style>

View file

@ -1,32 +1,43 @@
// custom.js // JavaScript code to change background image and text content based on URL
// Function to check if the current URL contains "nightly" or "develop" and adjust styles accordingly // Function to change the background image and text content
function checkURLForBranch() { function updatePageContent() {
const currentURL = window.location.href; // Get the current URL
var currentURL = window.location.href;
// Helper function to update style and text // Select the elements with the class .md-header and .md-tabs
function updateTheme(headerColor, tabsColor, textContent) { var elements = document.querySelectorAll('.md-header, .md-tabs');
const header = document.querySelector(".md-header");
const tabs = document.querySelector(".md-tabs");
const ellipsisSpan = document.querySelector(".md-ellipsis");
if (header && tabs) { // Check if elements exist // Select the element with the class .md-ellipsis
header.style.backgroundColor = headerColor; var ellipsisSpan = document.querySelector('.md-ellipsis');
tabs.style.backgroundColor = tabsColor;
// Variables for background image and text content
var backgroundImage = '';
var textContent = '';
// Determine which background image and text content to use based on the URL
if (currentURL.includes('guide')) {
backgroundImage = "url('/en/nightly/assets/backgroundnightly.jpg')";
textContent = "Kometa Nightly Wiki";
} else if (currentURL.includes('develop')) {
backgroundImage = "url('/en/nightly/assets/backgrounddevelop.jpg')";
textContent = "Kometa Develop Wiki";
} else {
// Default values if neither "guide" nor "develop" is found in the URL
backgroundImage = "url('/assets/background.jpg')";
textContent = "Kometa Wiki";
} }
if (ellipsisSpan) { // Check if element exists // Update the background image of the selected elements
ellipsisSpan.textContent = textContent; elements.forEach(function(element) {
} element.style.backgroundImage = backgroundImage;
} });
// Change theme based on URL segment // Update the text content of the .md-ellipsis element
if (currentURL.includes("en/nightly")) { if (ellipsisSpan) {
updateTheme("#262dbd", "#262dbd", "Kometa Nightly Wiki"); ellipsisSpan.textContent = textContent;
} else if (currentURL.includes("en/develop")) { }
updateTheme("#ffa724", "#ffa724", "Kometa Develop Wiki");
}
} }
// Call the function on page load // Call the function to update the page content
window.addEventListener("load", checkURLForBranch); updatePageContent();