Skip to content

Instantly share code, notes, and snippets.

@Mikescher
Last active August 29, 2015 14:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mikescher/f3d51a40dd0c5228df86 to your computer and use it in GitHub Desktop.
Save Mikescher/f3d51a40dd0c5228df86 to your computer and use it in GitHub Desktop.
[Greasemonkey] Rapla - script ((TINF12B5))
// ==UserScript==
// @name Rapla Highlighter
// @namespace https://rapla.dhbw-karlsruhe.de
// @include https://rapla.dhbw-karlsruhe.de/*
// @version 1
// @require http://code.jquery.com/jquery-latest.js
// @grant none
// @author Mikescher
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
if (!('contains' in String.prototype))
{
String.prototype.contains = function(str, startIndex)
{
return -1 !== String.prototype.indexOf.call(this, str, startIndex);
};
}
function padLeft(nr, n, str)
{
return Array(n-String(nr).length+1).join(str||'0')+nr;
}
//#############################################################################
// CHANGE ME
//#############################################################################
var excludedBlocks = [
"LPM4C", "LPM4B", "LPM56A", "LPM56B",
"Gamification", "Robotik", "Evolutionäre Algorithmen", "Web-Services",
"Englisch",
"Maschinenelemente für Informatiker",
"Fertigungstechnik für Informatiker",
"Konstruktionslehre für Informatiker",
"Wiederholungsklausur", "Klausurwoche",
"Psychologische Grundlagen", "High Performance Computing",
"Ausgewählte Themen der IT-Security", "Forensik",
"Nachprüfung"
];
var highlightedBlocks = [
"Klausur", "Studienarbeitstag", "Exkursion", "DevFest"
];
var rapcourse = "tinf12b5";
var rapuser = "vollmer";
//#############################################################################
$(".week_block").css(
{
"border-radius": "0px",
"box-shadow": "none",
});
$(".week_header").css(
{
"background-color": "white",
});
$(".week_times").css(
{
"background-color": "white",
});
$("div.datechooser").css(
{
"height": "auto",
"background": "none",
});
$(".button").css(
{
"height": "30px",
"border-radius": "0px",
"background": "transparent",
});
$(".button a, .button input").css(
{
"color": "#FFF",
"background-image": "none",
"background-color": "black"
});
//#############################################################################
$('.week_block').each(function()
{
me = $(this);
me.css(
{
"background-color": "#a3ddff"
});
highlightedBlocks.forEach(function(element, index, array)
{
if (me.text().toLowerCase().contains(element.toLowerCase()))
{
me.css(
{
"background-color": "#F80"
});
}
});
excludedBlocks.forEach(function(element, index, array)
{
if (me.text().toLowerCase().contains(element.toLowerCase()))
{
me.css(
{
"background-color": "#FFF"
});
}
});
});
//#############################################################################
date = new Date();
wday = (new Date()).getDay();
cell = $(".week_table > tbody > tr:first-child > td:nth-child(" + (wday+1) + ")");
isThisWeek = false;
if (cell.text().contains(padLeft(date.getDate(), 2) + "." + padLeft((date.getMonth()+1), 2)))
{
cell.css("background-color", "#FF0");
$('input[name="today"]').css("background-color", "#A00");
isThisWeek = true;
}
//#############################################################################
var matchrex = new RegExp("^(https?://)?(www\.)?rapla\.dhbw-karlsruhe\.de(/rapla)?/?$", "i");
if (window.location.toString().toLowerCase().match(matchrex) )
{
window.location.href = "https://rapla.dhbw-karlsruhe.de/rapla?page=calendar&user=" + rapuser + "&file=" + rapcourse;
}
//#############################################################################
wloc = window.location.toString().toLowerCase();
isToday_1 = wloc.contains("today=heute");
isToday_2 = ! (wloc.contains("day=") || wloc.contains("month=") || wloc.contains("year="));
if ( (isToday_1 || isToday_2) && (wday === 0 || wday === 6) ) // Skip on SA/SO to next week
{
date = new Date();
do
date.setDate(date.getDate()+1);
while (date.getDay() != 1);
window.location.href = "https://rapla.dhbw-karlsruhe.de/rapla?page=calendar&user=" + rapuser + "&file=" + rapcourse + "&day=" + date.getDate() + "&month=" + (date.getMonth() + 1) + "&year=" + date.getFullYear();
}
//#############################################################################
function updateTimeMarker() {
date = new Date();
if (date.getHours() < 8 || date.getHours() > 17)
{
$("#timemarker").css({ "top": "-1000px" });
}
$('.week_times').each(function()
{
me = $(this);
date = new Date();
if (me.text().trim() == (date.getHours() + ":00"))
{
ptop = me.position().top + (date.getMinutes() / 60.0) * me.innerHeight() - 1;
$("#timemarker").css({ "top": ptop + "px" });
me.css({ "background-color": "#FF0" });
}
else
{
me.css({ "background-color": "#FFF" });
}
});
}
if (isThisWeek)
{
$("#calendar").css({"position":"relative"});
$("#calendar").append("<div id=\"timemarker\"></div>");
$("#timemarker").css(
{
"width": "100%",
"position": "absolute",
"top": -1000 + "px",
"height": "3px",
"background-color": "rgba(255, 0, 0, 0.35)",
"left": "0px"
});
setTimeout(updateTimeMarker, 500);
setTimeout(updateTimeMarker, 1500);
setTimeout(updateTimeMarker, 2500);
setInterval(updateTimeMarker, 60000);
}
@Apfelkuchen91
Copy link

Too bad that isn't only highlighted the current day .

@Mikescher
Copy link
Author

@Apfelkuchen: [Fixed] Now it only highlights the current day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment