NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name KyivPasTrans_highlight // @description Shows transport wait time // @version 0.1 // @author victorrar // @license MIT // @include http://kpt.kiev.ua/information/passengers/timetable/* // @exclude http://kpt.kiev.ua/information/passengers/timetable/ // @updateURL https://openuserjs.org/meta/victorrar/KyivPasTrans_highlight.meta.js // @copyright 2017, victorrar // ==/UserScript== (function() { 'use strict'; var now = new Date(); function toDate(elem){ var temp = new Date(now); temp.setHours(elem.innerText.split(":")[0], elem.innerText.split(":")[1], 0); return temp; } function compareTime(tBase, tComp){ if(tComp == "Invalid Date"){ return true; } return tBase.getTime() > tComp.getTime(); } // Your code here... var tables = document.querySelectorAll(".transportTimetable"); var tablesLength = tables.length; for(var m = 0; m < tablesLength; m++){ var rows = tables[m].querySelectorAll(".t-row:not(.timetableHeader)"); var rowsLength = rows.length; var cellsLength = rows[0].querySelectorAll(".tt-e, .tt-f:not(.shift)").length; //num of columns var arr =[]; for(var i=0; i<rowsLength; i++){ var cells = rows[i].querySelectorAll(".tt-e, .tt-f:not(.shift)"); arr[i] = Array.prototype.slice.call( cells, 0 ); } //console.log(arr); var row = document.createElement("div"); row.classList.add("t-row"); var spacer = document.createElement("span"); spacer.classList.add("tt-e"); spacer.innerHTML = " "; row.appendChild(spacer); for(i = 0; i < cellsLength; i++){ var k = 0; while(k < rowsLength ? compareTime(now, toDate(arr[k][i])) : false){ k++; } var cell = document.createElement("span"); var text; cell.classList.add("tt-f"); if(k < rowsLength){ arr[k][i].style.color = "#5fa021"; var dateLeft = Math.ceil((toDate(arr[k][i]) - now) / 60000); text = document.createTextNode(dateLeft + " m"); } else { text = document.createTextNode("-"); } cell.appendChild(text); row.appendChild(cell); } tables[m].insertBefore(row, tables[m].children[1]); } })();