MediaWiki Diskussion:CFoptions.js

aus FreewarWiki, der Referenz für Freewar
Zur Navigation springen Zur Suche springen

Problem[Bearbeiten]

var calc, form, gw, mx;

 function init_CF() {
   if (!document.getElementById('CFoptions')) return;
   optcont = document.getElementById('CFoptions');
   caption = document.createElement('b');
   caption.appendChild(document.createTextNode('Lernzeit anzeigen: '));
   form = document.createElement('form');
   form.action = '#';
   form.style.display = 'inline';
 
   option = document.createElement('input'); option.type = 'radio'; option.setAttribute('onclick', 'switch_CF(this);'); option.checked = 'checked'; 
   option.name = 'CF_switch'; option.value = 'level'; form.appendChild(option); form.appendChild(document.createTextNode('Lernzeit pro Stufe'));
 
   option = document.createElement('input'); option.type = 'radio'; option.setAttribute('onclick', 'switch_CF(this);');
   option.name = 'CF_switch'; option.value = 'total'; form.appendChild(option); form.appendChild(document.createTextNode('Gesamtlernzeit'));
 
   option = document.createElement('input'); option.type = 'radio'; option.setAttribute('onclick', 'switch_CF(this);');
   option.name = 'CF_switch'; option.value = 'calc'; form.appendChild(option); form.appendChild(document.createTextNode('Wartezeitenrechner'));
 
   optcont.appendChild(caption);
   optcont.appendChild(form);
 
   calc = document.getElementById('CFcalc');
   gw = Number(calc.removeChild(calc.firstChild).nodeValue);
   mx = Number(document.getElementById('CFmax').firstChild.nodeValue);
   form = document.createElement('form');
   form.action = '#';
   table = document.createElement('table');
   
   tr = document.createElement('tr');
   td = document.createElement('td'); td.appendChild(document.createTextNode('Von Stufe:')); tr.appendChild(td);
   td = document.createElement('td'); input = document.createElement('input'); input.type = 'text';
   input.style.width = '100px'; input.name = 'CFstartlevel';input.value='1'; td.appendChild(input); tr.appendChild(td);
   table.appendChild(tr);

   tr = document.createElement('tr');
   td = document.createElement('td'); td.appendChild(document.createTextNode('Bis Stufe:')); tr.appendChild(td);
   td = document.createElement('td'); input = document.createElement('input'); input.type = 'text';
   input.style.width = '100px'; input.name = 'CFendlevel'; td.appendChild(input); tr.appendChild(td);
   table.appendChild(tr);
 
   tr = document.createElement('tr');
   td = document.createElement('td'); td.appendChild(document.createTextNode('Stufe Lerntechnik:')); tr.appendChild(td);
   td = document.createElement('td'); input = document.createElement('input'); input.type = 'text';
   input.style.width = '100px'; input.name = 'CFlerntech'; td.appendChild(input); tr.appendChild(td);
   table.appendChild(tr);
 
   tr = document.createElement('tr');
   td = document.createElement('td'); td.colspan = '2'; td.style.textAlign = 'center';
   input = document.createElement('input'); input.type = 'button'; input.value = 'Berechnen';
   input.onclick = calc_CF; td.appendChild(input); tr.appendChild(td);
   table.appendChild(tr);
 
   form.appendChild(table);
   calc.appendChild(form);
 
   document.getElementById('CFtotal').style.display = 'none';
   calc.style.display = 'none';
 }

 function switch_CF(option) {
   document.getElementById('CFstartlevel').style.display = (option.value == 'level' ? 'block' : 'none');
   document.getElementById('CFtotal').style.display = (option.value == 'total' ? 'block' : 'none');
   document.getElementById('CFcalc').style.display = (option.value == 'calc' ? 'block' : 'none');
 }

 function calc_CF() {
   if (isNaN(form.CFendlevel.value) ||isNaN(form.CFstartlevel.value) || isNaN(form.CFlerntech.value)) return alert('Bitte nur Zahlen eingeben!');
   if ((Number(form.CFendlevel.value) > mx) ||(Number(form.CFstartlevel.value)< -1) || (Number(form.CFlerntech.value) > 50)) alert('Mindestens ein eingegebener Wert ist höher als die Maximalstufe der betreffenden Fähigkeit. Das Ergebnis ist hypothetisch und kann so nicht im Spiel vorkommen.');
   duration = Math.pow(0.97, form.CFlerntech.value) * (form.CFendlevel.value - 1) * gw;
   totalduration = (Math.pow(0.97, form.CFlerntech.value) * (form.CFendlevel.value - 1) * form.CFendlevel.value / 2 * gw)-(Math.pow(0.97, form.CFlerntech.value) * (form.CFstartlevel.value - 1) * form.CFstartlevel.value / 2 * gw);
   lerntechsaving = (form.CFendlevel.value - 1) * gw - duration;
   lerntechtotalsaving = ((form.CFendlevel.value - 1) * form.CFendlevel.value / 2 * gw - totalduration)-(((form.CFstartlevel.value - 1) * form.CFstartlevel.value / 2 * gw));
   if (form.nextSibling) calc.removeChild(form.nextSibling);
   calc.appendChild(document.createTextNode('Das Training auf Stufe ' + form.CFendlevel.value + ' dauert '
    + (duration >= 86400 ? String(Math.floor(duration / 86400)) + ' Tage, ' : '') + String(Math.floor((duration % 86400) / 3600))
    + ' Stunden und ' + String(Math.floor((duration % 3600) / 60)) + ' Minuten. Die Gesamtlernzeit von Stufe ' + form.CFstartlevel.value + ' bis STufe ' + form.CFendlevel.value + ' beträgt '
    + (totalduration >= 86400 ? String(Math.floor(totalduration / 86400)) + ' Tage, ' : '') + String(Math.floor((totalduration % 86400) / 3600))
    + ' Stunden und ' + String(Math.floor((totalduration % 3600) / 60)) + ' Minuten.' + (form.CFlerntech.value > 0
    ? ' Gegenüber dem Training mit Lerntechnik auf Stufe 0 wurden ' + (lerntechsaving >= 86400
    ? String(Math.floor(lerntechsaving / 86400)) + ' Tage, ' : '') + String(Math.floor((lerntechsaving % 86400) / 3600))
    + ' Stunden und ' + String(Math.floor((lerntechsaving % 3600) / 60)) + ' Minuten (Gesamtlernzeit: ' + (lerntechtotalsaving >= 86400
    ? String(Math.floor(lerntechtotalsaving / 86400)) + ' Tage, ' : '') + String(Math.floor((lerntechtotalsaving % 86400) / 3600))
    + ' Stunden und ' + String(Math.floor((lerntechtotalsaving % 3600) / 60)) + ' Minuten) eingespart.' : '')));
 }

 addOnloadHook(init_CF);


Das müsste eig. funktionieren. Aber ich kanns nicht testen (oder doch? Falls ja, wie?) Hab grad nicht mehr Zeit, aber kann morgen nochmal in Ruhe drübergucken (Sagt mir bis dahin bitte jemand wo ich sowas testen kann? :)--Rober Croft 20:07, 5. Aug. 2012 (CEST)

Um was gehts? Was funktioniert nicht? Es gibt Tools um JS direkt in Seiten einzubinden, für FF z.B. Greasemonkey.--schönen August, Zabu krawumms 20:10, 5. Aug. 2012 (CEST)
Um dieses VOn STufe x - bis stufe y Lernzeit berechnen in sniggs Benutzerseite.

EDIT: Achja, Kann bei dem Browser hier nichts installieren, das ist das Problem^^ --Rober Croft 20:12, 5. Aug. 2012 (CEST)

Achso, naja auf jedenfall bitte vorher testen, danach kanns gern rein.--schönen August, Zabu krawumms 20:13, 5. Aug. 2012 (CEST)
Testen könnt ihr, ich habs grad nochmal durch ne kleine JS-Umgebung geschickt (Die im FFox), mehr kann ich nicht tun --Rober Croft 21:30, 5. Aug. 2012 (CEST)
du kannst zum testen unser testwiki nutzen rob. ich muss es nur grad komplett neu aufsetzen, weil ich ja keine db mehr hab :(
@zabu : ich test das bei mir, wenns nich klappt, wird rob das übernehmen. hab das mal wieder vergessen, aber gut, dass das wer macht.---sniGG why so serious? 00:15, 6. Aug. 2012 (CEST)

Neue Berechnung[Bearbeiten]

Bitte die Koeffizienten in calc_cf von .97 auf .99 erhöhen. LT bringt nur noch 1%. --Sphinx Echt? 13:19, 8. Jul. 2013 (CEST)

Waren 2 Edits, hoffe das passt nun so. Erledigt--schönen Juli, Zabu delta 17:56, 8. Jul. 2013 (CEST)
Schaut gut aus, danke. --Sphinx Echt? 20:48, 8. Jul. 2013 (CEST)