NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name PikaCalculator // @namespace https://openuserjs.org/scripts/alesc // @description Calculates eur from pike on Moja Pika Mercator web page. // @copyright 2018, alesc (https://openuserjs.org/users/alesc) // @updateURL https://openuserjs.org/meta/alesc/PikaCalculator.meta.js // @license MIT // @include https://www.mercator.si/user/kartice/* // @version 1.0.4 // @author alesc // @grant none // ==/UserScript== var bonsis = []; var myeur = []; var sum = 0; var today = new Date(); // Values from: https://www.mercator.si/pika/o-piki/bonitetni-sistem/ bonsis[0] = {pik: 3500, eur: 210}; bonsis[1] = {pik: 1250, eur: 50}; bonsis[2] = {pik: 250, eur: 5}; // Test values date to days: // today = new Date("2017-01-29"); // 2 // today = new Date("2017-03-29"); // 124 // today = new Date("2017-12-31"); // 31 // today = new Date("2017-01-01"); // 30 var firstPeriodStarts = new Date(today.getFullYear() + "-01-01"); // 2017-01-01 to 2017-01-31 var firstPeriodEnds = new Date(today.getFullYear() + "-01-31"); var secondPeriodStarts = new Date(today.getFullYear() + "-02-01"); // 2017-02-01 to 2017-07-31 var secondPeriodEnds = new Date(today.getFullYear() + "-07-31"); var thirdPeriodStarts = new Date(today.getFullYear() + "-08-01"); // 2017-08-01 to 2018-01-31 var thirdPeriodEnds = new Date((today.getFullYear()+1) + "-01-31"); var currentPeriodEnds = thirdPeriodEnds; if (firstPeriodStarts <= today && today <= firstPeriodEnds) { currentPeriodEnds = firstPeriodEnds; } else if (secondPeriodStarts <= today && today <= secondPeriodEnds) { currentPeriodEnds = secondPeriodEnds; } // Get piks var allcells = document.getElementsByTagName('td'); var origHTML = allcells[3].innerHTML; var mypik = origHTML.split(" "); mypik[0] = parseInt(mypik[0], 10); // Test values pik to eur: // mypik[0] = 0; // 0 // mypik[0] = 1; // 0 // mypik[0] = 251; // 5 // mypik[0] = 1250; // 50 // mypik[0] = 1721; // 55 // mypik[0] = 3500; // 210 // mypik[0] = 10000; // 530 if (Number.isInteger(mypik[0]) === false) { alert('Failed to get piks!\nhtml:[' + origHTML + '], pik:[' + mypik[0] + '], type:[' + typeof mypik[0] + ']'); return; } var remainderPik = mypik[0]; for (var i=0; i<bonsis.length; i++) { myeur[i] = Math.floor(remainderPik / bonsis[i].pik); remainderPik = remainderPik % bonsis[i].pik; } for (var i=0; i<myeur.length; i++) { sum += (myeur[i] * bonsis[i].eur); } //alert('Pik:' + mypik[0] + ' Sum:' + sum); allcells[3].innerHTML = origHTML + "<font color='purple'> = " + sum + " EUR</font><br/>"; allcells[3].innerHTML = allcells[3].innerHTML + "<font color='purple'>(Porabiti do: " + currentPeriodEnds.toDateString() + " oz. " + dateDiffInDays(today, currentPeriodEnds) + " DNI)</font>"; function dateDiffInDays(a, b) { var dateA = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate()); var dateB = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate()); return Math.floor((dateB - dateA) / (1000 * 3600 * 24)); }