Skip to content

Commit

Permalink
change background image dependant upon branch
Browse files Browse the repository at this point in the history
  • Loading branch information
YozoraXCII committed Jun 20, 2024
1 parent faee45f commit 12378db
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
Binary file added docs/assets/backgrounddevelop.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/backgroundnightly.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
---
title: Home
---
#

<style>
Expand Down
43 changes: 21 additions & 22 deletions docs/stylesheets/branch.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
// custom.js

// Function to check if the current URL contains "nightly" or "develop" and adjust styles accordingly
function checkURLForBranch() {
const 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 elements for background and text changes
const headerAndTabs = document.querySelectorAll(".md-header, .md-tabs");
const ellipsisSpan = document.querySelector(".md-ellipsis"); // Select ellipsisSpan

if (header && tabs) { // Check if elements exist
header.style.backgroundColor = headerColor;
tabs.style.backgroundColor = tabsColor;
}
if (headerAndTabs.length > 0) {
let backgroundImage = "https://raw.githubusercontent.com/Kometa-Team/Kometa/nightly/docs/assets/background.jpg";
let ellipsisText = ""; // Initialize ellipsisText

if (ellipsisSpan) { // Check if element exists
ellipsisSpan.textContent = textContent;
if (currentURL.includes("en/nightly")) {
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
if (currentURL.includes("en/nightly")) {
updateTheme("#262dbd", "#262dbd", "Kometa Nightly Wiki");
} else if (currentURL.includes("en/develop")) {
updateTheme("#ffa724", "#ffa724", "Kometa Develop Wiki");
headerAndTabs.forEach(element => {
element.style.backgroundImage = `url(${backgroundImage})`;
});

// 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);

0 comments on commit 12378db

Please sign in to comment.