2020-11-27 21:12:56 +00:00
|
|
|
|
/*
|
2023-07-03 15:59:25 +00:00
|
|
|
|
* Copyright (C) 2020 Birte Kristina Friesel
|
2020-11-27 21:12:56 +00:00
|
|
|
|
*
|
2021-01-29 17:32:13 +00:00
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-11-27 21:12:56 +00:00
|
|
|
|
*/
|
2019-10-29 20:18:46 +00:00
|
|
|
|
var j_departure = 0;
|
2019-05-10 15:58:13 +00:00
|
|
|
|
var j_duration = 0;
|
|
|
|
|
var j_arrival = 0;
|
2019-10-29 20:18:46 +00:00
|
|
|
|
var j_dest = '';
|
|
|
|
|
var j_stops = [];
|
2023-02-27 21:14:54 +00:00
|
|
|
|
var j_token = '';
|
2024-03-23 14:23:26 +00:00
|
|
|
|
|
|
|
|
|
function setTheme(theme) {
|
|
|
|
|
localStorage.setItem('theme', theme);
|
|
|
|
|
if (!otherTheme.hasOwnProperty(theme)) {
|
|
|
|
|
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
|
|
|
}
|
|
|
|
|
addStyleSheet(theme, 'theme');
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 15:58:13 +00:00
|
|
|
|
function upd_journey_data() {
|
|
|
|
|
$('.countdown').each(function() {
|
2023-02-27 21:14:54 +00:00
|
|
|
|
const journey_token = $(this).data('token');
|
|
|
|
|
if (journey_token) {
|
|
|
|
|
j_token = journey_token;
|
|
|
|
|
}
|
2019-10-29 20:18:46 +00:00
|
|
|
|
var journey_data = $(this).data('journey');
|
|
|
|
|
if (journey_data) {
|
|
|
|
|
journey_data = journey_data.split(';');
|
|
|
|
|
j_departure = parseInt(journey_data[0]);
|
|
|
|
|
j_arrival = parseInt(journey_data[1]);
|
|
|
|
|
j_duration = j_arrival - j_departure;
|
|
|
|
|
}
|
|
|
|
|
var journey_dest = $(this).data('dest');
|
|
|
|
|
if (journey_dest) {
|
|
|
|
|
j_dest = journey_dest;
|
|
|
|
|
}
|
|
|
|
|
var stops = $(this).data('route');
|
|
|
|
|
if (stops) {
|
|
|
|
|
stops = stops.split('|');
|
|
|
|
|
j_stops = [];
|
|
|
|
|
for (var stop_id in stops) {
|
|
|
|
|
var stopdata = stops[stop_id].split(';');
|
|
|
|
|
for (var i = 1; i < 5; i++) {
|
|
|
|
|
stopdata[i] = parseInt(stopdata[i]);
|
|
|
|
|
}
|
|
|
|
|
j_stops.push(stopdata);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-10 15:58:13 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function upd_countdown() {
|
2023-07-02 08:48:34 +00:00
|
|
|
|
const now = Date.now() / 1000;
|
2019-10-29 20:18:46 +00:00
|
|
|
|
if (j_departure > now) {
|
|
|
|
|
$('.countdown').text('Abfahrt in ' + Math.round((j_departure - now)/60) + ' Minuten');
|
|
|
|
|
} else if (j_arrival > 0) {
|
2019-05-10 15:58:13 +00:00
|
|
|
|
if (j_arrival > now) {
|
2023-07-02 08:48:34 +00:00
|
|
|
|
var diff = Math.round((j_arrival - now)/60);
|
|
|
|
|
if (diff >= 120) {
|
|
|
|
|
$('.countdown').text('Ankunft in ' + Math.floor(diff/60) + ' Stunden und ' + (diff%60) + ' Minuten');
|
|
|
|
|
} else if (diff >= 60) {
|
|
|
|
|
$('.countdown').text('Ankunft in 1 Stunde und ' + (diff%60) + ' Minuten');
|
|
|
|
|
} else {
|
|
|
|
|
$('.countdown').text('Ankunft in ' + diff + ' Minuten');
|
|
|
|
|
}
|
2019-05-10 15:58:13 +00:00
|
|
|
|
} else {
|
|
|
|
|
$('.countdown').text('Ziel erreicht');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-29 20:18:46 +00:00
|
|
|
|
function hhmm(epoch) {
|
|
|
|
|
var date = new Date(epoch * 1000);
|
|
|
|
|
var h = date.getHours();
|
|
|
|
|
var m = date.getMinutes();
|
|
|
|
|
return (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m);
|
|
|
|
|
}
|
|
|
|
|
function odelay(sched, rt) {
|
|
|
|
|
if (sched < rt) {
|
|
|
|
|
return ' (+' + ((rt - sched) / 60) + ')';
|
|
|
|
|
}
|
|
|
|
|
else if (sched == rt) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
return ' (' + ((rt - sched) / 60) + ')';
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 16:08:07 +00:00
|
|
|
|
function tvly_run(link, req, err_callback) {
|
2018-10-05 17:12:49 +00:00
|
|
|
|
var error_icon = '<i class="material-icons">error</i>';
|
2022-07-14 19:05:07 +00:00
|
|
|
|
var progressbar;
|
|
|
|
|
if (link.data('tr')) {
|
|
|
|
|
progressbar = $('<tr><td colspan="' + link.data('tr') + '"><div class="progress"><div class="indeterminate"></div></div></td></tr>');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
progressbar = $('<div class="progress"><div class="indeterminate"></div></div>');
|
|
|
|
|
}
|
2018-10-21 13:57:38 +00:00
|
|
|
|
link.hide();
|
|
|
|
|
link.after(progressbar);
|
|
|
|
|
$.post('/action', req, function(data) {
|
|
|
|
|
if (data.success) {
|
2019-04-23 16:08:07 +00:00
|
|
|
|
$(location).attr('href', data.redirect_to);
|
2018-10-21 13:57:38 +00:00
|
|
|
|
} else {
|
|
|
|
|
M.toast({html: error_icon + ' ' + data.error});
|
|
|
|
|
progressbar.remove();
|
|
|
|
|
if (err_callback) {
|
|
|
|
|
err_callback();
|
|
|
|
|
}
|
|
|
|
|
link.append(' ' + error_icon);
|
|
|
|
|
link.show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-04-23 20:27:13 +00:00
|
|
|
|
function tvly_update() {
|
|
|
|
|
$.get('/ajax/status_card.html', function(data) {
|
|
|
|
|
$('.statuscol').html(data);
|
|
|
|
|
tvly_reg_handlers();
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_journey_data();
|
|
|
|
|
setTimeout(tvly_update, 40000);
|
2019-04-23 20:27:13 +00:00
|
|
|
|
}).fail(function() {
|
2019-04-26 20:27:07 +00:00
|
|
|
|
$('.sync-failed-marker').css('display', 'block');
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_countdown();
|
2019-05-07 16:01:49 +00:00
|
|
|
|
setTimeout(tvly_update, 5000);
|
2019-05-02 08:05:15 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function tvly_update_public() {
|
|
|
|
|
var user_name;
|
2023-06-04 16:48:05 +00:00
|
|
|
|
var profile_status = 0;
|
2019-05-02 08:05:15 +00:00
|
|
|
|
$('.publicstatuscol').each(function() {
|
|
|
|
|
user_name = $(this).data('user');
|
2023-06-04 16:48:05 +00:00
|
|
|
|
profile_status = $(this).data('profile');
|
2019-05-02 08:05:15 +00:00
|
|
|
|
});
|
2023-06-04 16:48:05 +00:00
|
|
|
|
$.get('/ajax/status/' + user_name + '.html', {token: j_token, profile: profile_status}, function(data) {
|
2019-05-02 08:05:15 +00:00
|
|
|
|
$('.publicstatuscol').html(data);
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_journey_data();
|
|
|
|
|
setTimeout(tvly_update_public, 40000);
|
2019-05-02 08:05:15 +00:00
|
|
|
|
}).fail(function() {
|
|
|
|
|
$('.sync-failed-marker').css('display', 'block');
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_countdown();
|
2019-05-07 16:01:49 +00:00
|
|
|
|
setTimeout(tvly_update_public, 5000);
|
2019-04-23 20:27:13 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-16 08:34:05 +00:00
|
|
|
|
function tvly_update_timeline() {
|
|
|
|
|
$.get('/timeline/in-transit', {ajax: 1}, function(data) {
|
|
|
|
|
$('.timeline-in-transit').html(data);
|
|
|
|
|
setTimeout(tvly_update_timeline, 60000);
|
|
|
|
|
}).fail(function() {
|
|
|
|
|
$('.sync-failed-marker').css('display', 'block');
|
|
|
|
|
setTimeout(tvly_update_timeline, 10000);
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-05-10 15:58:13 +00:00
|
|
|
|
function tvly_journey_progress() {
|
|
|
|
|
var now = Date.now() / 1000;
|
|
|
|
|
var progress = 0;
|
|
|
|
|
if (j_duration > 0) {
|
|
|
|
|
progress = 1 - ((j_arrival - now) / j_duration);
|
|
|
|
|
if (progress < 0) {
|
|
|
|
|
progress = 0;
|
|
|
|
|
}
|
|
|
|
|
if (progress > 1) {
|
|
|
|
|
progress = 1;
|
|
|
|
|
}
|
|
|
|
|
$('.progress .determinate').css('width', (progress * 100) + '%');
|
2019-10-29 20:18:46 +00:00
|
|
|
|
|
|
|
|
|
for (stop in j_stops) {
|
|
|
|
|
var stop_name = j_stops[stop][0];
|
|
|
|
|
var sched_arr = j_stops[stop][1];
|
|
|
|
|
var rt_arr = j_stops[stop][2];
|
|
|
|
|
var sched_dep = j_stops[stop][3];
|
|
|
|
|
var rt_dep = j_stops[stop][4];
|
|
|
|
|
if (stop_name == j_dest) {
|
|
|
|
|
$('.next-stop').html('');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ((rt_arr != 0) && (rt_arr - now > 0)) {
|
|
|
|
|
$('.next-stop').html(stop_name + '<br/>' + hhmm(rt_arr) + odelay(sched_arr, rt_arr));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ((rt_dep != 0) && (rt_dep - now > 0)) {
|
2023-10-05 04:06:08 +00:00
|
|
|
|
if (rt_arr != 0) {
|
|
|
|
|
$('.next-stop').html(stop_name + '<br/>' + hhmm(rt_arr) + ' → ' + hhmm(rt_dep) + odelay(sched_dep, rt_dep));
|
|
|
|
|
} else {
|
|
|
|
|
$('.next-stop').html(stop_name + '<br/>' + hhmm(rt_dep) + odelay(sched_dep, rt_dep));
|
|
|
|
|
}
|
2019-10-29 20:18:46 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-10 15:58:13 +00:00
|
|
|
|
setTimeout(tvly_journey_progress, 5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-23 20:27:13 +00:00
|
|
|
|
function tvly_reg_handlers() {
|
2018-10-05 14:33:59 +00:00
|
|
|
|
$('.action-checkin').click(function() {
|
|
|
|
|
var link = $(this);
|
2018-10-21 13:57:38 +00:00
|
|
|
|
var req = {
|
2018-10-05 14:33:59 +00:00
|
|
|
|
action: 'checkin',
|
2024-07-26 16:55:58 +00:00
|
|
|
|
hafas: link.data('hafas'),
|
2018-10-05 14:33:59 +00:00
|
|
|
|
station: link.data('station'),
|
|
|
|
|
train: link.data('train'),
|
2019-05-19 08:32:57 +00:00
|
|
|
|
dest: link.data('dest'),
|
2023-10-20 16:04:32 +00:00
|
|
|
|
ts: link.data('ts'),
|
2018-10-05 14:33:59 +00:00
|
|
|
|
};
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req);
|
2018-10-05 14:33:59 +00:00
|
|
|
|
});
|
|
|
|
|
$('.action-checkout').click(function() {
|
|
|
|
|
var link = $(this);
|
2018-10-21 13:57:38 +00:00
|
|
|
|
var req = {
|
2018-10-05 14:33:59 +00:00
|
|
|
|
action: 'checkout',
|
2024-07-26 16:55:58 +00:00
|
|
|
|
hafas: link.data('hafas'),
|
2018-10-05 14:33:59 +00:00
|
|
|
|
station: link.data('station'),
|
|
|
|
|
force: link.data('force'),
|
|
|
|
|
};
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req, function() {
|
2022-08-18 16:22:13 +00:00
|
|
|
|
if (!link.data('force')) {
|
|
|
|
|
link.append(' – Ohne Echtzeitdaten auschecken?')
|
|
|
|
|
link.data('force', true);
|
|
|
|
|
}
|
2018-10-05 14:33:59 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2018-11-02 20:35:53 +00:00
|
|
|
|
$('.action-undo').click(function() {
|
|
|
|
|
var link = $(this);
|
2019-12-08 20:04:34 +00:00
|
|
|
|
var now = Date.now() / 1000;
|
|
|
|
|
var checkints = parseInt(link.data('checkints'));
|
2018-11-02 20:35:53 +00:00
|
|
|
|
var req = {
|
|
|
|
|
action: 'undo',
|
2019-03-31 06:45:51 +00:00
|
|
|
|
undo_id: link.data('id'),
|
2018-11-02 20:35:53 +00:00
|
|
|
|
};
|
2019-12-08 20:04:34 +00:00
|
|
|
|
var do_checkout = true;
|
|
|
|
|
if (now - checkints > 900) {
|
|
|
|
|
do_checkout = confirm("Checkin wirklich rückgängig machen? Er kann ggf. nicht wiederholt werden.");
|
|
|
|
|
}
|
|
|
|
|
if (do_checkout) {
|
|
|
|
|
tvly_run(link, req);
|
|
|
|
|
}
|
2019-03-19 17:20:05 +00:00
|
|
|
|
});
|
|
|
|
|
$('.action-cancelled-from').click(function() {
|
|
|
|
|
var link = $(this);
|
|
|
|
|
var req = {
|
|
|
|
|
action: 'cancelled_from',
|
2024-07-26 16:55:58 +00:00
|
|
|
|
hafas: link.data('hafas'),
|
2019-03-19 17:20:05 +00:00
|
|
|
|
station: link.data('station'),
|
2023-10-20 16:04:32 +00:00
|
|
|
|
ts: link.data('ts'),
|
2019-03-19 17:20:05 +00:00
|
|
|
|
train: link.data('train'),
|
|
|
|
|
};
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req);
|
2019-03-19 17:20:05 +00:00
|
|
|
|
});
|
|
|
|
|
$('.action-cancelled-to').click(function() {
|
|
|
|
|
var link = $(this);
|
|
|
|
|
var req = {
|
|
|
|
|
action: 'cancelled_to',
|
2024-07-26 16:55:58 +00:00
|
|
|
|
hafas: link.data('hafas'),
|
2019-03-19 17:20:05 +00:00
|
|
|
|
station: link.data('station'),
|
|
|
|
|
force: true,
|
|
|
|
|
};
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req);
|
2018-11-02 20:35:53 +00:00
|
|
|
|
});
|
2019-04-04 16:26:53 +00:00
|
|
|
|
$('.action-delete').click(function() {
|
|
|
|
|
var link = $(this);
|
|
|
|
|
var req = {
|
|
|
|
|
action: 'delete',
|
2019-04-23 16:08:07 +00:00
|
|
|
|
id: link.data('id'),
|
2019-04-04 16:26:53 +00:00
|
|
|
|
checkin: link.data('checkin'),
|
|
|
|
|
checkout: link.data('checkout'),
|
|
|
|
|
};
|
2024-04-23 15:12:48 +00:00
|
|
|
|
var really_delete = confirm("Diese Fahrt wirklich löschen? Der Eintrag wird sofort aus der Datenbank entfernt und kann nicht wiederhergestellt werden.");
|
2019-04-04 16:26:53 +00:00
|
|
|
|
if (really_delete) {
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req);
|
2019-04-04 16:26:53 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2019-05-12 09:44:28 +00:00
|
|
|
|
$('.action-share').click(function() {
|
2019-11-14 16:47:06 +00:00
|
|
|
|
var text = $(this).data('text');
|
2019-11-14 17:23:21 +00:00
|
|
|
|
var url = $(this).data('url');
|
2019-05-12 09:44:28 +00:00
|
|
|
|
if (navigator.share) {
|
|
|
|
|
shareObj = {
|
2019-11-14 16:47:06 +00:00
|
|
|
|
text: text
|
2019-05-12 09:44:28 +00:00
|
|
|
|
};
|
2019-11-14 17:23:21 +00:00
|
|
|
|
if (url) {
|
|
|
|
|
shareObj['url'] = url;
|
2019-05-12 09:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
navigator.share(shareObj);
|
2019-11-14 16:47:06 +00:00
|
|
|
|
} else {
|
|
|
|
|
var el = document.createElement('textarea');
|
2019-11-14 17:23:21 +00:00
|
|
|
|
if (url) {
|
|
|
|
|
text += ' ' + url;
|
|
|
|
|
}
|
2019-11-14 16:47:06 +00:00
|
|
|
|
el.value = text;
|
|
|
|
|
el.setAttribute('readonly', '');
|
|
|
|
|
el.style.position = 'absolute';
|
|
|
|
|
el.style.left = '-9999px';
|
|
|
|
|
document.body.appendChild(el);
|
|
|
|
|
el.select();
|
|
|
|
|
el.setSelectionRange(0, 99999);
|
|
|
|
|
document.execCommand('copy');
|
|
|
|
|
document.body.removeChild(el);
|
|
|
|
|
M.toast({html: 'Text kopiert: „' + text + '“'});
|
2019-05-12 09:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2019-04-23 20:27:13 +00:00
|
|
|
|
}
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
tvly_reg_handlers();
|
|
|
|
|
if ($('.statuscol .autorefresh').length) {
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_journey_data();
|
|
|
|
|
setTimeout(tvly_update, 40000);
|
|
|
|
|
setTimeout(tvly_journey_progress, 5000);
|
2019-05-02 08:05:15 +00:00
|
|
|
|
}
|
|
|
|
|
if ($('.publicstatuscol .autorefresh').length) {
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_journey_data();
|
|
|
|
|
setTimeout(tvly_update_public, 40000);
|
|
|
|
|
setTimeout(tvly_journey_progress, 5000);
|
2019-04-23 20:27:13 +00:00
|
|
|
|
}
|
2023-07-16 08:34:05 +00:00
|
|
|
|
if ($('.timeline-in-transit .autorefresh').length) {
|
|
|
|
|
setTimeout(tvly_update_timeline, 60000);
|
|
|
|
|
}
|
2019-05-07 15:56:40 +00:00
|
|
|
|
$('a[href]').click(function() {
|
2019-05-06 16:07:53 +00:00
|
|
|
|
$('nav .preloader-wrapper').addClass('active');
|
|
|
|
|
});
|
2023-10-22 17:05:28 +00:00
|
|
|
|
$('a[href="#now"]').keydown(function(event) {
|
|
|
|
|
// also trigger click handler on keyboard enter
|
|
|
|
|
if (event.keyCode == 13) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.target.click();
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-10-22 12:40:17 +00:00
|
|
|
|
$('a[href="#now"]').click(function(event) {
|
|
|
|
|
event.preventDefault();
|
2023-10-22 17:05:28 +00:00
|
|
|
|
$('nav .preloader-wrapper').removeClass('active');
|
|
|
|
|
now_el = $('#now')[0];
|
|
|
|
|
now_el.previousElementSibling.querySelector(".dep-time").focus();
|
|
|
|
|
now_el.scrollIntoView({behavior: "smooth", block: "center"});
|
2023-10-22 12:40:17 +00:00
|
|
|
|
});
|
2022-12-27 10:07:16 +00:00
|
|
|
|
const elems = document.querySelectorAll('.carousel');
|
|
|
|
|
const instances = M.Carousel.init(elems, {
|
|
|
|
|
fullWidth: true,
|
|
|
|
|
indicators: true}
|
|
|
|
|
);
|
2018-10-05 14:33:59 +00:00
|
|
|
|
});
|