Last active
February 9, 2017 13:02
-
-
Save bjelline/2e9629abf814b654eb36966e4fcfd3e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name FHSysUsability | |
// @namespace FHS | |
// @include https://fhsys.fh-salzburg.ac.at/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
function pick_sem_for_today(){ | |
var today = new Date(); | |
var year = today.getFullYear() | |
var month = 1 + today.getMonth(); | |
var chose_sem, chose_year; | |
if ( month < 8 ) { | |
// Jan - Jul: choose this ss | |
chose_year = year; | |
chose_sem = "SS" | |
} else if ( month < 12 ) { | |
// Aug - Nov: chose this ws | |
chose_year = year; | |
chose_sem = "WS" | |
} else { | |
// Dec: chose next SS | |
chose_year = year + 1; | |
chose_sem = "SS" | |
} | |
chose_year = "" + chose_year; // force string | |
return [chose_sem, chose_year]; | |
} | |
function selectItemByValue(s, value){ | |
for(var i=0; i < s.options.length; i++) | |
{ | |
if(s.options[i].value === value) { | |
s.selectedIndex = i; | |
break; | |
} | |
} | |
} | |
console.log("Installing FHSysUsability Script:"); | |
// look for different names ! | |
if($('select[name=wsSS],select[name=semWsSs]').length>0) { | |
// ["WS", "2017"] | |
var sem_and_year = pick_sem_for_today(); | |
console.log("Installing FHSysUsability Script: set to " + sem_and_year); | |
$('select[name=wsSS]').each(function(i){ | |
selectItemByValue(this,sem_and_year[0]); | |
}) | |
$('select[name=semWsSs]').each(function(i){ | |
selectItemByValue(this,sem_and_year[0]); | |
}) | |
$('select[name=jahr]').each(function(i){ | |
selectItemByValue(this,sem_and_year[1]); | |
}) | |
$('select[name=semJahr]').each(function(i){ | |
selectItemByValue(this,sem_and_year[1]); | |
}) | |
console.log("Installing FHSysUsability Script: add up and down buttons"); | |
$('select[name=wsSS]').parent().prepend( "<button class='down_this' data-selector1='wsSS' data-selector2='jahr' >←</button>"); | |
$('select[name=semWsSs]').parent().prepend("<button class='down_this' data-selector1='semWsSs' data-selector2='semJahr' >←</button>"); | |
$('select[name=jahr]').parent().append( "<button class='up_this' data-selector1='wsSS' data-selector2='jahr' >→</button>"); | |
$('select[name=semJahr]').parent().append( "<button class='up_this' data-selector1='semWsSs' data-selector2='semJahr' >→</button>"); | |
} | |
$('.down_this').click(function(event){ | |
event.preventDefault(); | |
console.log("reading and writing to select tags " + $(this).attr('data-selector1') + " and " + $(this).attr('data-selector2') ); | |
var $sem = $(this).parent().parent().find('select[name='+ $(this).attr('data-selector1') +']'); | |
var $jahr = $(this).parent().parent().find('select[name='+ $(this).attr('data-selector2') +']'); | |
var sem = $sem.val(); | |
var jahr = $jahr.val(); | |
new_sem = sem == 'SS' ? 'WS' : 'SS'; | |
new_jahr = sem == 'SS' ? "" + (parseInt(jahr)-1) : jahr; | |
console.log("down from " + sem + "/" + jahr + " to " + new_sem + "/" + new_jahr); | |
$sem.val(new_sem); | |
$jahr.val(new_jahr); | |
}); | |
$('.up_this').click(function(event){ | |
event.preventDefault(); | |
console.log("reading and writing to select tags " + $(this).attr('data-selector1') + " and " + $(this).attr('data-selector2') ); | |
var $sem = $(this).parent().parent().find('select[name='+ $(this).attr('data-selector1') +']'); | |
var $jahr = $(this).parent().parent().find('select[name='+ $(this).attr('data-selector2') +']'); | |
var sem = $sem.val(); | |
var jahr = $jahr.val(); | |
new_sem = sem == 'SS' ? 'WS' : 'SS'; | |
new_jahr = sem == 'WS' ? "" + (parseInt(jahr)+1) : jahr; | |
console.log("up from " + sem + "/" + jahr + " to " + new_sem + "/" + new_jahr); | |
$sem.val(new_sem); | |
$jahr.val(new_jahr); | |
}); | |
console.log("Installing FHSysUsability Script: hover table row"); | |
$('.formborder tr').hover(function(event){ | |
$(this).css({"background-color": "pink"}); | |
},function(event){ | |
$(this).css({"background-color": null}); | |
}); | |
console.log("Installing FHSysUsability Script succeeded."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment