const themes = getThemes();
document.querySelector("span").textContent = themes[0];
hljs.highlightAll();
document.addEventListener("keydown", (event) => {
if (event.key === "ArrowRight") {
nextTheme();
event.preventDefault();
} else if (event.key === "ArrowLeft") {
prevTheme();
event.preventDefault();
}
});
function prevTheme() {
themes.unshift(themes.pop());
changeTheme();
}
function nextTheme() {
themes.push(themes.shift());
changeTheme();
}
function changeTheme() {
document.querySelector('link[href*="highlight.js"]').remove();
const link = document.createElement("link");
const theme = themes[0];
link.rel = "stylesheet";
link.href = `https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/${theme}.min.css`;
document.querySelector("head").append(link);
document.querySelector("span").textContent = theme;
}
function getThemes() {
return [
"a11y-dark",
"a11y-light",
"agate",
"an-old-hope",
"androidstudio",
"arduino-light",
"arta",
"ascetic",
"atom-one-dark-reasonable",
"atom-one-dark",
"atom-one-light",
"brown-paper",
"codepen-embed",
"color-brewer",
"dark",
"default",
"devibeans",
"docco",
"far",
"felipec",
"foundation",
"github-dark-dimmed",
"github-dark",
"github",
"gml",
"googlecode",
"gradient-dark",
"gradient-light",
"grayscale",
"hybrid",
"idea",
"intellij-light",
"ir-black",
"isbl-editor-dark",
"isbl-editor-light",
"kimbie-dark",
"kimbie-light",
"lightfair",
"lioshi",
"magula",
"mono-blue",
"monokai-sublime",
"monokai",
"night-owl",
"nnfx-dark",
"nnfx-light",
"nord",
"obsidian",
"panda-syntax-dark",
"panda-syntax-light",
"paraiso-dark",
"paraiso-light",
"pojoaque",
"purebasic",
"qtcreator-dark",
"qtcreator-light",
"rainbow",
"routeros",
"school-book",
"shades-of-purple",
"srcery",
"stackoverflow-dark",
"stackoverflow-light",
"sunburst",
"tokyo-night-dark",
"tokyo-night-light",
"tomorrow-night-blue",
"tomorrow-night-bright",
"vs",
"vs2015",
"xcode",
"xt256",
];
}
<meta name="color-scheme" content="dark light" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/a11y-dark.min.css"
/>
<button type="button" onclick="prevTheme()"><</button>
<button type="button" onclick="nextTheme()">></button>
<span></span>
<pre><code>{
"web-app": {
"servlet-name": "cofaxTools",
"servlet-class": "org.cofax.cms.CofaxToolsServlet",
"init-param": {
"log": true,
"logMaxSize": null,
"dataLog": 1123
}
}
}</code></pre>