Last active
January 16, 2023 15:20
-
-
Save jsilva74/c822bf4df319b1a26dca0ec16fc2ed09 to your computer and use it in GitHub Desktop.
Tampermonkey user script to convert fuel to gallons at FSE World goods page
This file contains hidden or 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 FSE Fuel in Gallons | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description convert fuel to gallons at FSE World goods page | |
// @author jsilva74 | |
// @match https://server.fseconomy.net/goods.jsp | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=fseconomy.net | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const addFuelAmountInGallons = () => { | |
const table = document.querySelector('table') | |
if (!table) return | |
for (let i = 1; i < table.rows.length; i++) { | |
const row = table.rows[i] | |
const isFuel = row.cells[1].innerText.includes('Fuel') | |
const amountInKg = parseInt(row.cells[2].innerText.split(' ')[0]) | |
const amountText = [`${amountInKg.toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: 0 })} Kg`] | |
if (isFuel) { | |
const amountInGallons = Math.trunc(parseInt(amountInKg) / 2.68735) | |
amountText.push('=', `${amountInGallons.toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: 0 })} gal`) | |
} | |
row.cells[2].innerText = amountText.join(' ') | |
} | |
} | |
document.addEventListener('load', addFuelAmountInGallons(), false) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment