0% found this document useful (0 votes)
267 views

Github Unit of Balance Free Bitco - in

This userscript changes the unit of the displayed bitcoin balance on freebitco.in from BTC to microBTC (μBTC). It gets the balance element, removes any existing child nodes, calculates the new balance value in microBTC, creates new elements to display the updated balance and unit, and inserts an event listener to keep the balance updated if the DOM changes.

Uploaded by

Chandra Shekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
267 views

Github Unit of Balance Free Bitco - in

This userscript changes the unit of the displayed bitcoin balance on freebitco.in from BTC to microBTC (μBTC). It gets the balance element, removes any existing child nodes, calculates the new balance value in microBTC, creates new elements to display the updated balance and unit, and inserts an event listener to keep the balance updated if the DOM changes.

Uploaded by

Chandra Shekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

==UserScr

ipt==
// @name change unit of balance on freebitco.in
// @namespace http://5th.ch/
// @version 0.5
// @description change unit of balance on freebitco.in
// @author @koma5
// @match https://freebitco.in/*
// @grant none
// @downloadURL
https://gist.githubusercontent.com/koma5/4eccd9251d5874d454a197958e78135c/raw/
change_unit_of_balance_freebitco.in.js
// @updateURL
https://gist.githubusercontent.com/koma5/4eccd9251d5874d454a197958e78135c/raw/
change_unit_of_balance_freebitco.in.js
// ==/UserScript==
(function() {
'use strict';
function changeDOM() {
var unitMap = {mBTC : { unit : 'mBTC', factor : 1e3 },
satoshi : { unit : 'satoshi', factor : 1e8 },
microBTC : { unit : 'μBTC', factor : 1e6 }
};
var unitChoice = unitMap.microBTC;
var balanceLi = document.getElementById("balance").parentNode;
//remove eventListener otherwise we run into a loop
balanceLi.removeEventListener('DOMNodeInserted', changeDOM);
var balance = document.getElementById("balance").innerHTML;
balance *= unitChoice.factor;
//remove balance and textnode
while (balanceLi.hasChildNodes()) {
balanceLi.removeChild(balanceLi.firstChild);
}
//recreate balance span
var balanceSpan = document.createElement("span");
balanceSpan.setAttribute('id', 'balance');
var balanceSpanText = document.createTextNode(balance);
balanceSpan.appendChild(balanceSpanText);
//recreate textnode
var balanceLiUnitText = document.createTextNode(' ' + unitChoice.unit);
//insert balance and textnode into existing and empty blanaceli
balanceLi.appendChild(balanceSpan);
balanceLi.appendChild(balanceLiUnitText);
//readd removed eventListener
balanceLi.addEventListener('DOMNodeInserted', changeDOM, false);
console.log('changed to ' + balance + ' ' + unitChoice.unit);
}
changeDOM();
var balanceLi = document.getElementById("balance").parentNode;
balanceLi.addEventListener('DOMNodeInserted', changeDOM, false);
})();

You might also like