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>

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 checkURLForBranch() {
const currentURL = window.location.href;
// Function to change the background image and text content
function updatePageContent() {
// Get the current URL
var currentURL = window.location.href;
// Helper function to update style and text
function updateTheme(headerColor, tabsColor, textContent) {
const header = document.querySelector(".md-header");
const tabs = document.querySelector(".md-tabs");
const ellipsisSpan = document.querySelector(".md-ellipsis");
// Select the elements with the class .md-header and .md-tabs
var elements = document.querySelectorAll('.md-header, .md-tabs');
if (header && tabs) { // Check if elements exist
header.style.backgroundColor = headerColor;
tabs.style.backgroundColor = tabsColor;
// Select the element with the class .md-ellipsis
var ellipsisSpan = document.querySelector('.md-ellipsis');
// 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
elements.forEach(function(element) {
element.style.backgroundImage = backgroundImage;
});
// Update the text content of the .md-ellipsis element
if (ellipsisSpan) {
ellipsisSpan.textContent = textContent;
}
}
// Change theme based on URL segment
if (currentURL.includes("en/nightly")) {
updateTheme("#262dbd", "#262dbd", "Kometa Nightly Wiki");
} else if (currentURL.includes("en/develop")) {
updateTheme("#ffa724", "#ffa724", "Kometa Develop Wiki");
}
}
// Call the function on page load
window.addEventListener("load", checkURLForBranch);
// Call the function to update the page content
updatePageContent();