psilocybe / Free time calculator (plan.polsl.pl)

// ==UserScript==
// @name         Free time calculator (plan.polsl.pl)
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Calculate your free time from plan.polsl.pl timetable.
// @author       Psilo
// @match        *plan.polsl.pl/*
// @grant        none
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js

// ==/UserScript==
/* jshint -W097 */

'use strict';
(function() {
    //
    // Constants & variables
    var currentFreeTime = 0; //minutes
    var interval = 15; //minutes 

    //
    // Functions
    var setEvents = function () {
      var isSelecting = false;
      jq(".coursediv").css("pointer-events", "none");
      jq(document).on("mousedown", function () {
          isSelecting = true;
      }).on("mouseup", function () {
          isSelecting = false;
      }).on("mousemove", function (e) {
          e.preventDefault();
      });
      jq(".cdS")
      .on("mousedown mouseover", function (e) {
          if(e.type==="mousedown") {
              isSelecting = true;
          }
          if(isSelecting) {    
              jq(this).css("background-color", "red").css("z-index", "100").css("overflow", "");
              currentFreeTime += interval;
              var minutes = (currentFreeTime % 60);
              var hours = ((currentFreeTime - minutes) / 60);
              
              jq("#freeTimeMin").val(minutes);
              jq("#freeTimeHour").val(hours);
          }
      })
      .on("mouseleave", function (e) {
          if(isSelecting) {
              //jq(this).css("background-color", "red");
          }
      });
    };
  
    var generateUI = function () {
        var toWrap = jq('#weekBrowser');
        toWrap.css("position", "relative");
        toWrap.css("display", "inline");
        toWrap.css("float", "left");
        toWrap.css("top", "");
        toWrap.css("left", "");
        var newOuterNode = jq("<div style='position: absolute; top: 67px; left: 5px' />");
        newOuterNode.insertAfter(toWrap);
        toWrap.appendTo(newOuterNode);
        var newNode = jq(
            "<div class='wBBox' id='freeTimeCalc' style='float: left; width:250px; margin-left: 5px; height: 118px; display: inline;'>" +
            "<div class='titleBar'>Wolny czas</div>" +
            "<div class='wBParent' >" + 
            "<div style='text-align: center'>" +
            "<input type='text' id='freeTimeHour' style='width: 50px; margin-top: 5px; text-align: left' readonly value='0'/> h " +
            "<input type='text' id='freeTimeMin' style='width: 50px; margin-top: 5px; text-align: left' readonly value='0'/> min" +
            "</div>" + 
            "</div>" +
            "</div>"
        );
        newNode.appendTo(newOuterNode);
    };

    //
    // Entry Point
    var jq = jQuery.noConflict(true);

    setEvents();
    generateUI();
})();