每日天气助手(修复版)
// ==UserScript==
// @name 每日天气助手(修复版)
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.0
// @description 每天9点-23:59之间运行一次,获取每日天气信息
// @author 小P
// @crontab * 9-23 once * *
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @grant GM_getValue
// @connect uapis.cn
// ==/UserScript==
/* ==UserConfig==
配置:
city:
title: 输入所在城市名称,支持市区县, 不支持乡镇!
description: 地区信息
default:
==/UserConfig== */
return new Promise((resolve, reject) => {
let region = GM_getValue("配置.city") || "北京";
GM_xmlhttpRequest({
method: "GET",
responseType: "json",
url: 'https://uapis.cn/api/weather?name=' + region,
onload: function (xhr) {
console.log(xhr.response)
if (xhr.response.code === 200) {
let province = xhr.response.province
let city = xhr.response.city
let wea = xhr.response.weather
let tem = xhr.response.temperature
let shidu = xhr.response.humidity
let win = xhr.response.wind_direction
let win_speed = xhr.response.wind_power
let time = xhr.response.reporttime
GM_notification({
title: "每日实时天气",
text: `地区:${province}${city} 天气:${wea} \n温度:${tem} 湿度:${shidu} \n风向:${win} 风力:${win_speed} \n数据更新时间:${time}`,
image: "https://img.api.aa1.cn/2022/12/18/1d5e59e3e192a.svg"
})
resolve();
} else {
GM_notification("数据获取失败,请修改城市名称,支持市区县, 不支持乡镇!");
resolve();
}
}
})
});