Skip to content

Instantly share code, notes, and snippets.

@DanAtkinson
Last active April 9, 2020 19:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanAtkinson/dc208620b9b11d7949efc7ff6eebb39c to your computer and use it in GitHub Desktop.
Save DanAtkinson/dc208620b9b11d7949efc7ff6eebb39c to your computer and use it in GitHub Desktop.
worldometer Covid-19 additions of mortality and highlighting of European nations
// ==UserScript==
// @name COVID-19 Mortality Meter
// @namespace http://tampermonkey.net/
// @version 1.1
// @description try to take over the world!
// @author You
// @match https://www.worldometers.info/coronavirus/
// @grant none
// @require https://code.jquery.com/jquery-3.4.1.min.js#sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=
// ==/UserScript==
jQuery(function() {
'use strict';
let tablesList = ['#main_table_countries_today', '#main_table_countries_yesterday'];
let europeanCountries = ['albania', 'andorra', 'austria', 'belarus', 'belgium', 'bosnia and herzegovina', 'bulgaria', 'channel islands', 'croatia', 'cyprus', 'czechia', 'denmark', 'estonia', 'faeroe islands', 'finland', 'france', 'germany', 'gibraltar', 'greece', 'hungary', 'iceland', 'ireland', 'isle of man', 'italy', 'latvia', 'liechtenstein', 'lithuania', 'luxembourg', 'malta', 'moldova', 'monaco', 'netherlands', 'north macedonia', 'norway', 'poland', 'portugal', 'romania', 'san marino', 'serbia', 'slovakia', 'slovenia', 'spain', 'sweden', 'switzerland', 'uk', 'ukraine'];
for (var i = 0; i < tablesList.length; i++) {
if (!$(tablesList[i]).length) {
continue;
}
//Add in mortality column.
$(tablesList[i] + ' thead tr th').eq(4).after('<th class="sorting" tabindex="0" rowspan="1" colspan="1" style="width: 78px;" width="30">Morality<br>Rate</th>');
$(tablesList[i] + ' thead tr th').eq(8).after('<th class="sorting" tabindex="0" rowspan="1" colspan="1" style="width: 78px;" width="30">Population</th>');
let countryName, totalCases, totalDeaths, totalCasesPerMillion, mortalityRate, population, countryCount, $countryTable;
//Countries
$countryTable = $(tablesList[i] + ' tbody:eq(0) tr');
countryCount = $countryTable.length - 1;
$countryTable.each(function(i) {
countryName = $(this).find('td:eq(0)').text();
totalCases = Number.parseFloat($(this).find('td:eq(1)').text().replace(/,/g, ''), 10);
totalDeaths = Number.parseFloat($(this).find('td:eq(3)').text().replace(/,/g, '') | '0', 10);
totalCasesPerMillion = Number.parseFloat(($(this).find('td:eq(8)').text() || '0').replace(/,/g, ''), 10);
mortalityRate = ((100 / totalCases) * totalDeaths).toFixed(2);
population = (Math.round(Number.parseFloat((totalCases / totalCasesPerMillion) * 1000000, 10) / 1000000) * 1000000).toLocaleString('en');
if (europeanCountries.includes(countryName.toLowerCase())) {
$(this).attr('style','background-color:#67E2E85C; color:#000;');
}
if (!$(this).find('td:eq(0) a').length) {
$(this).find('td:eq(0)').html('<a class="mt_a" href="country/' + countryName.toLowerCase() + '/">' + countryName + '</a>');
}
$(this).find('td:eq(0)').prepend(i + ': ');
$(this).find('td:eq(4)').after('<td style="font-weight: bold; text-align:right">' + mortalityRate + '%</td>');
$(this).find('td:eq(8)').after('<td style="font-weight: bold; text-align:right">' + population + '</td>');
});
//World
$(tablesList[i] + ' tbody:eq(1) tr').each(function() {
totalCases = Number.parseFloat($(this).find('td:eq(1)').text().replace(/,/g, ''), 10);
totalDeaths = Number.parseFloat($(this).find('td:eq(3)').text().replace(/,/g, '') | '0', 10);
totalCasesPerMillion = Number.parseFloat(($(this).find('td:eq(8)').text() || '0').replace(/,/g, ''), 10);
mortalityRate = ((100 / totalCases) * totalDeaths).toFixed(2);
population = (Math.round(Number.parseFloat((totalCases / totalCasesPerMillion) * 1000000, 10) / 1000000) * 1000000).toLocaleString('en');
$(this).find('td:eq(0)').html('<strong>' + countryCount + ' Nations</strong>');
$(this).find('td:eq(4)').after('<td style="font-weight: bold; text-align:right">' + mortalityRate + '%</td>');
$(this).attr('style','background-color:#B594FF; color:#000;');
$(this).find('td:eq(8)').after('<td style="font-weight: bold; text-align:right">' + population + '</td>');
});
$(tablesList[i] + ' tbody:eq(0) tr:eq(0)').before($(tablesList[i] + ' tbody:eq(1) tr').parent().clone().html());
$(tablesList[i] + ' tbody:eq(0) tr:eq(1)').remove();
}
}($.noConflict()));
@smadep
Copy link

smadep commented Apr 8, 2020

thanks for that nice user script in these unpleasant days ...
small issue ... the population totals are not working (for me)

@DanAtkinson
Copy link
Author

DanAtkinson commented Apr 8, 2020

Hi @smadep, I've updated the script based on my current version.

Population is (totalCases / totalCasesPerMillion) * 1000000) so the number can vary considerably each day. It's not required but is useful as a guide, and shouldn't be considered accurate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment