NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Bankmanagergame - Beratung
// @namespace http://gelink.de/
// @description Erweitert die Berater und Beratungs Auswahlmöglichkeiten.
// @author Georg J.P. Link
// @include http://bankmanagergame.de/index.php?section=beratung*
// @include http://www.bankmanagergame.de/index.php?section=beratung*
// ==/UserScript==
var $;
var wartendeberater;
// beratungsdauern = new Array;
// Add jQuery
(function(){
if (typeof unsafeWindow.jQuery == 'undefined') {
var GM_Head = document.getElementsByTagName('head')[0] || document.documentElement,
GM_JQ = document.createElement('script');
GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
GM_JQ.type = 'text/javascript';
GM_JQ.async = true;
GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);
}
GM_wait();
})();
// Check if jQuery's loaded
function GM_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(GM_wait, 100);
} else {
$1 = unsafeWindow.jQuery;
beratung();
}
}
/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
* The level - OPTIONAL
* Returns : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
* Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
*/
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;
//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += " ";
if(typeof(arr) == 'object') { //Array/Hashes/Objects
for(var item in arr) {
var value = arr[item];
if(typeof(value) == 'object') { //If it is an array,
dumped_text += level_padding + "'" + item + "' ...\n";
dumped_text += dump(value,level+1);
} else {
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
}
}
} else { //Stings/Chars/Numbers etc.
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}
// formatiert die Ertragsaussicht mit Tausender Trennzeichen
function Trenner(number) {
// Info: Die '' sind zwei Hochkommas
number = '' + number;
teile = number.split(".");
ganze = teile[0];
if (teile[1]){
komma = teile[1];
} else {
komma = "00";
}
while(komma.length <2) {
komma += "0";
}
komma = komma.substr(0,2);
if (ganze.length > 3) {
var mod = ganze.length % 3;
var output = (mod > 0 ? (ganze.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(ganze.length / 3); i++) {
if ((mod == 0) && (i == 0))
output += ganze.substring(mod+ 3 * i, mod + 3 * i + 3);
else
// hier wird das Trennzeichen festgelegt mit '.'
output+= '.' + ganze.substring(mod + 3 * i, mod + 3 * i + 3);
}
// return (output+','+komma);
return output;
}
// else return teile[0]+','+komma;
else return teile[0];
}
//
function beratung() {
wartendeberater = 0;
$1('#content').append('<div id="abcd" style="position:fixed; top:20px; right:20px; width:200px; height:200px; overflow:auto; z-index:999;"><table width="100%"><tr><td id="beratungnext">Keine Beratung aktiv.</td></td></table></div>');
/**
// sortiert nachgefragte Beratungen standardm��ig nicht
if (GM_getValue('sortFolgeBeratOben','null')=='asc'){
$1(".tablesorter:first thead tr").children("th:contains('"+GM_getValue('sortBeratOben','Bezahlung')+"')").click();
} else if (GM_getValue('sortFolgeBeratOben','null')=='desc') {
$1(".tablesorter:first thead tr").children("th:contains('"+GM_getValue('sortBeratOben','Bezahlung')+"')").click().click();
}
// sortiere Berater standardm��ig nicht
if (GM_getValue('sortFolgeBeratUnten','null')=='asc'){
$1(".tablesorter:last thead tr").children("th:contains('"+GM_getValue('sortBeratUnten','Level')+"')").click();
} else if(GM_getValue('sortFolgeBeratUnten','null')=='desc') {
$1(".tablesorter:last thead tr").children("th:contains('"+GM_getValue('sortBeratUnten','Level')+"')").click().click();
}
*/
// Adding Heading for Rating column
$1('.tablesorter:first thead tr').append('<th class="scriptRating">Rating</th>');
// berechner fuer jede Anfrage
$1('.tablesorter:first tbody tr').each(function ( ) {
// extrahiere alle Werte aus Tabelle
werte = new Array;
i=0;
$1(this).children().each(function () {
werte[i] = $1(this).text();
i++
});
// Aufbereitung der Werte
var dauer_eing = werte[1]
var dauer_regex = /(\d+)/;
if (dauer_regex.test(dauer_eing)){
var dauer = parseInt(dauer_eing.match(dauer_regex,$1)[1]);
} else {
var dauer = 0;
}
var bezahlung = parseFloat(werte[3].replace(/\./g, "").replace(/,/, "."));
rating = Math.round(bezahlung/dauer)
//trage Rating in tabelle ein.
$1(this).append('<td class="scriptRating">'+Trenner(rating)+'&eur;/min</td>');
});
/**
// alert('Highscore')
$1("tr:contains('"+GM_getValue('highscoreInteresse','TLB')+"')").children().attr('style','background-color:'+GM_getValue('highscoreFarbe','Yellow')+';');
*/
$1('.tablesorter:last thead tr').append('<th class="header scriptErtrag">Blubb</th>');
i=0;
$1('.tablesorter:last > tbody > tr').each(function ( ) {
werte = new Array;
$1(this).children(":contains('Geldanlage')").each(function () {
zwischenwerte = new Array();
$1(this).find("tr").each(function(){
zwischenwerte.push($1(this).children("td:first").text());
zwischenwerte.push($1(this).children("td:last").text());
// werte.push(dump(zwischenwerte));
zwischenwerte.reverse()
ganzezahl = /d+/;
zwischenwerte[0] = zwischenwerte[0].substr(0,zwischenwerte[0].length-1);
// zwischenwerte.sort(sortierfunktion) // // Entry Point !!!!
werte.push(zwischenwerte);
zwischenwerte = new Array();
// alert($1(this).text());
});
//werte.push("1: ");
});
werte.sort(sortierfunktion);
//werte = new Array("2","6");
beraterid = 0;
aktion = $1(this).children("td:last").html();
beraterid_regex = /berater=(\d+)/;
if(beraterid_regex.test(aktion)){
beraterid = aktion.match(beraterid_regex)[1];
//alert(beraterid);
}
zelleninhalt = $1(this).children("td:first").text();
wartetaufeinsatz_regex = /Einsatz/;
//trage Rating in tabelle ein.
// $1(this).append('<td class="scriptErtrag"><pre style="font-size: 10pt;">'+ dump(werte)+ '</pre></td>');
if(wartetaufeinsatz_regex.test(zelleninhalt)){
Ausgabe = "<a href='javascript:void()' id='markberater"+i+"' blubb='"+ werte[0][1]+"' blubb2='"+beraterid+"'>Markiere: "+ werte[0][1]+"</a>";
$1(this).append('<td class="scriptErtrag">'+ Ausgabe+ '</td>');
addButtonListener(i,beraterid)
wartendeberater++
}
else
{
Ausgabe = "steht nicht zur Auswahl";
$1(this).append('<td class="scriptErtrag">'+ Ausgabe+ '</td>');
}
i++;
});
// markiereAngebote("Aktien");
// window.setInterval("updateBeratungsdauern()", 1000);
window.setTimeout(updateBeratungsdauern, 1000);
// updateBeratungsdauern();
}
function sortierfunktion(a, b) {
// alert(a + '-' + b)
return parseInt(b[0]) - parseInt(a[0]);
}
function markiereAngebote() {
// alert ($1(this).attr("blubb"));
$1(".tablesorter:first tr").children().attr('style','');
highlighting="YellowGreen";
highlighting2=$1("#content").attr("highlighting");
if(highlighting2 != ""){
highlighting=highlighting2;
}
$1(".tablesorter:first tr:contains('"+$1(this).attr("blubb")+"')").children().attr('style','background-color:'+highlighting+';');
$1("select.berater").attr('value',$1(this).attr("blubb2"));
//$1(".tablesorter:first tr:contains('"+a+"')").children().attr('style','background-color:yellow;');
return false;
}
function addButtonListener(i,a){
var button = document.getElementById("markberater"+i);
button.addEventListener('click',markiereAngebote,true);
// var button = document.getElementById("showuebersicht");
// button.addEventListener('click',showUebersicht,true);
}
function updateBeratungsdauern() {
neuertitle='';
if(wartendeberater>0){
neuertitle+='('+wartendeberater + ' bereit)';
}
kleinstedauer = new Array();
kleinstedauer["min"] = 999
stopp = false;
erneutupdaten = false;
$1('.tablesorter:last > tbody > tr').each(function ( ) {
zelleninhalt = $1(this).children("td:first").html()
min_regex = /(\d+) Min/;
// alert($1(this).children("td:first").html());
if (min_regex.test(zelleninhalt)){
sek_regex = /(\d+) Sek/;
var verblminuten = parseInt(zelleninhalt.match(min_regex,$1)[1]);
if(sek_regex.test(zelleninhalt)){
var verblsekunden = parseInt(zelleninhalt.match(sek_regex,$1)[1]);
verblsekunden--;
//alert(verblminuten);
if(verblsekunden<0){
verblsekunden = 59;
verblminuten--;
//alert(verblminuten);
zelleninhalt = zelleninhalt.replace(min_regex, verblminuten + " Min");
}
zelleninhalt = zelleninhalt.replace(sek_regex, verblsekunden + " Sek");
}
else
{
verblsekunden =29
zelleninhalt += "<br>29 Sekunden";
// var verblminuten = parseInt(zelleninhalt.match(min_regex,$1)[1]);
// verblminuten--;
//alert(verblminuten);
zelleninhalt = zelleninhalt.replace(min_regex, verblminuten + " Min");
}
if( kleinstedauer["min"] > verblminuten){
// alert(1);
kleinstedauer["min"] = verblminuten
kleinstedauer["sek"] = verblsekunden
}
} else {
return true;
}
if (verblminuten<1 && verblsekunden < 2){
stopp = true;
pfad = window.location.href;
position = pfad.indexOf("/index.php");
if((pfad.substr(position) == '/index.php?section=beratung') || (pfad.substr(position,26) == '/index.php?section=beratung#')) {
location.reload();
return false;
} else {
window.location.pathname = "/index.php?section=beratung";
return false;
}
return true;
}
$1(this).children("td:first").html(zelleninhalt)
erneutupdaten = true;
});
if(erneutupdaten && !stopp){
window.setTimeout(updateBeratungsdauern, 995);
} else {
// alert("stopp");
}
// $1('#abcd').remove();
if (kleinstedauer["min"]<999){
neuertitle+=' next in '+kleinstedauer["min"]+' Min '+kleinstedauer["sek"]+' Sek';
$1("#beratungnext").html(wartendeberater+' Berater bereit<br>Nächste Beratung in '+kleinstedauer["min"]+' Min '+kleinstedauer["sek"]+' Sek.');
}
document.title=neuertitle;
}