mirror of
https://github.com/hnasheralneam/hnasheralneam.github.io.git
synced 2025-06-06 13:24:16 -04:00
Save theme color across pages
This commit is contained in:
parent
9c0a834c71
commit
ebb8568ca1
8 changed files with 46 additions and 85 deletions
24
scripts/copypopup.js
Normal file
24
scripts/copypopup.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
let url = document.location.href;
|
||||
|
||||
function copy(txt) {
|
||||
let link = `${url}#${txt}`;
|
||||
navigator.clipboard.writeText(link).then(() => {
|
||||
console.log("Copied link!");
|
||||
}, () => { console.log("Error copying link."); });
|
||||
let alert = document.createElement("DIV");
|
||||
alert.textContent = "Copied Link to Heading!";
|
||||
alert.classList.add("tempAlert");
|
||||
document.body.appendChild(alert);
|
||||
setTimeout(() => {
|
||||
alert.style.opacity = "1";
|
||||
alert.style.bottom = ".5rem";
|
||||
}, 200);
|
||||
setTimeout(() => {
|
||||
alert.style.opacity = "0";
|
||||
alert.style.bottom = "-10rem";
|
||||
}, 4200);
|
||||
setTimeout(() => {
|
||||
alert.remove();
|
||||
}, 4400);
|
||||
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
console.log("hello");
|
||||
|
||||
window.addEventListener("scroll", () => {
|
||||
document.body.style.setProperty("--scroll", window.pageYOffset / (document.body.offsetHeight - window.innerHeight));
|
||||
}, false);
|
||||
|
@ -20,8 +18,6 @@ function changeThemeHex() {
|
|||
}
|
||||
}
|
||||
|
||||
function setThemeColor(color) {
|
||||
document.documentElement.style.setProperty("--theme-color", color);
|
||||
let metaThemeColor = document.querySelector("meta[name=theme-color]");
|
||||
metaThemeColor.setAttribute("content", color);
|
||||
function resetTheme() {
|
||||
setThemeColor("#f69b46");
|
||||
}
|
11
scripts/script.js
Normal file
11
scripts/script.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
// theme color
|
||||
let themeColor = localStorage.getItem("theme-color");
|
||||
if (!themeColor) themeColor = "#f69b46";
|
||||
setThemeColor(themeColor);
|
||||
|
||||
function setThemeColor(color) {
|
||||
document.documentElement.style.setProperty("--theme-color", color);
|
||||
let metaThemeColor = document.querySelector("meta[name=theme-color]");
|
||||
metaThemeColor.setAttribute("content", color);
|
||||
localStorage.setItem("theme-color", color);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue