Skip to content

Instantly share code, notes, and snippets.

@mkolesnik
Created February 12, 2020 09:39
Show Gist options
  • Select an option

  • Save mkolesnik/b38bdd6d3c9c011f4b01737fecf89a47 to your computer and use it in GitHub Desktop.

Select an option

Save mkolesnik/b38bdd6d3c9c011f4b01737fecf89a47 to your computer and use it in GitHub Desktop.
Greasemonkey script to show balance on 10bis
// ==UserScript==
// @name 10bis balance
// @namespace 10bis
// @author Mike Kolesnik <[email protected]>
// @include https://www.10bis.co.il/*
// @exclude https://www.10bis.co.il/Account/*
// @version 1
// @grant GM_log
// @require http://code.jquery.com/jquery-2.1.1.min.js
// @require https://raw.githubusercontent.com/hebcal/hebcal-js/master/client/hebcal.noloc.min.js
// ==/UserScript==
// -------------[ USER CONFIG ]--------------
// Your monthly allowance
var ALLOWANCE = 735
// Day of month when 10bis allowance is reset
var REFILL_DAY_OF_MONTH = 11
// On which days don't you order food?
// 0 = Sunday, 1 = Monday, etc..
var NO_ORDER_DAYS = [0,5,6]
// -------------[ END USER CONFIG ]--------------
var ATZMAUT = new Hebcal.HDate(5, 2)
var ATZMAUT_WEEK_DAY = ATZMAUT.greg().getDay()
if (ATZMAUT_WEEK_DAY == 5) {
ATZMAUT = new Hebcal.HDate(4, 2)
} else if (ATZMAUT_WEEK_DAY == 6) {
ATZMAUT = new Hebcal.HDate(3, 2)
} else if (ATZMAUT_WEEK_DAY == 1) {
ATZMAUT = new Hebcal.HDate(6, 2)
}
var TODAY = new Hebcal.HDate()
var TISHREI_YEAR = TODAY.getFullYear()
if (TODAY.getMonth() == 6) {
TISHREI_YEAR++
}
var HOLIDAYS = [
// Rosh Hashana
new Hebcal.HDate(29, 6),
new Hebcal.HDate(1, 7, TISHREI_YEAR),
new Hebcal.HDate(2, 7, TISHREI_YEAR),
// Kipur
new Hebcal.HDate(9, 7, TISHREI_YEAR),
new Hebcal.HDate(10, 7, TISHREI_YEAR),
// Sukkot
new Hebcal.HDate(14, 7, TISHREI_YEAR),
new Hebcal.HDate(15, 7, TISHREI_YEAR),
new Hebcal.HDate(21, 7, TISHREI_YEAR),
new Hebcal.HDate(22, 7, TISHREI_YEAR),
// Pesach
new Hebcal.HDate(14, 1),
new Hebcal.HDate(15, 1),
new Hebcal.HDate(20, 1),
new Hebcal.HDate(21, 1),
// Shavuot
new Hebcal.HDate(5, 3),
new Hebcal.HDate(6, 3),
ATZMAUT
]
// Function to add days to Date
Date.prototype.addDays=function(d){return new Date(this.valueOf()+864E5*d);};
function calcNonOrderDays() {
// Calculate when 10bis is getting refilled
var curDate = TODAY.greg()
var refillDate = new Date(curDate)
refillDate.setDate(REFILL_DAY_OF_MONTH)
if (refillDate <= curDate) {
refillDate.setMonth(refillDate.getMonth() + 1)
}
var daysLeft = 0
while (curDate < refillDate) {
if ($.inArray(curDate.getDay(), NO_ORDER_DAYS) == -1 &&
$.grep(HOLIDAYS, function(h) { return h.isSameDate(new Hebcal.HDate(curDate))}).length == 0) {
daysLeft++
}
curDate = curDate.addDays(1)
}
return daysLeft
}
$.get("https://www.10bis.co.il/Account/UserReport", function(data) {
$balance = $(data).find('.userReportDataTbl').clone().wrap('<p/>').parent()
// Calculate how much sibsidized money left, make sure not to go over negatives
$usedText = $($balance.clone().find('.totalsFieldValueTh')[1]).text()
$used = parseFloat($usedText.replace(/[^\d.-]/g,''))
$left = (ALLOWANCE-$used)
if ($left <= 0) {
$left = 0
}
var daysLeft = calcNonOrderDays()
$balance.find('tr:last').prepend(
'<tr style="height: 0px;">' +
'<th class="totalsFieldNameTh"> יתרה מסובסדת : </th>' +
'<th class="totalsFieldValueTh currency"> ₪' + $left.toFixed(2) + '</th>' +
'<th class="totalsFieldNameTh"> לניצול יומי (נותרו ' + daysLeft + ' ימי עבודה) : </th>' +
'<th class="totalsFieldValueTh currency"> ₪' + ($left / daysLeft).toFixed(2) + '</th>' +
'<th class="totalsFieldNameTh"> מסגרת מסובסדת : </th>' +
'<th class="totalsFieldValueTh currency"> ₪' + ALLOWANCE.toFixed(2) + '</th>' +
'</tr>'
)
$(".mainElement_div > div").prepend(
'<div class="userReport">' + $balance.html() + '</div>')
$(".userReport tr").css('height', '0px')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment