// ==UserScript== // @name LztWeatherApi // @namespace http://tampermonkey.net/ // @version 0.1 // @description Отображение погоды на главной странице форума // @author vuchaev2015 // @match https://zelenka.guru/ // @icon https://www.google.com/s2/favicons?sz=64&domain=zelenka.guru // @grant none // @downloadURL none // ==/UserScript== const apiKey = "3a068cfd15014c20b75173452232307"; let city = ""; fetch('https://ipwho.is/') .then(response => response.json()) .then(data => { city = data.city.replace(/'/g, ""); // Get weather data for city const url = `https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${city}`; fetch(url) .then(response => response.json()) .then(data => { let text = `Город: ${city}
`; const h = data.current; if ('temp_c' in h) { text += `Температура: ${h['temp_c']} °C
`; } if ('feelslike_c' in h) { text += `Ощущается как: ${h['feelslike_c']} °C
`; } if ('humidity' in h) { text += `Влажность: ${h['humidity']} %
`; } if ('pressure_mb' in h) { text += `Давление: ${h['pressure_mb']} мб
`; } if ('wind_kph' in h) { text += `Скорость ветра: ${h['wind_kph']} км/ч
`; } if ('vis_km' in h) { text += `Видимость: ${h['vis_km']} км
`; } console.log(text); const weatherContainer = document.querySelector("#content > div > div > aside > div > div:nth-child(2)"); weatherContainer.innerHTML = `
Погода
${text}
Получить Json
`; }); });