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) {
|
||||
station = station.replace(/\+/g, " ").replace(/\b[a-z]/g, function(letter) {
|
||||
function getStationName(station) {
|
||||
return station.replace(/\+/g, " ").replace(/\b[a-z]/g, function(letter) {
|
||||
return letter.toUpperCase();
|
||||
}).replace(/\b(de|du|sur)\b/gi, function(word) {
|
||||
return word.toLowerCase();
|
||||
});
|
||||
}
|
||||
|
||||
function defineTag(type, station) {
|
||||
station = getStationName(station);
|
||||
$("#station").text(station);
|
||||
$(".navbar-brand").hide();
|
||||
$("#station").show();
|
||||
@ -142,6 +146,18 @@ function updateTime(time) {
|
||||
}
|
||||
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) {
|
||||
$("#lines").hide();
|
||||
$("#line").attr("disabled", true);
|
||||
@ -150,6 +166,7 @@ function main(uri, fetchTrafic) {
|
||||
$("#schedule").hide();
|
||||
$("#loading").hide();
|
||||
$("#mainerror").hide();
|
||||
$("#recents").hide();
|
||||
|
||||
if (nextTraffic != null) {
|
||||
clearTimeout(nextTraffic);
|
||||
@ -160,6 +177,9 @@ function main(uri, fetchTrafic) {
|
||||
nextSchedule = null;
|
||||
}
|
||||
|
||||
if (localStorage.getItem("recents") === null)
|
||||
localStorage.setItem("recents", JSON.stringify({}));
|
||||
|
||||
if (uri.length == 4 || uri.length == 3) {
|
||||
if (uri[3] == "")
|
||||
uri.pop();
|
||||
@ -168,8 +188,16 @@ function main(uri, fetchTrafic) {
|
||||
|
||||
defineTag(uri[0], uri[2]);
|
||||
getSchedule(uri[0], uri[1], uri[2], uri[3]);
|
||||
|
||||
if (fetchTrafic)
|
||||
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) {
|
||||
$("#traffic").hide();
|
||||
$("#station").hide();
|
||||
@ -188,11 +216,13 @@ function main(uri, fetchTrafic) {
|
||||
default:
|
||||
window.location.pathname = "/";
|
||||
}
|
||||
viewRecents(uri[0]);
|
||||
} else if (uri.length == 0) {
|
||||
if ($("#linesFilter").val().length != 0)
|
||||
main([ $("#linesFilter").val() ], true);
|
||||
else
|
||||
$("#lines").show();
|
||||
viewRecents();
|
||||
}
|
||||
}
|
||||
main(uri, true);
|
||||
|
@ -68,6 +68,8 @@
|
||||
<p></p>
|
||||
</div>
|
||||
|
||||
<div id="recents" class="pagination" style="display: none; margin: 1em 0"></div>
|
||||
|
||||
<small id="update"></small>
|
||||
|
||||
<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