2021-04-07 02:41:53 +02:00
|
|
|
Number.prototype.pad = function(size) {
|
2024-12-07 21:15:46 +01:00
|
|
|
var s = String(this);
|
|
|
|
while (s.length < (size || 2)) {s = "0" + s;}
|
|
|
|
return s;
|
2021-04-07 02:41:53 +02:00
|
|
|
}
|
|
|
|
|
2022-07-16 19:15:25 +02:00
|
|
|
const Mode = {
|
2024-12-07 21:15:46 +01:00
|
|
|
Deposit: 0,
|
|
|
|
Buy: 1,
|
|
|
|
Transfer: 2,
|
2022-07-16 19:15:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let mode = Mode.Deposit;
|
2021-04-07 09:36:18 +02:00
|
|
|
let product_id = null;
|
2022-07-16 19:15:25 +02:00
|
|
|
let target_user = null;
|
|
|
|
let target_user_li = null;
|
2021-04-07 02:41:53 +02:00
|
|
|
let deposit = '0';
|
2024-12-07 15:50:37 +01:00
|
|
|
let button = document.createElement('a');
|
|
|
|
let button_transfer = document.createElement('a');
|
2021-04-07 02:41:53 +02:00
|
|
|
let input = document.getElementById('deposit-wrapper');
|
|
|
|
let amount = document.getElementById('deposit-amount');
|
2021-04-07 09:36:18 +02:00
|
|
|
let title = document.getElementById('deposit-title');
|
2022-07-16 19:15:25 +02:00
|
|
|
let userlist = document.getElementById('transfer-userlist');
|
|
|
|
let userlist_list = document.getElementById('transfer-userlist-list');
|
|
|
|
let ok_button = document.getElementById('numpad-ok');
|
2024-12-07 15:50:37 +01:00
|
|
|
button.classList.add('btn');
|
|
|
|
button.classList.add('btn-primary');
|
|
|
|
button.classList.add('me-2');
|
2021-04-07 02:41:53 +02:00
|
|
|
button.innerText = 'Deposit';
|
|
|
|
button.onclick = (ev) => {
|
2024-12-07 21:15:46 +01:00
|
|
|
mode = Mode.Deposit;
|
2021-04-07 09:36:18 +02:00
|
|
|
product_id = null;
|
2024-12-07 21:15:46 +01:00
|
|
|
target_user = null;
|
2021-04-07 02:41:53 +02:00
|
|
|
deposit = '0';
|
2021-04-07 09:36:18 +02:00
|
|
|
title.innerText = 'Deposit';
|
2021-04-07 02:41:53 +02:00
|
|
|
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
|
|
|
|
input.classList.add('show');
|
2024-12-07 21:15:46 +01:00
|
|
|
userlist.classList.remove('show');
|
|
|
|
ok_button.classList.remove('disabled');
|
2022-07-16 19:15:25 +02:00
|
|
|
};
|
2024-12-07 15:50:37 +01:00
|
|
|
button_transfer.classList.add('btn');
|
|
|
|
button_transfer.classList.add('btn-primary');
|
|
|
|
button_transfer.classList.add('me-2');
|
2022-07-16 19:15:25 +02:00
|
|
|
button_transfer.innerText = 'Transfer';
|
|
|
|
button_transfer.onclick = (ev) => {
|
2024-12-07 21:15:46 +01:00
|
|
|
mode = Mode.Transfer;
|
2022-07-16 19:15:25 +02:00
|
|
|
product_id = null;
|
2024-12-07 21:15:46 +01:00
|
|
|
target_user = null;
|
2022-07-16 19:15:25 +02:00
|
|
|
deposit = '0';
|
|
|
|
title.innerText = 'Transfer';
|
|
|
|
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
|
|
|
|
input.classList.add('show');
|
2024-12-07 21:15:46 +01:00
|
|
|
userlist.classList.add('show');
|
|
|
|
ok_button.classList.add('disabled');
|
2021-04-07 02:41:53 +02:00
|
|
|
};
|
2021-04-07 09:36:18 +02:00
|
|
|
setup_custom_price = (pid, pname) => {
|
2024-12-07 21:15:46 +01:00
|
|
|
mode = Mode.Buy;
|
2021-04-07 09:36:18 +02:00
|
|
|
product_id = pid;
|
2024-12-07 21:15:46 +01:00
|
|
|
target_user = null;
|
2021-04-07 09:36:18 +02:00
|
|
|
title.innerText = pname;
|
|
|
|
deposit = '0';
|
|
|
|
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
|
2022-07-16 19:15:25 +02:00
|
|
|
input.classList.add('show');
|
2024-12-07 21:15:46 +01:00
|
|
|
userlist.classList.remove('show');
|
|
|
|
ok_button.classList.remove('disabled');
|
2021-04-07 09:36:18 +02:00
|
|
|
};
|
2022-07-16 19:15:25 +02:00
|
|
|
set_transfer_user = (li, uid) => {
|
2024-12-07 21:15:46 +01:00
|
|
|
if (target_user_li != null) {
|
|
|
|
target_user_li.classList.remove('active');
|
|
|
|
}
|
|
|
|
target_user = uid;
|
|
|
|
target_user_li = li;
|
|
|
|
ok_button.classList.remove('disabled');
|
|
|
|
target_user_li.classList.add('active');
|
2022-07-16 19:15:25 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
scrollUserlist = (delta) => {
|
2024-12-07 21:15:46 +01:00
|
|
|
userlist_list.scrollBy(0, delta);
|
2022-07-16 19:15:25 +02:00
|
|
|
}
|
|
|
|
deposit_key = (k) => {
|
2024-12-07 21:15:46 +01:00
|
|
|
if (k == 'ok') {
|
|
|
|
switch (mode) {
|
|
|
|
case Mode.Deposit:
|
|
|
|
window.location.href = '/deposit?n=' + parseInt(deposit) + append_query_string;
|
|
|
|
break;
|
|
|
|
case Mode.Buy:
|
|
|
|
window.location.href = '/buy?pid=' + product_id + '&price=' + parseInt(deposit) + append_query_string;
|
|
|
|
break;
|
|
|
|
case Mode.Transfer:
|
|
|
|
if (target_user == null) {
|
|
|
|
return;
|
2022-07-18 23:49:13 +02:00
|
|
|
}
|
2024-12-07 21:15:46 +01:00
|
|
|
window.location.href = '/transfer?target=' + target_user + '&n=' + parseInt(deposit) + append_query_string;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mode = Mode.Deposit;
|
|
|
|
deposit = '0';
|
|
|
|
product_id = null;
|
|
|
|
target_user = null;
|
|
|
|
if (target_user_li != null) {
|
|
|
|
target_user_li.classList.remove('active');
|
|
|
|
}
|
|
|
|
input.classList.remove('show');
|
|
|
|
userlist.classList.remove('show');
|
2021-04-07 02:41:53 +02:00
|
|
|
} else if (k == 'del') {
|
2024-12-07 21:15:46 +01:00
|
|
|
if (deposit == '0') {
|
|
|
|
product_id = null;
|
|
|
|
target_user = null;
|
|
|
|
if (target_user_li != null) {
|
|
|
|
target_user_li.classList.remove('active');
|
|
|
|
}
|
|
|
|
userlist.classList.remove('show');
|
|
|
|
input.classList.remove('show');
|
|
|
|
}
|
|
|
|
deposit = deposit.substr(0, deposit.length - 1);
|
|
|
|
if (deposit.length == 0) {
|
|
|
|
deposit = '0';
|
|
|
|
}
|
|
|
|
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
|
|
|
|
} else {
|
|
|
|
if (deposit == '0') {
|
|
|
|
deposit = k;
|
2021-04-07 02:41:53 +02:00
|
|
|
} else {
|
2024-12-07 21:15:46 +01:00
|
|
|
deposit += k;
|
|
|
|
}
|
|
|
|
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
|
2021-04-07 02:41:53 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-12-08 00:21:11 +01:00
|
|
|
let oldbuttons = document.getElementsByClassName("deposit-to-remove");
|
|
|
|
while (oldbuttons.length > 0) {
|
|
|
|
oldbuttons[0].remove();
|
2024-12-07 21:15:46 +01:00
|
|
|
}
|
2024-12-08 00:21:11 +01:00
|
|
|
let list = document.getElementById("depositlist");
|
2024-12-07 21:15:46 +01:00
|
|
|
list.insertBefore(button_transfer, list.children[0]);
|
|
|
|
list.insertBefore(button, list.children[0]);
|