Skip to content

Instantly share code, notes, and snippets.

@rizkysyazuli
Last active February 21, 2020 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rizkysyazuli/1590750045f6c3e04bc10410fd9277de to your computer and use it in GitHub Desktop.
Save rizkysyazuli/1590750045f6c3e04bc10410fd9277de to your computer and use it in GitHub Desktop.
[Bookmarklet - Bitcoin.co.id] Get estimate values of your crypto currency portfolio in Rupiah. Probably no longer works. #bookmarklets
/*
* Author: Rizky Syazuli <br4inwash3r@gmail.com>
* This code snippet is used to show live IDR estimate of your crypto assets in Bitcoin.co.id
* Used as a bookmarklet. Go here to do convert any JS snippets into a bookmarklet: https://bookmarkify.it
*/
if (window.location.href !== 'https://vip.bitcoin.co.id/market') {
alert(`Your're not in VIP spot market page`);
}
function updateMarketTable(rows) {
rows.forEach(function(coin, index) {
let balanceCell = coin.querySelector('td:nth-child(6)');
let frozenCell = coin.querySelector('td:last-child');
// get coin code/label
let coinLabel = balanceCell.querySelector('span').className.split('_')[1];
let coinCode = coin.querySelector('td:first-child').innerText.split('/')[0];
// fetches global variables available from the site
let coinBalance = window[`balance_${coinLabel}`];
let coinFrozen = window[`balance_frozen_${coinLabel}`];
let coinPrice = window[`price_${coinLabel}idr`];
// convert values
let coinValue = Math.round(coinPrice * coinBalance);
let coinFrozenValue = Math.round(coinPrice * coinFrozen);
// output formatting, use some functions from the site
let coinBalanceText = `<span class="balance_${coinLabel}_val">${btc_format(coinBalance)}</span> ${coinCode}`;
let coinValueText = `<br><strong>${rp_format(coinValue)} IDR</strong>`;
let coinFrozenText = `<span>${btc_format(coinFrozen)}</span> ${coinCode}`;
let coinFrozenValueText = `<br><strong>${rp_format(coinFrozenValue)} IDR</strong>`;
// update balance & current value
balanceCell.innerHTML = coinBalance ? `${coinBalanceText}${coinValueText}` : `${coinBalanceText}`;
frozenCell.innerHTML = coinFrozen ? `${coinFrozenText}${coinFrozenValueText}` : `${coinFrozenText}`;
});
}
let marketIDR = document.querySelector('.table-markets');
let marketIDRCoins = marketIDR.querySelectorAll('tbody tr');
// add new column to display frozen assets
marketIDR.querySelectorAll('tr').forEach(function(row, index) {
if (index) {
row.insertCell();
var marketCell = row.querySelector('td:first-child');
marketCell.innerHTML = `<a href="${row.getAttribute('href')}">${marketCell.innerText}</a>`;
} else {
row.appendChild(document.createElement('th')).innerText = 'Frozen Balance';
row.querySelectorAll('th').forEach(function(head, index) {
head.removeAttribute('width'); // reset column width
});
}
});
// init function
updateMarketTable(marketIDRCoins);
// auto update price every 2s
setInterval(function() {
updateMarketTable(marketIDRCoins);
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment