GisMeteo Humidex

Баллы Humidex для Gismeteo

目前为 2020-06-15 提交的版本。查看 最新版本

// ==UserScript==
// @name			GisMeteo Humidex
// @version			2020.06.15
// @description		Баллы Humidex для Gismeteo
// @include			http*://*gismeteo.ru/*
// @exclude			http*://*gismeteo.ru/*/10-days/
// @exclude			http*://*gismeteo.ru/*/2-weeks/
// @icon			https://www.google.com/s2/favicons?domain=gismeteo.ru
// @author			Rainbow-Spike
// @namespace		https://greasyfork.org/users/7568
// @homepage		https://greasyfork.org/ru/users/7568-dr-yukon
// @grant			none
// ==/UserScript==

var temps = document.querySelectorAll ( '.w_temperature .value span:nth-of-type(1)' ),
	hums = document.querySelectorAll ( 'div[data-widget-id = humidity] .w-humidity' ),
	i, temp, hum, humidex, color, text;

function paint ( h ) {
	switch ( true ) {
		case h < 0:
			color = 'violet';
			text = 'Нет дискомфорта';
			break;
		case h < 10:
			color = 'blue';
			text = 'Нет дискомфорта';
			break;
		case h < 20:
			color = 'darkturquoise';
			text = 'Нет дискомфорта';
			break;
		case h < 30:
			color = 'green';
			text = 'Нет дискомфорта';
			break;
		case h <= 40:
			color = 'gold';
			text = 'Некоторый дискомфорт';
			break;
		case h <= 45:
			color = 'orange';
			text = 'Большой дискомфорт; избегать усилий';
			break;
		case h < 54:
			color = 'red';
			text = 'Опасно; возможен тепловой удар';
			break;
		case h >= 54:
			color = 'darkred';
			text = 'Опасно; возможен тепловой удар';
			break;
		default:
			color = 'black';
			text = '-';
			break;
	}
}

for ( i = 0; i < temps.length; i++ ) {
	temp = temps [ i ].innerHTML.replace ( '+', '' ) * 1;
	hum = hums [ i ].innerHTML * 1;
	humidex = Math.round ( temp + 5 / 9 * ( ( 6.112 * Math.pow ( 10, ( 7.5 * temp / ( 237.7 + temp ) ) ) * hum / 100 ) - 10 ) );
	paint ( humidex );
	temps [ i ].innerHTML = temps [ i ].innerHTML + '<div style = "font-weight: bold; font-size: 90%; margin: 7px 0 0 12px; color: ' + color + '" title = "' + text + '">' + humidex + '</div>';
}