Skip to content

Instantly share code, notes, and snippets.

@alex7kom
Last active June 12, 2016 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex7kom/2292c6436bd39ae81bf7e99286a3876b to your computer and use it in GitHub Desktop.
Save alex7kom/2292c6436bd39ae81bf7e99286a3876b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Yandex Trains Helper
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Highlights the current station and fades out past stations
// @author Alex7Kom
// @match https://rasp.yandex.ru/thread/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
// @grant none
// ==/UserScript==
(function() {
function getTimeFromAttr (attr) {
var timeData = eval('(function(){' + attr + '})()');
var time = new Date(+new Date(timeData['i-time'].local) + 1000 * 60 * timeData['i-time'].shifts[213]);
return time;
}
function check () {
$('.b-timetable__row').each(function (i, item) {
var depTimeCell = $(item).find('.b-timetable__cell_type_departure .b-timetable__time .b-timetable__time');
if (depTimeCell.length < 1) {
return;
}
var depTime = getTimeFromAttr($(depTimeCell[0]).attr('onclick'));
if (+depTime < +new Date()) {
$(item).css('opacity','0.5').css('background-color','#fff');
} else {
var arrTimeCell = $(item).find('.b-timetable__cell_type_arrival .b-timetable__time .b-timetable__time');
if (arrTimeCell.length < 1) {
return;
}
var arrTime = getTimeFromAttr($(arrTimeCell[0]).attr('onclick'));
if (+arrTime < +new Date()) {
$(item).css('background-color','#fbec5d');
}
}
});
}
check();
setInterval(check, 1000 * 10);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment