Skip to content

Instantly share code, notes, and snippets.

@christoph2806
Last active January 26, 2021 09:24
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 christoph2806/d9d3d025dc9535dff1d5fc1041cddfcf to your computer and use it in GitHub Desktop.
Save christoph2806/d9d3d025dc9535dff1d5fc1041cddfcf to your computer and use it in GitHub Desktop.
Userscript to fix Etherscan amount representation
// ==UserScript==
// @name Etherscan Number fix
// @namespace http://etherisc.com
// @version 0.1
// @description Fix representation of amounts in etherscan
// @author Christoph Mussenbrock
// @match https://etherscan.io/token/*
// @grant none
// @license https://unlicense.org/
// ==/UserScript==
//
// To run this script, install Tampermonkey and install this script as a userscript.
// Instructions: https://www.tampermonkey.net/
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
(function() {
'use strict';
const decimals = 4;
function fixIt(item) {
if (item.nodeName === 'TD') {
const newTd = document.createElement('td');
newTd.style.textAlign = 'right';
newTd.innerHTML = (Math.round(Number(item.innerHTML.replace(/,/g, '')*10**decimals))/10**decimals)
.toLocaleString(undefined, {minimumFractionDigits: decimals});
return newTd;
}
return item;
}
let rows;
try {
rows = document.querySelector('#maindiv').childNodes[3].childNodes[1].childNodes[3].childNodes;
} catch (e) {
return;
}
rows.forEach(item => {
if (item.nodeName === 'TR') {
item.childNodes[7].replaceWith(fixIt(item.childNodes[7]));
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment