1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Updated javascript

This commit is contained in:
Krateng 2019-11-20 21:10:50 +01:00
parent 9b7bc5e38e
commit f540862881
2 changed files with 7 additions and 48 deletions

View File

@ -1,53 +1,12 @@
apikeycorrect = false;
var cookies = {};
function getCookies() {
cookiestrings = decodeURIComponent(document.cookie).split(';');
for(var i = 0; i <cookiestrings.length; i++) {
cookiestrings[i] = cookiestrings[i].trim();
[key,value] = cookiestrings[i].split("=");
cookies[key] = value;
}
}
// always on document load, but call specifically when needed early
document.addEventListener("load",getCookies);
function setCookie(key,val,session=true) {
cookies[key] = val;
if (!session) {
var d = new Date();
d.setTime(d.getTime() + (500*24*60*60*1000));
expirestr = "expires=" + d.toUTCString();
}
else {
expirestr = ""
}
document.cookie = encodeURIComponent(key) + "=" + encodeURIComponent(val) + ";" + expirestr;
}
function saveCookies() {
for (var c in cookies) {
document.cookie = encodeURIComponent(c) + "=" + encodeURIComponent(cookies[c]);
}
}
/// RANGE SELECTORS
// in rangeselect.js
/// API KEY
function insertAPIKeyFromCookie() {
element = document.getElementById("apikey")
if (element != null && element != undefined) {
getCookies();
key = cookies["apikey"];
var key = neo.getCookie("apikey");
if (key != null && key != undefined) {
element.value = key;
checkAPIkey();
@ -62,7 +21,7 @@ window.addEventListener("load",insertAPIKeyFromCookie);
function saveAPIkey() {
key = APIkey();
setCookie("apikey",key,false);
neo.setCookie("apikey",key,false);
}

View File

@ -38,16 +38,16 @@ function showRange(identifier,unit) {
function showRangeManual(identifier,unit) {
showRange(identifier,unit);
setCookie("rangeselect_" + identifier,unit);
neo.setCookie("rangeselect_" + identifier,unit);
}
document.addEventListener('DOMContentLoaded',function() {
getCookies();
for (c in cookies) {
if (c.startsWith("rangeselect_")) {
showRange(c.slice(12),cookies[c]);
for (let type of ["topartists","toptracks","pulse"]) {
var val = neo.getCookie("rangeselect_" + type);
if (val != undefined) {
showRange(type,val);
}
}
})