Save recents stations
This commit is contained in:
parent
0f397bf23a
commit
95d75405cb
34
app.js
34
app.js
@ -122,12 +122,16 @@ function getSchedule(type, code, station, way) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function defineTag(type, station) {
|
function getStationName(station) {
|
||||||
station = station.replace(/\+/g, " ").replace(/\b[a-z]/g, function(letter) {
|
return station.replace(/\+/g, " ").replace(/\b[a-z]/g, function(letter) {
|
||||||
return letter.toUpperCase();
|
return letter.toUpperCase();
|
||||||
}).replace(/\b(de|du|sur)\b/gi, function(word) {
|
}).replace(/\b(de|du|sur)\b/gi, function(word) {
|
||||||
return word.toLowerCase();
|
return word.toLowerCase();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function defineTag(type, station) {
|
||||||
|
station = getStationName(station);
|
||||||
$("#station").text(station);
|
$("#station").text(station);
|
||||||
$(".navbar-brand").hide();
|
$(".navbar-brand").hide();
|
||||||
$("#station").show();
|
$("#station").show();
|
||||||
@ -142,6 +146,18 @@ function updateTime(time) {
|
|||||||
}
|
}
|
||||||
updateTime(new Date());
|
updateTime(new Date());
|
||||||
|
|
||||||
|
function viewRecents(type) {
|
||||||
|
$("#recents").empty();
|
||||||
|
var recents = JSON.parse(localStorage.recents);
|
||||||
|
$.each( Object.keys(recents).sort(function(a,b){return recents[b]-recents[a]}), function( key, val ) {
|
||||||
|
if (recents[val] > 1) {
|
||||||
|
var s = val.split("/");
|
||||||
|
$("<li class='page-item'/>", {html: $( "<a/>", { href: "/" + val, "class": "page-link", text: s[0][0].toUpperCase() + s[1] + " : " + getStationName(s[2]) } ).bind("click", function(e) { main(val.split("/"), true); history.pushState(null, "title 1", "/" + val); return false; }).appendTo("#recents")});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$("#recents").show();
|
||||||
|
}
|
||||||
|
|
||||||
function main(uri, fetchTrafic) {
|
function main(uri, fetchTrafic) {
|
||||||
$("#lines").hide();
|
$("#lines").hide();
|
||||||
$("#line").attr("disabled", true);
|
$("#line").attr("disabled", true);
|
||||||
@ -150,6 +166,7 @@ function main(uri, fetchTrafic) {
|
|||||||
$("#schedule").hide();
|
$("#schedule").hide();
|
||||||
$("#loading").hide();
|
$("#loading").hide();
|
||||||
$("#mainerror").hide();
|
$("#mainerror").hide();
|
||||||
|
$("#recents").hide();
|
||||||
|
|
||||||
if (nextTraffic != null) {
|
if (nextTraffic != null) {
|
||||||
clearTimeout(nextTraffic);
|
clearTimeout(nextTraffic);
|
||||||
@ -160,6 +177,9 @@ function main(uri, fetchTrafic) {
|
|||||||
nextSchedule = null;
|
nextSchedule = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (localStorage.getItem("recents") === null)
|
||||||
|
localStorage.setItem("recents", JSON.stringify({}));
|
||||||
|
|
||||||
if (uri.length == 4 || uri.length == 3) {
|
if (uri.length == 4 || uri.length == 3) {
|
||||||
if (uri[3] == "")
|
if (uri[3] == "")
|
||||||
uri.pop();
|
uri.pop();
|
||||||
@ -168,8 +188,16 @@ function main(uri, fetchTrafic) {
|
|||||||
|
|
||||||
defineTag(uri[0], uri[2]);
|
defineTag(uri[0], uri[2]);
|
||||||
getSchedule(uri[0], uri[1], uri[2], uri[3]);
|
getSchedule(uri[0], uri[1], uri[2], uri[3]);
|
||||||
|
|
||||||
if (fetchTrafic)
|
if (fetchTrafic)
|
||||||
getTraffic(uri[0], uri[1]);
|
getTraffic(uri[0], uri[1]);
|
||||||
|
|
||||||
|
mpath = uri.slice(0,3);
|
||||||
|
recents = JSON.parse(localStorage.recents);
|
||||||
|
if (recents[mpath.join("/")] === undefined)
|
||||||
|
recents[mpath.join("/")] = 0;
|
||||||
|
recents[mpath.join("/")] += 1;
|
||||||
|
localStorage.recents = JSON.stringify(recents);
|
||||||
} else if (uri.length == 1 || uri.length == 2) {
|
} else if (uri.length == 1 || uri.length == 2) {
|
||||||
$("#traffic").hide();
|
$("#traffic").hide();
|
||||||
$("#station").hide();
|
$("#station").hide();
|
||||||
@ -188,11 +216,13 @@ function main(uri, fetchTrafic) {
|
|||||||
default:
|
default:
|
||||||
window.location.pathname = "/";
|
window.location.pathname = "/";
|
||||||
}
|
}
|
||||||
|
viewRecents(uri[0]);
|
||||||
} else if (uri.length == 0) {
|
} else if (uri.length == 0) {
|
||||||
if ($("#linesFilter").val().length != 0)
|
if ($("#linesFilter").val().length != 0)
|
||||||
main([ $("#linesFilter").val() ], true);
|
main([ $("#linesFilter").val() ], true);
|
||||||
else
|
else
|
||||||
$("#lines").show();
|
$("#lines").show();
|
||||||
|
viewRecents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
main(uri, true);
|
main(uri, true);
|
||||||
|
@ -68,6 +68,8 @@
|
|||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="recents" class="pagination" style="display: none; margin: 1em 0"></div>
|
||||||
|
|
||||||
<small id="update"></small>
|
<small id="update"></small>
|
||||||
|
|
||||||
<script src="https://cdn.nemunai.re/js/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
|
<script src="https://cdn.nemunai.re/js/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user