Last active
February 8, 2021 10:35
-
-
Save GedoonS/07b0a382fd8d7a874f398a7de6d30973 to your computer and use it in GitHub Desktop.
Converts Finnish Covid 19 vaccination tracking numbers to percentages and progressbars
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
| // ==UserScript== | |
| // @name episeuranta-percentagify | |
| // @description Converts Finnish Covid 19 vaccination tracking numbers to percentages and progressbars | |
| // @namespace https://github.com/gedoons/ | |
| // @downloadURL https://gist.githubusercontent.com/GedoonS/07b0a382fd8d7a874f398a7de6d30973/raw/gistfile1.txt | |
| // @updateURL https://gist.githubusercontent.com/GedoonS/07b0a382fd8d7a874f398a7de6d30973/raw/gistfile1.txt | |
| // @version 0.1 | |
| // @author GedoonS | |
| // @match https://www.thl.fi/episeuranta/rokotukset/koronarokotusten_edistyminen.html | |
| // @grant none | |
| // @run-at document-idle | |
| // @noframes | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| const shp_populations = { | |
| 'Ahvenanmaa':29789, | |
| 'Etelä-Karjalan SHP':128756, | |
| 'Etelä-Pohjanmaan SHP':194316, | |
| 'Etelä-Savon SHP':100226, | |
| 'Helsingin ja Uudenmaan SHP':1667203, | |
| 'Itä-Savon SHP':41060, | |
| 'Kainuun SHP':73061, | |
| 'Kanta-Hämeen SHP':171364, | |
| 'Keski-Pohjanmaan SHP':77689, | |
| 'Keski-Suomen SHP':252676, | |
| 'Kymenlaakson SHP':166623, | |
| 'Lapin SHP':117350, | |
| 'Länsi-Pohjan SHP':61172, | |
| 'Pirkanmaan SHP':535044, | |
| 'Pohjois-Karjalan SHP':165569, | |
| 'Pohjois-Pohjanmaan SHP':409418, | |
| 'Pohjois-Savon SHP':245602, | |
| 'Päijät-Hämeen SHP':211215, | |
| 'Satakunnan SHP':218624, | |
| 'Vaasan SHP':169684, | |
| 'Varsinais-Suomen SHP':481478, | |
| }; | |
| const head = document.querySelectorAll('#covid-19-rokoteannokset-sairaanhoitopiireittäin table thead th'); | |
| head.forEach( col => { | |
| col.style.width = '25%'; | |
| }) | |
| document.querySelector('.main-container').style.maxWidth = 'unset'; | |
| const rows = document.querySelectorAll('#covid-19-rokoteannokset-sairaanhoitopiireittäin table tbody tr'); | |
| [2,3].map( col => { | |
| rows.forEach(row => { | |
| const name = row.querySelector('td').innerHTML.trim() | |
| if(!shp_populations[name]) row.style.display='none' | |
| const td = row.querySelector(`td:nth-child(${col})`); | |
| const first = parseInt(td.innerHTML.trim()) | |
| const percentage = (first/ shp_populations[name]*100).toFixed(1) | |
| td.innerHTML = percentage + ' % ';// + '|'.repeat(percentage*2) | |
| let color = '#000000'; | |
| switch (true){ | |
| case percentage > 80: color = '#69B34C'; break; | |
| case percentage > 60: color = '#ACB334'; break; | |
| case percentage > 40: color = '#FAB733'; break; | |
| case percentage > 20: color = '#FF8E15'; break; | |
| case percentage > 10: color = '#FF4E11'; break; | |
| case percentage > 0: color = '#FF0D0D'; break; | |
| } | |
| td.style.background=`linear-gradient(to right, #fff, ${color} 0%, ${color} ${percentage}%, #fff ${percentage}%, #eee 100%)` | |
| }) | |
| }) | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment