mirror of
https://github.com/krateng/maloja.git
synced 2025-04-19 10:07:37 +03:00
Range selections are now saved in cookies
This commit is contained in:
parent
649075286c
commit
e6aa0a25c8
@ -4,7 +4,8 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Maloja - KEY_ARTISTNAME</title>
|
||||
<script src="javascript/rangeselect.js" async></script>
|
||||
<script src="javascript/cookies.js"></script>
|
||||
<script src="javascript/rangeselect.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -35,10 +36,10 @@
|
||||
<h2><a href='/pulse?artist=KEY_ENC_ARTISTNAME&step=year&trail=1'>Pulse</a></h2>
|
||||
|
||||
|
||||
<span onclick="showRange('pulse','days')" class="stat_selector_pulse selector_pulse_days">7 days</span>
|
||||
| <span onclick="showRange('pulse','weeks')" class="stat_selector_pulse selector_pulse_weeks">12 weeks</span>
|
||||
| <span onclick="showRange('pulse','months')" class="stat_selector_pulse selector_pulse_months" style="opacity:0.5;">12 months</span>
|
||||
| <span onclick="showRange('pulse','years')" class="stat_selector_pulse selector_pulse_years">10 years</span>
|
||||
<span onclick="showRangeManual('pulse','days')" class="stat_selector_pulse selector_pulse_days">7 days</span>
|
||||
| <span onclick="showRangeManual('pulse','weeks')" class="stat_selector_pulse selector_pulse_weeks">12 weeks</span>
|
||||
| <span onclick="showRangeManual('pulse','months')" class="stat_selector_pulse selector_pulse_months" style="opacity:0.5;">12 months</span>
|
||||
| <span onclick="showRangeManual('pulse','years')" class="stat_selector_pulse selector_pulse_years">10 years</span>
|
||||
|
||||
<br/><br/>
|
||||
|
||||
@ -50,10 +51,10 @@
|
||||
<td>
|
||||
<!-- We use the same classes / function calls here because we want it to switch together with pulse -->
|
||||
<h2><a href='/performance?artist=KEY_ENC_CREDITEDARTISTNAME&step=year&trail=1'>Performance</a></h2>
|
||||
<span onclick="showRange('pulse','days')" class="stat_selector_pulse selector_pulse_days">7 days</span>
|
||||
| <span onclick="showRange('pulse','weeks')" class="stat_selector_pulse selector_pulse_weeks">12 weeks</span>
|
||||
| <span onclick="showRange('pulse','months')" class="stat_selector_pulse selector_pulse_months" style="opacity:0.5;">12 months</span>
|
||||
| <span onclick="showRange('pulse','years')" class="stat_selector_pulse selector_pulse_years">10 years</span>
|
||||
<span onclick="showRangeManual('pulse','days')" class="stat_selector_pulse selector_pulse_days">7 days</span>
|
||||
| <span onclick="showRangeManual('pulse','weeks')" class="stat_selector_pulse selector_pulse_weeks">12 weeks</span>
|
||||
| <span onclick="showRangeManual('pulse','months')" class="stat_selector_pulse selector_pulse_months" style="opacity:0.5;">12 months</span>
|
||||
| <span onclick="showRangeManual('pulse','years')" class="stat_selector_pulse selector_pulse_years">10 years</span>
|
||||
|
||||
<br/><br/>
|
||||
|
||||
|
@ -1,27 +1,57 @@
|
||||
apikeycorrect = false;
|
||||
|
||||
function insertAPIKeyFromCookie() {
|
||||
cookies = decodeURIComponent(document.cookie).split(';');
|
||||
for(var i = 0; i <cookies.length; i++) {
|
||||
cookies[i] = cookies[i].trim()
|
||||
if (cookies[i].startsWith("apikey=")) {
|
||||
document.getElementById("apikey").value = cookies[i].replace("apikey=","")
|
||||
checkAPIkey()
|
||||
}
|
||||
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) {
|
||||
cookies[key] = val;
|
||||
document.cookie = encodeURIComponent(key) + "=" + encodeURIComponent(val);
|
||||
}
|
||||
function saveCookies() {
|
||||
for (var c in cookies) {
|
||||
document.cookie = encodeURIComponent(c) + "=" + encodeURIComponent(cookies[c]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// RANGE SELECTORS
|
||||
|
||||
// in rangeselect.js
|
||||
|
||||
|
||||
/// API KEY
|
||||
|
||||
|
||||
|
||||
function insertAPIKeyFromCookie() {
|
||||
getCookies();
|
||||
key = cookies["apikey"];
|
||||
document.getElementById("apikey").value = key;
|
||||
checkAPIkey()
|
||||
}
|
||||
|
||||
function saveAPIkey() {
|
||||
key = document.getElementById("apikey").value
|
||||
document.cookie = "apikey=" + encodeURIComponent(key)
|
||||
key = APIkey()
|
||||
setCookie("apikey",key)
|
||||
}
|
||||
|
||||
|
||||
|
||||
function checkAPIkey() {
|
||||
saveAPIkey()
|
||||
url = "/api/test?key=" + document.getElementById("apikey").value
|
||||
|
||||
url = "/api/test?key=" + APIkey()
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && (this.status == 204 || this.status == 205)) {
|
||||
@ -41,6 +71,9 @@ function checkAPIkey() {
|
||||
document.getElementById("apikey").style.backgroundColor = "red"
|
||||
apikeycorrect = false
|
||||
}
|
||||
if (apikeycorrect) {
|
||||
saveAPIkey();
|
||||
}
|
||||
}
|
||||
|
||||
function APIkey() {
|
||||
|
@ -25,4 +25,21 @@ function showRange(identifier,unit) {
|
||||
for (var i=0;i<reactivate.length;i++) {
|
||||
reactivate[i].setAttribute("style","opacity:0.5;")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function showRangeManual(identifier,unit) {
|
||||
showRange(identifier,unit);
|
||||
setCookie("rangeselect_" + identifier,unit);
|
||||
}
|
||||
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded',function() {
|
||||
getCookies();
|
||||
for (c in cookies) {
|
||||
if (c.startsWith("rangeselect_")) {
|
||||
showRange(c.slice(12),cookies[c]);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 55 KiB |
BIN
website/media/record_gold_original.png
Normal file
BIN
website/media/record_gold_original.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 58 KiB |
@ -4,10 +4,12 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Maloja</title>
|
||||
<script src="javascript/rangeselect.js"></script>
|
||||
|
||||
<script>document.addEventListener('DOMContentLoaded',function() {
|
||||
KEY_JS_INIT_RANGES
|
||||
})</script>
|
||||
<script src="javascript/cookies.js"></script>
|
||||
<script src="javascript/rangeselect.js"></script>
|
||||
</head>
|
||||
|
||||
|
||||
@ -23,10 +25,10 @@
|
||||
|
||||
|
||||
|
||||
<span onclick="showRange('topartists','week')" class="stat_selector_topartists selector_topartists_week">This Week</span>
|
||||
| <span onclick="showRange('topartists','month')" class="stat_selector_topartists selector_topartists_month">This Month</span>
|
||||
| <span onclick="showRange('topartists','year')" class="stat_selector_topartists selector_topartists_year">This Year</span>
|
||||
| <span onclick="showRange('topartists','alltime')" class="stat_selector_topartists selector_topartists_alltime" style="opacity:0.5;">All Time</span>
|
||||
<span onclick="showRangeManual('topartists','week')" class="stat_selector_topartists selector_topartists_week">This Week</span>
|
||||
| <span onclick="showRangeManual('topartists','month')" class="stat_selector_topartists selector_topartists_month">This Month</span>
|
||||
| <span onclick="showRangeManual('topartists','year')" class="stat_selector_topartists selector_topartists_year">This Year</span>
|
||||
| <span onclick="showRangeManual('topartists','alltime')" class="stat_selector_topartists selector_topartists_alltime" style="opacity:0.5;">All Time</span>
|
||||
|
||||
<br/><br/>
|
||||
|
||||
@ -42,9 +44,9 @@
|
||||
|
||||
|
||||
<span onclick="showRange('toptracks','week')" class="stat_selector_toptracks selector_toptracks_week">This Week</span>
|
||||
| <span onclick="showRange('toptracks','month')" class="stat_selector_toptracks selector_toptracks_month">This Month</span>
|
||||
| <span onclick="showRange('toptracks','year')" class="stat_selector_toptracks selector_toptracks_year">This Year</span>
|
||||
| <span onclick="showRange('toptracks','alltime')" class="stat_selector_toptracks selector_toptracks_alltime" style="opacity:0.5;">All Time</span>
|
||||
| <span onclick="showRangeManual('toptracks','month')" class="stat_selector_toptracks selector_toptracks_month">This Month</span>
|
||||
| <span onclick="showRangeManual('toptracks','year')" class="stat_selector_toptracks selector_toptracks_year">This Year</span>
|
||||
| <span onclick="showRangeManual('toptracks','alltime')" class="stat_selector_toptracks selector_toptracks_alltime" style="opacity:0.5;">All Time</span>
|
||||
|
||||
<br/><br/>
|
||||
|
||||
@ -81,10 +83,10 @@
|
||||
<a href="/pulse?step=year&trail=1">Years</a>
|
||||
-->
|
||||
|
||||
<span onclick="showRange('pulse','days')" class="stat_selector_pulse selector_pulse_days">7 days</span>
|
||||
| <span onclick="showRange('pulse','weeks')" class="stat_selector_pulse selector_pulse_weeks">12 weeks</span>
|
||||
| <span onclick="showRange('pulse','months')" class="stat_selector_pulse selector_pulse_months" style="opacity:0.5;">12 months</span>
|
||||
| <span onclick="showRange('pulse','years')" class="stat_selector_pulse selector_pulse_years">10 years</span>
|
||||
<span onclick="showRangeManual('pulse','days')" class="stat_selector_pulse selector_pulse_days">7 days</span>
|
||||
| <span onclick="showRangeManual('pulse','weeks')" class="stat_selector_pulse selector_pulse_weeks">12 weeks</span>
|
||||
| <span onclick="showRangeManual('pulse','months')" class="stat_selector_pulse selector_pulse_months" style="opacity:0.5;">12 months</span>
|
||||
| <span onclick="showRangeManual('pulse','years')" class="stat_selector_pulse selector_pulse_years">10 years</span>
|
||||
<!--
|
||||
### this is for extra views of the current canonical week / month / year
|
||||
<br/>
|
||||
|
@ -4,7 +4,8 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Maloja - KEY_TRACKTITLE</title>
|
||||
<script src="javascript/rangeselect.js" async></script>
|
||||
<script src="javascript/cookies.js" ></script>
|
||||
<script src="javascript/rangeselect.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -30,10 +31,10 @@
|
||||
<tr>
|
||||
<td>
|
||||
<h2><a href='/pulse?KEY_SCROBBLELINK&step=year&trail=1'>Pulse</a></h2>
|
||||
<span onclick="showRange('pulse','days')" class="stat_selector_pulse selector_pulse_days">7 days</span>
|
||||
| <span onclick="showRange('pulse','weeks')" class="stat_selector_pulse selector_pulse_weeks">12 weeks</span>
|
||||
| <span onclick="showRange('pulse','months')" class="stat_selector_pulse selector_pulse_months" style="opacity:0.5;">12 months</span>
|
||||
| <span onclick="showRange('pulse','years')" class="stat_selector_pulse selector_pulse_years">10 years</span>
|
||||
<span onclick="showRangeManual('pulse','days')" class="stat_selector_pulse selector_pulse_days">7 days</span>
|
||||
| <span onclick="showRangeManual('pulse','weeks')" class="stat_selector_pulse selector_pulse_weeks">12 weeks</span>
|
||||
| <span onclick="showRangeManual('pulse','months')" class="stat_selector_pulse selector_pulse_months" style="opacity:0.5;">12 months</span>
|
||||
| <span onclick="showRangeManual('pulse','years')" class="stat_selector_pulse selector_pulse_years">10 years</span>
|
||||
|
||||
<br/><br/>
|
||||
|
||||
@ -44,10 +45,10 @@
|
||||
</td>
|
||||
<td>
|
||||
<h2><a href='/performance?KEY_SCROBBLELINK&step=year&trail=1'>Performance</a></h2>
|
||||
<span onclick="showRange('pulse','days')" class="stat_selector_pulse selector_pulse_days">7 days</span>
|
||||
| <span onclick="showRange('pulse','weeks')" class="stat_selector_pulse selector_pulse_weeks">12 weeks</span>
|
||||
| <span onclick="showRange('pulse','months')" class="stat_selector_pulse selector_pulse_months" style="opacity:0.5;">12 months</span>
|
||||
| <span onclick="showRange('pulse','years')" class="stat_selector_pulse selector_pulse_years">10 years</span>
|
||||
<span onclick="showRangeManual('pulse','days')" class="stat_selector_pulse selector_pulse_days">7 days</span>
|
||||
| <span onclick="showRangeManual('pulse','weeks')" class="stat_selector_pulse selector_pulse_weeks">12 weeks</span>
|
||||
| <span onclick="showRangeManual('pulse','months')" class="stat_selector_pulse selector_pulse_months" style="opacity:0.5;">12 months</span>
|
||||
| <span onclick="showRangeManual('pulse','years')" class="stat_selector_pulse selector_pulse_years">10 years</span>
|
||||
|
||||
<br/><br/>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user