Last active
December 25, 2020 21:36
-
-
Save cmnt/73a230bddfa011f2bfcea626584cb826 to your computer and use it in GitHub Desktop.
worldometer Covid-19 : Add column "Daily deaths/ million" to see fairly the daily deaths impact on each country, regardless of population size.
This file contains 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 COVID-19 Add daily death per million column to worldometers.info | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Add column "Daily deaths per million" to see fairly the daily deaths impact on each country, regardless of population size. | |
// @author Clément Dufour | |
// @match https://www.worldometers.info/coronavirus/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const nameColumn = Array.from(document.querySelector('#main_table_countries_today thead tr').children).map(col => col.textContent); | |
const indexDailyDeath = nameColumn.indexOf("NewDeaths"); | |
const indexPop = nameColumn.indexOf("Population"); | |
document.querySelectorAll('.main_table_countries_div').forEach((table) => { | |
const parentThead = table.querySelector('thead tr'); | |
const childAfter = parentThead.querySelector('th:nth-child(6)'); | |
const newChild = childAfter.cloneNode(); | |
newChild.innerText = 'New Deaths/ 1M pop'; | |
newChild.ariaLabel = 'New Deaths/ 1M pop : activate to sort column descending' | |
parentThead.insertBefore(newChild, childAfter); | |
const bodyTable = Array.from(table.querySelector('tbody').children); | |
bodyTable.forEach((row) => { | |
const dailyDeath = parseInt(row.children[indexDailyDeath].textContent.replaceAll(',','')); | |
const pop = parseInt(row.children[indexPop].textContent.replaceAll(',','')); | |
const deathsPerMillion = Math.round((dailyDeath / (pop / 1000000)) * 100 ) / 100; | |
const cellAfter = row.querySelector('td:nth-child(6)'); | |
const newCell = cellAfter.cloneNode(); | |
if (dailyDeath && !Number.isNaN(deathsPerMillion)) { | |
newCell.innerText = `+${deathsPerMillion}`; | |
} | |
row.insertBefore(newCell, cellAfter); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment