每日天气助手
// ==UserScript==
// @name 每日天气助手
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.0
// @description 每天9点-23:59之间运行一次,获取每日天气信息
// @author 张仨
// @crontab * 9-23 once * *
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @grant GM_getValue
// @connect api.iyk0.com
// ==/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://api.iyk0.com/tq/?city=' + region,
onload: function (xhr) {
console.log(xhr.response)
if (xhr.response.code === 200) {
let city = xhr.response.city
let wea = xhr.response.wea
let tem_day = xhr.response.tem_day
let tem_night = xhr.response.tem_night
let tem = xhr.response.tem
let win = xhr.response.win
let win_meter = xhr.response.win_meter
let win_speed = xhr.response.win_speed
let air = xhr.response.air
GM_notification({
title: "每日实时天气",
text: `城市:${city} 天气:${wea} \n实时温度:${tem} 高温:${tem_day} 低温:${tem_night} \n风向:${win} 风速:${win_meter} 风力:${win_speed} \n空气质量:${air}`,
image: "https://gitee.com/MarHangover/images/raw/master/image/logo.webp"
})
resolve();
} else {
GM_notification("数据获取失败,请修改城市名称,支持市区县, 不支持乡镇!");
resolve();
}
}
})
});