Last active
May 9, 2022 14:39
-
-
Save ricealexander/a527ba6fde495e7ed7ec37a74210498e to your computer and use it in GitHub Desktop.
A fix for StreamGuys platforms reports, fixing the broken downloads total field
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
// StreamGuys Platforms Report Fix | |
// In the StreamGuys platform, all "Total" fields on tables are empty. | |
// This script can be run in the console and populates the "Total" field | |
// for all tables on the current page. | |
// Tables have an id following pattern /re\d+:table/ | |
const tables = document.querySelectorAll('table[id^="re"][id$=":table"]') | |
for (const table of tables) { | |
const downloadsCells = table.querySelectorAll('tr:not(.standard-re-row-total) td.txt + td') | |
const totalsCell = table.querySelector('tr.standard-re-row-total td.txt + td') | |
// Empty tables do not match elements for downloadsCells or totalsCell | |
if (downloadsCells.length === 0) continue | |
// Sum the values of each cell | |
let totalDownloads = 0 | |
for (const cell of downloadsCells) { | |
const downloads = cell.textContent.replace(/,/g, '') // remove commas from numbers | |
totalDownloads += Number(downloads) | |
} | |
totalsCell.innerText = totalDownloads | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment