Skip to content

Instantly share code, notes, and snippets.

@timdorr
Last active Jun 4, 2021
Embed
What would you like to do?
// ==UserScript==
// @name Worldometers Tweaks
// @namespace http://tampermonkey.net/
// @version 1.0.1
// @description Add data to Worldometers
// @author timdorr
// @match https://www.worldometers.info/coronavirus/country/us/
// @icon https://www.google.com/s2/favicons?domain=worldometers.info
// @grant none
// ==/UserScript==
/*global $, Highcharts*/
$('body > .container').last().removeClass('container').addClass('container-fluid')
$('.container-fluid .col-md-8').first().addClass('col-md-12').removeClass('col-md-8')
$('.container-fluid .col-md-8').first().addClass('col-md-offset-2')
$('.col-md-12').first().find('> div:nth-child(-n+3)').remove()
$('.content-inner div:nth-of-type(n+7)').remove()
window.dispatchEvent(new Event('resize'));
const totalCaseChange = $('#usa_table_countries_today tbody:nth-child(2) tr:not(.total_row_usa) td:nth-child(4)')
.toArray()
.map((row, i) => [
Number(
$(row)
.text()
.replace(/[\W+,]/g, '')
),
Number(
$(`#usa_table_countries_yesterday tbody:nth-child(2) tr:nth-child(${i + 2}) td:nth-child(4)`)
.first()
.text()
.replace(/[\W+,]/g, '')
)
])
.reduce((total, v) => total + (v[0] == 0 ? 0 : v[0] - v[1]), 0)
$('#usa_table_countries_today tr td:nth-child(4)').after(
'<td style="font-weight: bold; text-align:right;"></td><td style="font-weight: bold; text-align:right;"></td>'
)
$('#usa_table_countries_today tr th:nth-child(4)').after('<th>Y New Cases</th><th>Case Change</th>')
$('#usa_table_countries_today tbody:nth-child(2) tr.total_row_usa td:nth-child(5)')
.text($('#usa_table_countries_yesterday tbody:nth-child(2) tr.total_row_usa td:nth-child(4)').text())
.css('font-weight', 'normal')
$('#usa_table_countries_today tbody:nth-child(2) tr.total_row_usa td:nth-child(6)')
.text(`${totalCaseChange > 0 ? '+' : ''}${totalCaseChange.toLocaleString()}`)
.css('font-weight', 'normal')
$('#usa_table_countries_today tbody:nth-child(2) tr:not(.total_row_usa) td:nth-child(4)').each((i, row) => {
const prevCaseChange = $(`#usa_table_countries_yesterday tbody:nth-child(2) tr:nth-child(${i + 2}) td:nth-child(4)`)
.first()
.text()
.trim()
const todayCaseChange = Number(
$(row)
.text()
.replace(/[\W+,]/g, '')
)
const caseRateChange = todayCaseChange - Number(prevCaseChange.replace(/[\W+,]/g, ''))
$(row).next().text(prevCaseChange)
if (todayCaseChange) {
$(row)
.next()
.next()
.text(`${caseRateChange > 0 ? '+' : ''}${caseRateChange.toLocaleString()}`)
.css('background-color', caseRateChange > 0 ? '#fcc' : '#cfc')
}
})
const caseData = Highcharts.charts[3].series[0].data
$('#usa_table_countries_today tbody:nth-child(2) tr.total_row_usa td:nth-child(4)')
.append(`<br/><small>+${caseData[caseData.length - 7].y.toLocaleString()}</small>`)
$('#usa_table_countries_today tbody:nth-child(2) tr.total_row_usa td:nth-child(5)')
.append(`<br/><small>+${caseData[caseData.length - 8].y.toLocaleString()}</small>`)
// New Deaths
const totalDeathChange = $('#usa_table_countries_today tbody:nth-child(2) tr:not(.total_row_usa) td:nth-child(8)')
.toArray()
.map((row, i) => [
Number(
$(row)
.text()
.replace(/[\W+,]/g, '')
),
Number(
$(`#usa_table_countries_yesterday tbody:nth-child(2) tr:nth-child(${i + 2}) td:nth-child(6)`)
.first()
.text()
.replace(/[\W+,]/g, '')
)
])
.reduce((total, v) => total + (v[0] == 0 ? 0 : v[0] - v[1]), 0)
$('#usa_table_countries_today tr td:nth-child(8)').after(
'<td style="font-weight: bold; text-align:right;"></td><td style="font-weight: bold; text-align:right;"></td>'
)
$('#usa_table_countries_today tr th:nth-child(8)').after('<th>Y New Deaths</th><th>Deaths Change</th>')
$('#usa_table_countries_today tbody:nth-child(2) tr.total_row_usa td:nth-child(9)')
.text($('#usa_table_countries_yesterday tbody:nth-child(2) tr.total_row_usa td:nth-child(6)').text())
.css('font-weight', 'normal')
$('#usa_table_countries_today tbody:nth-child(2) tr.total_row_usa td:nth-child(10)')
.text(`${totalDeathChange > 0 ? '+' : ''}${totalDeathChange.toLocaleString()}`)
.css('font-weight', 'normal')
$('#usa_table_countries_today tbody:nth-child(2) tr:not(.total_row_usa) td:nth-child(8)').each((i, row) => {
const prevDeathChange = $(`#usa_table_countries_yesterday tbody:nth-child(2) tr:nth-child(${i + 2}) td:nth-child(6)`)
.first()
.text()
.trim()
const todayDeathChange = Number(
$(row)
.text()
.replace(/[\W+,]/g, '')
)
const deathRateChange = todayDeathChange - Number(prevDeathChange.replace(/[\W+,]/g, ''))
$(row).next().text(prevDeathChange)
if (todayDeathChange) {
$(row)
.next()
.next()
.text(`${deathRateChange > 0 ? '+' : ''}${deathRateChange.toLocaleString()}`)
.css('background-color', deathRateChange > 0 ? '#fcc' : '#cfc')
}
})
const deathData = Highcharts.charts[7].series[0].data
$('#usa_table_countries_today tbody:nth-child(2) tr.total_row_usa td:nth-child(8)')
.append(`<br/><small>+${deathData[deathData.length - 7].y.toLocaleString()}</small>`)
$('#usa_table_countries_today tbody:nth-child(2) tr.total_row_usa td:nth-child(9)')
.append(`<br/><small>+${deathData[deathData.length - 8].y.toLocaleString()}</small>`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment