Last active
January 26, 2021 09:24
-
-
Save christoph2806/d9d3d025dc9535dff1d5fc1041cddfcf to your computer and use it in GitHub Desktop.
Userscript to fix Etherscan amount representation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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