mirror of
https://github.com/davegallant/davegallant.github.io.git
synced 2025-08-10 18:32:28 +00:00
Switch to gruvbox theme
This commit is contained in:
0
public/js/.gitkeep
Normal file
0
public/js/.gitkeep
Normal file
@@ -1,59 +0,0 @@
|
||||
function createCopyButton(highlightDiv) {
|
||||
const button = document.createElement("button");
|
||||
button.className = "copy-code-button";
|
||||
button.type = "button";
|
||||
button.innerText = "Copy";
|
||||
button.addEventListener("click", () =>
|
||||
copyCodeToClipboard(button, highlightDiv)
|
||||
);
|
||||
highlightDiv.insertBefore(button, highlightDiv.firstChild);
|
||||
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.className = "highlight-wrapper";
|
||||
highlightDiv.parentNode.insertBefore(wrapper, highlightDiv);
|
||||
wrapper.appendChild(highlightDiv);
|
||||
}
|
||||
|
||||
document
|
||||
.querySelectorAll(".highlight")
|
||||
.forEach((highlightDiv) => createCopyButton(highlightDiv));
|
||||
|
||||
async function copyCodeToClipboard(button, highlightDiv) {
|
||||
const codeToCopy = highlightDiv
|
||||
.querySelector("pre > code ")
|
||||
.innerText.replace(/\n\n/g, "\n") // Fix the double spacing
|
||||
.replace(/\n$/, ""); // Clean up last empty line
|
||||
try {
|
||||
var result = await navigator.permissions.query({ name: "clipboard-write" });
|
||||
if (result.state == "granted" || result.state == "prompt") {
|
||||
await navigator.clipboard.writeText(codeToCopy);
|
||||
} else {
|
||||
copyCodeBlockExecCommand(codeToCopy, highlightDiv);
|
||||
}
|
||||
} catch (_) {
|
||||
copyCodeBlockExecCommand(codeToCopy, highlightDiv);
|
||||
} finally {
|
||||
button.blur();
|
||||
button.innerText = "Copied!";
|
||||
setTimeout(function () {
|
||||
button.innerText = "Copy";
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
function copyCodeBlockExecCommand(codeToCopy, highlightDiv) {
|
||||
const textArea = document.createElement("textArea");
|
||||
textArea.contentEditable = "true";
|
||||
textArea.readOnly = "false";
|
||||
textArea.className = "copyable-text-area";
|
||||
textArea.value = codeToCopy;
|
||||
highlightDiv.insertBefore(textArea, highlightDiv.firstChild);
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(textArea);
|
||||
const sel = window.getSelection();
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
textArea.setSelectionRange(0, 999999);
|
||||
document.execCommand("copy");
|
||||
highlightDiv.removeChild(textArea);
|
||||
}
|
13
public/js/feather.min.js
vendored
13
public/js/feather.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,36 +0,0 @@
|
||||
function setTheme(mode) {
|
||||
localStorage.setItem("theme-storage", mode);
|
||||
if (mode === "dark") {
|
||||
document.getElementById("darkModeStyle").disabled=false;
|
||||
document.getElementById("dark-mode-toggle").innerHTML = "<i data-feather=\"sun\"></i>";
|
||||
feather.replace();
|
||||
setUtterancesTheme("github-dark");
|
||||
} else if (mode === "light") {
|
||||
document.getElementById("darkModeStyle").disabled=true;
|
||||
document.getElementById("dark-mode-toggle").innerHTML = "<i data-feather=\"moon\"></i>";
|
||||
feather.replace();
|
||||
setUtterancesTheme("github-light");
|
||||
}
|
||||
}
|
||||
|
||||
function setUtterancesTheme (theme) {
|
||||
if (document.querySelector('.utterances-frame')) {
|
||||
const message = {
|
||||
type: 'set-theme',
|
||||
theme: theme
|
||||
};
|
||||
const iframe = document.querySelector('.utterances-frame');
|
||||
iframe.contentWindow.postMessage(message, 'https://utteranc.es');
|
||||
}
|
||||
}
|
||||
|
||||
function toggleTheme() {
|
||||
if (localStorage.getItem("theme-storage") === "light") {
|
||||
setTheme("dark");
|
||||
} else if (localStorage.getItem("theme-storage") === "dark") {
|
||||
setTheme("light");
|
||||
}
|
||||
}
|
||||
|
||||
var savedTheme = localStorage.getItem("theme-storage") || "light";
|
||||
setTheme(savedTheme);
|
Reference in New Issue
Block a user