Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the theme loader as to work when <head> isn't yet created #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# **************************************************************************** #
# #
Expand Down
56 changes: 33 additions & 23 deletions features/themes/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,51 @@
/* */
/* ************************************************************************** */

let themeColorsLink = null;
let themeLink = null;
// let themeColorsLink = null;
//let themeLink = null;

let themeLink = () => {
let raw = document.getElementById("#improved_intra__themelink");
if (raw === null)
{
raw = document.createElement("link");
raw.setAttribute("type", "text/css");
raw.setAttribute("rel", "stylesheet");
document.head.appendChild(raw);
}
return (raw);
};

let themeColorsLink = () => {
let raw = document.getElementById("#improved_intra__themecolorslink");
if (raw === null)
{
raw = document.createElement("link");
raw.setAttribute("type", "text/css");
raw.setAttribute("rel", "stylesheet");
document.head.appendChild(raw);
}
return (raw);
}


// Disable a theme, set theme or colors to false to not disable those colors
function disableTheme(theme, colors) {
if (theme !== false && themeLink) {
themeLink.remove();
themeLink = null;
if (theme !== false) {
themeLink().remove();
}
if (colors !== false && themeColorsLink) {
if (colors !== false) {
themeColorsLink.remove();
themeColorsLink = null;
reColorizeLogTimeChart();
}
}

// Enable a theme, leave colors as null or undefined to use default color scheme
function enableTheme(theme, colors) {
iConsole.log("Enabling theme '" + theme + "'" + (colors ? " in '" + colors + "' mode..." : ""));
if (!themeLink) {
themeLink = document.createElement("link");
themeLink.setAttribute("type", "text/css");
themeLink.setAttribute("rel", "stylesheet");
document.getElementsByTagName("head")[0].appendChild(themeLink);
}
themeLink.setAttribute("href", chrome.runtime.getURL("features/themes/"+theme+".css"));

themeLink().setAttribute("href", chrome.runtime.getURL("features/themes/"+theme+".css"));
if (colors && colors !== "default") {
if (!themeColorsLink) {
themeColorsLink = document.createElement("link");
themeColorsLink.setAttribute("type", "text/css");
themeColorsLink.setAttribute("rel", "stylesheet");
document.getElementsByTagName("head")[0].appendChild(themeColorsLink);
}
themeColorsLink.setAttribute("href", chrome.runtime.getURL("features/themes/colors/"+colors+".css"));
themeColorsLink().setAttribute("href", chrome.runtime.getURL("features/themes/colors/"+colors+".css"));
setTimeout(function() {
reColorizeLogTimeChart();
}, 100);
Expand Down Expand Up @@ -139,7 +149,7 @@ window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", fun
checkThemeSetting();
});

checkThemeSetting();
window.addEventListener("DOMContentLoaded", () => checkThemeSetting());

// fix sign in page issue with background image
window.addEventListener("DOMContentLoaded", function() {
Expand Down