switch to local storage
All checks were successful
Jenkins
Ellpeck/Web/pipeline/head This commit looks good
All checks were successful
Jenkins
Ellpeck/Web/pipeline/head This commit looks good
This commit is contained in:
parent
2844b58dda
commit
11c00e85b3
7 changed files with 26 additions and 45 deletions
|
@ -22,7 +22,10 @@ nav: nav/blognav.html
|
||||||
{% else %}
|
{% else %}
|
||||||
<script>
|
<script>
|
||||||
let style = dark ? "monokai" : "friendly";
|
let style = dark ? "monokai" : "friendly";
|
||||||
addStyle(`https://cdn.jsdelivr.net/gh/richleland/pygments-css@master/${style}.css`);
|
$('head').append($("<link/>", {
|
||||||
|
rel: "stylesheet",
|
||||||
|
href: `https://cdn.jsdelivr.net/gh/richleland/pygments-css@master/${style}.css`
|
||||||
|
}));
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,6 @@
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
|
||||||
<script src="/scripts/util.js"></script>
|
|
||||||
<script src="/scripts/main.js"></script>
|
<script src="/scripts/main.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script src="../scripts/util.js"></script>
|
|
||||||
|
|
||||||
<script data-ad-client="ca-pub-5754829579653773" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
<script data-ad-client="ca-pub-5754829579653773" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,16 @@ function populateManual(lang) {
|
||||||
entries.append(t);
|
entries.append(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
forceToAnchor();
|
let anchor = undefined || location.hash;
|
||||||
|
// this is probably a terrible hack
|
||||||
|
if (anchor.startsWith("#")) {
|
||||||
|
let element = $(anchor);
|
||||||
|
if (element.length) {
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: element.offset().top
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceFormatting(text) {
|
function replaceFormatting(text) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
if (getCookie("notification") !== "true") {
|
if (localStorage.getItem("notification") !== "true") {
|
||||||
$('#cookieinfo').html( /*html*/ `
|
$('#cookieinfo').html( /*html*/ `
|
||||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||||
This site uses cookies to store information about your browsing activity.
|
This site uses your browser's local storage to store information about your browsing activity.
|
||||||
<br>For more information, check out the <a href="/privacy">privacy policy</a>.
|
<br>For more information, check out the <a href="/privacy">privacy policy</a>.
|
||||||
<br>Have a nice day!
|
<br>Have a nice day!
|
||||||
<button type="button" class="close" data-dismiss="alert" id="notif-close">
|
<button type="button" class="close" data-dismiss="alert" id="notif-close">
|
||||||
|
@ -10,6 +10,6 @@ if (getCookie("notification") !== "true") {
|
||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
$("#notif-close").on("click", function () {
|
$("#notif-close").on("click", function () {
|
||||||
setCookie("notification", "true", 365);
|
localStorage.setItem("notification", "true");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
const darkCookie = getCookie("dark");
|
const darkCookie = localStorage.getItem("dark");
|
||||||
const dark = darkCookie == undefined ? window.matchMedia("(prefers-color-scheme: dark)").matches : darkCookie == "true";
|
const dark = darkCookie === null ? window.matchMedia("(prefers-color-scheme: dark)").matches : darkCookie === "true";
|
||||||
if (dark)
|
if (dark)
|
||||||
addStyle("/style/dark.css");
|
$('head').append($("<link/>", {
|
||||||
|
rel: "stylesheet",
|
||||||
|
href: "/style/dark.css"
|
||||||
|
}));
|
||||||
|
|
||||||
// redirect legacy anchors
|
// redirect legacy anchors
|
||||||
if (/^#privacy\/?$/.test(location.hash))
|
if (/^#privacy\/?$/.test(location.hash))
|
||||||
|
@ -21,8 +24,8 @@ $(function () {
|
||||||
let mode = $('#dark-mode');
|
let mode = $('#dark-mode');
|
||||||
mode.prop('checked', dark);
|
mode.prop('checked', dark);
|
||||||
mode.on('click', function () {
|
mode.on('click', function () {
|
||||||
setCookie("dark", $(this).prop('checked'), 365);
|
localStorage.setItem("dark", $(this).prop('checked'));
|
||||||
location.hash = "";
|
location.hash = "";
|
||||||
location.reload();
|
location.reload();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
function getCookie(key) {
|
|
||||||
let match = new RegExp(`${key}=([^;]+);?`, "g").exec(document.cookie);
|
|
||||||
return match ? match[1] : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setCookie(key, value, days) {
|
|
||||||
let date = new Date();
|
|
||||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
||||||
document.cookie = `${key}=${value}; expires=${date.toUTCString()}; path=/`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function forceToAnchor(customAnchor) {
|
|
||||||
let anchor = customAnchor || location.hash;
|
|
||||||
// this is probably a terrible hack
|
|
||||||
if (anchor.startsWith("#")) {
|
|
||||||
let element = $(anchor);
|
|
||||||
if (element.length) {
|
|
||||||
$('html, body').animate({
|
|
||||||
scrollTop: element.offset().top
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addStyle(path) {
|
|
||||||
$('head').append($("<link/>", {
|
|
||||||
rel: "stylesheet",
|
|
||||||
href: path
|
|
||||||
}));
|
|
||||||
}
|
|
Loading…
Reference in a new issue