mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-12 23:20:25 +08:00
hopefully fixed config not saving and loading
This commit is contained in:
parent
f03c4f8390
commit
5fbc59270c
2 changed files with 43 additions and 16 deletions
|
@ -105,6 +105,29 @@ async function getLanguage(lang) {
|
|||
}
|
||||
}
|
||||
|
||||
function setCookie(cname, cvalue, exdays) {
|
||||
var d = new Date();
|
||||
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
|
||||
var expires = "expires=" + d.toUTCString();
|
||||
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
||||
}
|
||||
|
||||
function getCookie(cname) {
|
||||
var name = cname + "=";
|
||||
var decodedCookie = decodeURIComponent(document.cookie);
|
||||
var ca = decodedCookie.split(";");
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) == " ") {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(name) == 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function smooth(arr, windowSize, getter = (value) => value, setter) {
|
||||
const get = getter;
|
||||
const result = [];
|
||||
|
|
|
@ -87,12 +87,13 @@ async function saveConfigToCookie(noDbCheck = false) {
|
|||
if (!dbConfigLoaded && !noDbCheck) {
|
||||
configChangedBeforeDb = true;
|
||||
}
|
||||
let d = new Date();
|
||||
d.setFullYear(d.getFullYear() + 1);
|
||||
$.cookie("config", JSON.stringify(config), {
|
||||
expires: d,
|
||||
path: "/",
|
||||
});
|
||||
// let d = new Date();
|
||||
// d.setFullYear(d.getFullYear() + 1);
|
||||
// $.cookie("config", JSON.stringify(config), {
|
||||
// expires: d,
|
||||
// path: "/",
|
||||
// });
|
||||
setCookie("config", JSON.stringify(config), 365);
|
||||
restartCount = 0;
|
||||
if (!noDbCheck) await saveConfigToDB();
|
||||
}
|
||||
|
@ -133,19 +134,21 @@ function saveActiveTagsToCookie() {
|
|||
tags.push(tag.id);
|
||||
}
|
||||
});
|
||||
let d = new Date();
|
||||
d.setFullYear(d.getFullYear() + 1);
|
||||
$.cookie("activeTags", null);
|
||||
$.cookie("activeTags", JSON.stringify(tags), {
|
||||
expires: d,
|
||||
path: "/",
|
||||
});
|
||||
// let d = new Date();
|
||||
// d.setFullYear(d.getFullYear() + 1);
|
||||
// $.cookie("activeTags", null);
|
||||
// $.cookie("activeTags", JSON.stringify(tags), {
|
||||
// expires: d,
|
||||
// path: "/",
|
||||
// });
|
||||
setCookie("activeTags", JSON.stringify(tags), 365);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function loadConfigFromCookie() {
|
||||
console.log("loading cookie config");
|
||||
let newConfig = $.cookie("config");
|
||||
// let newConfig = $.cookie("config");
|
||||
let newConfig = getCookie("config");
|
||||
if (newConfig !== undefined) {
|
||||
newConfig = JSON.parse(newConfig);
|
||||
applyConfig(newConfig);
|
||||
|
@ -286,8 +289,9 @@ function applyConfig(configObj) {
|
|||
}
|
||||
|
||||
function loadActiveTagsFromCookie() {
|
||||
let newTags = $.cookie("activeTags");
|
||||
if (newTags !== undefined) {
|
||||
// let newTags = $.cookie("activeTags");
|
||||
let newTags = getCookie("activeTags");
|
||||
if (newTags !== undefined && newTags !== "") {
|
||||
newTags = JSON.parse(newTags);
|
||||
newTags.forEach((ntag) => {
|
||||
toggleTag(ntag, true);
|
||||
|
|
Loading…
Reference in a new issue