<Back
let p = document.location.pathname, u = '/grades/grades/', u2 = '/grades/pupils', lsId = s => localStorage[p.replace(u, '')] = JSON.stringify(s), data = id => JSON.parse(localStorage[id] || '{}'); function round_nearest(value, decPlaces) { return Math.round(value * Math.pow(10, decPlaces)) / Math.pow(10, decPlaces); } function calcPoints() { let total = {p:0, max: 0, done: false, pct: '0%'}; $('.previewquestionbox').each((i, e) => { let max = +$('.right ~ *, .right > *', e).last().text().match(/[0-9]+/)[0]; let $p = $('.right.pointsdesc, .right.pointsdesc input', e); total.max += max; let addpts = 0, incor = 0; if ($(e).is('.inconclusive')) { addpts = $p.eq(1).val(); } else { incor = $('.checkedincorrect, .checkedrealanswer', e).length; addpts = !$('.checkedincorrect, .checkedcorrect', e).length ? 0 : max - incor; $p.text(addpts); } total.p += +addpts; let pct = round_nearest(total.p / total.max * 100, 2) + '%'; $('.result', '#result_div_new').eq(0).text(total.p + ' von ' + total.max); $('.result', '#result_div_new').eq(1).text(pct); total.pct = pct; }); total.done = $('#done').is(':checked'); lsId(total); } if (p.indexOf(u) === 0) { $(_=> { $('#result_div').attr('id', 'result_div_new').find('table').append('WIRD NICHT GESPEICHERT'); $('#done').click(calcPoints); let chPts = changePoints; window.changePoints = function(a,b,c) { calcPoints(); chPts(a,b,c); }; calcPoints(); }); } else if (p.indexOf(u2) === 0) { $('a', '.classroom').each((i, e) => { let info = data(e.pathname.replace(u,'')), $c = $('td', $(e).closest('tr')); $c.eq(3).text(info.pct || '---'); $c.eq(4).text((info.p ||'?') + ' / ' + (info.max || '?')); $c.eq(5).text(info.done ? 'JA' : '---'); }); }