Artemiy.Nosov / myTimetable

// ==UserScript==
// @name         myTimetable
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        *://*.mytimetable.bath.ac.uk/*
// @grant        none
// @run-at       document-end
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// @license      MIT
// ==/UserScript==

$(document).ready(function () { //When document has loaded

  setTimeout(function () {

    //jQuery('.mytimetable-application-panel').remove()

    var d = new Date();
    var hours = d.getUTCHours() + 1;
    var minutes = d.getUTCMinutes();
    var adjustmentFactor = 0;
    if (minutes > 15) {
      adjustmentFactor = 1;
    }
    var L = jQuery('.wc-today').children().children();
    var nLectures = L.length;
    var lectureArr = [];
    var counter = 0;
    var i = 0;
    var timeArr = [];
    var startTime;
    var nextLecture = [];
    for (i = 0; i < nLectures; i++) {
      var lectureName = jQuery(L[i]).text();
      if (lectureName != "") {
        startTime = parseInt(lectureName.slice(0, 2)); //HOURS:15
        lectureName = lectureName.slice(13, 20);
        if (startTime > (hours + adjustmentFactor - 1) && nextLecture == "") {
          nextLecture[0] = startTime;
          nextLecture[1] = lectureName;
          nextLecture[2] = jQuery(L[i]).children().children().childrens('.wc-locations').text();
        }
        lectureArr[counter] = lectureName;
        timeArr[counter] = startTime;
        counter = counter + 1;
      }
    }
    var hoursUntilNextLec = nextLecture[0] - hours - adjustmentFactor;
    var minutesUntilNextLec = 15 - minutes;
    if (minutesUntilNextLec < 0) {
      minutesUntilNextLec = minutesUntilNextLec + 60;
    }

    var stringMessage = "";
    if (nextLecture[0] != "") {
      if (hoursUntilNextLec == 0) {
        stringMessage = nextLecture[1].concat(" in ", minutesUntilNextLec, "min ", "at ", nextLecture[2]);
      }
      if (hoursUntilNextLec > 0) {
        stringMessage = nextLecture[1].concat(" in ", hoursUntilNextLec, "hr ", minutesUntilNextLec, "min ", "at ", nextLecture[2]);
      }
    }

    var pixelPosition = Math.floor(hours * 80 + minutes * 80 / 60);
    var stringThing1 = '<div class="wc-cal-event color-3 removable" style="top: ';
    var stringThing2 = 'px; width: 100%; left: 0%;"><div class="wc-cal-event-border" style=';
    //stringMessage here!
    var stringThing3 = '"height: 4px; min-height: 4px; background-color: gold; border: ">'; //thickness and colour of the line
    if (stringMessage != "") {
      stringThing3 = '"height: 17px; min-height: 17px; background-color: gold; border: ">'; //make the line thinner if empty
    }
    var stringThing4 = '</div></div>';
    var fullString = stringThing1.concat(pixelPosition.toString(), stringThing2, stringThing3, stringMessage, stringThing4);
    jQuery(".wc-today .wc-day-column-inner").append(fullString);

  }, 400); //Two seconds will elapse and Code will execute.

});