Script: Google Weather

Google Weather

I wanted to give Google Weather website a facelift and make it resemble the way it looks on mobile. Also, used some simple GM scripts to make some minor improvements such as highlighting Feels Like temperature, adding a reload button etc.

 

screenshot of the website

 

/* ==UserStyle==
@name www.google.com/search
@namespace github.com/openstyles/stylus
@version 1.0.0
@description A new userstyle
@author Me
==/UserStyle== */
@-moz-document url-prefix("https://www.google.com/search?client=firefox-b-d&q=montreal+weather") {
/* weather box */
#rso.dURPMd div.ULSxyf {
background: linear-gradient(to top, #d6e9f4 0%, #e2ebf0 100%);
padding: 30px;
border-radius: 15px;
box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
margin: 0 auto;
width: 34%;
}
/* weather box parent: fixed, capped at 1000px, centered */
#rso {
position: fixed;
left: 0;
right: 0;
margin: 0 auto;
width: 100vw;
max-width: 1000px;
box-sizing: border-box;
}
.rso > .MjjYud:nth-child(n + 3) {
display: none;
}
#botstuff,
#sfooter,
#searchform,
[data-st-tgt="fb"],
[data-attrid="title"],
#qslc,
.uQ249e,
.h9sJw,
.eakexd,
.r2VLS,
.Y3kFwd,
.YfftMc {
display: none !important;
}
#sfcnt {
padding-top: 35px;
}
/* location name */
#oFNiHe {
padding-left: 100px;
}
#taw {
display: none;
}
.lP6sWe {
display: flex;
align-items: center;
gap: 38px;
margin-bottom: 35px;
}
.lP6sWe > .sjBi9c {
order: -1;
}
.yMplof > span {
color: #ccc;
}
.gVkeMe > .tNxQIb {
width: 190px;
padding: 3px 0px;
font-size: 0.8rem;
border-bottom: 1px solid #7a7a7a;
}
.RyIFgf {
overflow-x: hidden !important;
}
.TEk95b > .sjVJQd {
color: #8e8e8e;
font-weight: normal;
}
.HG5ZQb {
display: flex;
justify-content: start;
}
header {
width: 1000px !important;
margin: 0 auto;
}
body {
color: #fff !important;
background: transparent !important;
}
html {
/** background-image: url('https://raw.githubusercontent.com/dvnlgls/public/refs/heads/main/starry.jpg') !important; **/
background-image: url('https://assets.aboutamazon.com/66/71/1d75dd1d47ae8204b0bffb30cb66/007-2026-5.jpg') !important;
background-color: #131518 !important;
background-size: auto !important;
background-repeat: no-repeat !important;
background-position: center !important;
background-attachment: fixed !important;
}
}
// ==UserScript==
// @name Google Weather - swap temps
// @version 1
// @match https://www.google.com/*
// @grant none
// ==/UserScript==
(() => {
const cardSelector = 'div.gVkeMe[role="group"][aria-label^="Now,"]';
const temperatureSelector = '.Li0Yl.yMplof';
const feelsLikeSelector = '.ApHyTb';
function colorFor(value) {
if (value <= 0) return '#eb3b3b';
if (value < 10) return '#f0b11a';
return '#539dff';
}
function updateCard(card) {
const nowMatch = card.getAttribute('aria-label')?.match(/^Now,\s*(.+?)(?:,\s|$)/);
const feelsElement = card.querySelector(feelsLikeSelector);
const feelsMatch = feelsElement?.textContent
?.trim()
.match(/^Feels like\s+(.+)$/i);
const temperature = card.querySelector(temperatureSelector);
if (!nowMatch || !feelsMatch || !temperature) return;
const now = nowMatch[1];
const feelsLike = feelsMatch[1];
const valueKey = `${now}|${feelsLike}`;
if (temperature.dataset.feelsNowValue === valueKey) return;
const feelsNum = parseFloat(feelsLike.replace('−', '-')); // handles Unicode minus
const originalNow = document.createElement('span');
originalNow.textContent = feelsLike;
if (!Number.isNaN(feelsNum)) {
originalNow.style.color = colorFor(feelsNum);
}
const smallerNow = document.createElement('span');
smallerNow.textContent = ` (${now})`;
smallerNow.style.cssText = 'font-size:0.4em; font-weight:normal;';
temperature.replaceChildren(originalNow, smallerNow);
temperature.dataset.feelsNowValue = valueKey;
const label = card.querySelector('.tNxQIb');
if (label) label.textContent = 'Feels like';
if (feelsElement) feelsElement.remove();
}
function updateCards() {
document.querySelectorAll(cardSelector).forEach(updateCard);
}
let scheduled = false;
new MutationObserver(() => {
if (scheduled) return;
scheduled = true;
requestAnimationFrame(() => {
scheduled = false;
updateCards();
});
}).observe(document.documentElement, {
subtree: true,
childList: true,
characterData: true,
attributes: true,
attributeFilter: ['aria-label'],
});
updateCards();
})();