Skip to content

Instantly share code, notes, and snippets.

@ricealexander
Last active May 9, 2022 14:39
Show Gist options
  • Save ricealexander/a527ba6fde495e7ed7ec37a74210498e to your computer and use it in GitHub Desktop.
Save ricealexander/a527ba6fde495e7ed7ec37a74210498e to your computer and use it in GitHub Desktop.
A fix for StreamGuys platforms reports, fixing the broken downloads total field
// 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