Last active
November 25, 2023 10:12
-
-
Save jsilva74/f81877aeae866b52111db4aea7a39d5d to your computer and use it in GitHub Desktop.
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 My Flight Totals | |
// @namespace http://tampermonkey.net/ | |
// @version 1.3.1 | |
// @description try to take over the world! | |
// @author José Silva Jr. | |
// @match https://server.fseconomy.net/myflight.jsp | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=fseconomy.net | |
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js | |
// ==/UserScript== | |
/* global $ */ | |
function main() { | |
$(document).ready(function() { | |
const header = $('h2:contains("Assignments")') | |
const ready = $('.myflight-assignments--ready') | |
const notDeparting = $('.myflight-assignments--notDeparting') | |
const otherAirport = $('.myflight-assignments--otherAirport') | |
const readyTable = $(ready).find('.assignmentTable > tbody > tr') | |
const notDepartingTable = $(notDeparting).find('.assignmentTable > tbody > tr') | |
const otherAirportTable = $(otherAirport).find('.assignmentTable > tbody > tr') | |
const holdTable = $('.holdTable > tbody > tr') | |
const readyTableValues = Array.from(readyTable || []).map((row) => Number(row.cells[1].innerText.replace(/[$,]/g, ''))) || [] | |
const readyTableTotal = readyTableValues.reduce((tot, val) => tot + val, 0) | |
const readyTableCount = readyTableValues.length | |
const notDepartingTableValues = Array.from(notDepartingTable || []).map((row) => Number(row.cells[1].innerText.replace(/[$,]/g, ''))) || [] | |
const notDepartingTableTotal = notDepartingTableValues.reduce((tot, val) => tot + val, 0) | |
const notDepartingTableCount = notDepartingTableValues.length | |
const otherAirportValues = Array.from(otherAirportTable || []).map((row) => Number(row.cells[1].innerText.replace(/[$,]/g, ''))) || [] | |
const otherAirportTotal = otherAirportValues.reduce((tot, val) => tot + val, 0) | |
const otherAirportCount = otherAirportValues.length | |
const holdTableValues = Array.from(holdTable || []).map(row => Number(row.cells[1].innerText.replace(/[$,]/g, ''))) || [] | |
const holdTableTotal = holdTableValues.reduce((tot, val) => tot + val, 0) | |
const holdTableCount = holdTableValues.length | |
const total = readyTableTotal + notDepartingTableTotal + otherAirportTotal + holdTableTotal | |
const count = readyTableCount + notDepartingTableCount + otherAirportCount + holdTableCount | |
otherAirport.append(` | |
<hr/> | |
<p> | |
<strong>${Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(otherAirportTotal)}</strong>, Total pay from ${otherAirportCount} assignment${otherAirportCount > 1 ? 's' : ''} | |
</p> | |
`) | |
header.append(` (${Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(total)}, ${count} assignment${count !== 1 ? 's' : ''})`) | |
}) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment