Skip to content

Commit

Permalink
Publishing to gh-pages (publish.sh)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayamir committed Apr 26, 2024
1 parent d3dc497 commit d568f00
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions public/js/theme-mode.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
function switchTheme() {
const currentStyle = currentTheme();
const iconElement = document.getElementById('github-icon');
const iconElement = document.getElementById("github-icon");

if (currentStyle === 'light') {
setTheme('dark');
setIconTheme('dark')
if (currentStyle === "light") {
setTheme("dark");
setIconTheme("dark");
if (iconElement) {
iconElement.setAttribute('class', 'octicon');
iconElement.setAttribute('color', '#f0f6fc');
iconElement.setAttribute("class", "octicon");
iconElement.setAttribute("color", "#f0f6fc");
}
}
else {
setTheme('light');
setIconTheme('light')
} else {
setTheme("light");
setIconTheme("light");
if (iconElement) {
iconElement.removeAttribute('color');
iconElement.removeAttribute('class');
iconElement.removeAttribute("color");
iconElement.removeAttribute("class");
}
}
}

function setTheme(style) {
document.querySelectorAll('.isInitialToggle').forEach(elem => {
elem.classList.remove('isInitialToggle');
document.querySelectorAll(".isInitialToggle").forEach((elem) => {
elem.classList.remove("isInitialToggle");
});
document.documentElement.setAttribute('data-color-mode', style);
localStorage.setItem('data-color-mode', style);
document.documentElement.setAttribute("data-color-mode", style);
const message = {
type: "set-theme",
theme: style == "dark" ? "github-dark" : "github-light",
};
const iframe = document.querySelector(".utterances-frame");
iframe.contentWindow.postMessage(message, "https://utteranc.es");
localStorage.setItem("data-color-mode", style);
}

function setIconTheme(theme) {
twitterIconElement = document.getElementById('twitter-icon');
if (theme === 'light') {
twitterIconElement.setAttribute("fill", "black")
} else if (theme === 'dark') {
twitterIconElement.setAttribute("fill", "white")
twitterIconElement = document.getElementById("twitter-icon");
if (theme === "light") {
twitterIconElement.setAttribute("fill", "black");
} else if (theme === "dark") {
twitterIconElement.setAttribute("fill", "white");
}
}

function currentTheme() {
const localStyle = localStorage.getItem('data-color-mode');
const systemStyle = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
const localStyle = localStorage.getItem("data-color-mode");
const systemStyle =
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
return localStyle || systemStyle;
}

Expand Down

0 comments on commit d568f00

Please sign in to comment.