auto一键复制html,auto.html

 
天气加载中...

// 深浅色模式标示

var lightMode = true

// 创建XMLHttpRequest对象

function createXHR() {

var xhr = null;

if (window.XMLHttpRequest) {

xhr = new XMLHttpRequest();

} else if (window.ActiveXObject) {

xhr = new ActiveXObject("Microsoft.XMLHTTP");

}

return xhr;

}

// 一言模块

function hitokoto() {

var xhr = createXHR();

xhr.open('GET', 'https://v1.hitokoto.cn?encode=json&charset=utf-8', true);

xhr.onreadystatechange = function() {

if (this.readyState == 4) {

var data = JSON.parse(this.responseText)

document.getElementById('hitokoto').innerHTML = data.hitokoto

document.getElementById('from').innerHTML = data.from_who ? "「" + data.from + " " + data.from_who + "」" : "「" + data.from + "」"

}

}

xhr.send(null);

}

hitokoto()

setInterval("hitokoto()", 60 * 1000 * 60)

// 时钟模块

function clock() {

var date = new Date()

var utc8DiffMinutes = date.getTimezoneOffset() + 480

date.setMinutes(date.getMinutes() + utc8DiffMinutes)

var hour = date.getHours()

// 20点后6点前启用深色模式

if (hour > 19 || hour < 6) {

if (lightMode) {

document.getElementsByClassName('page')[0].style.color = '#ffffff'

document.getElementsByClassName('page')[0].style.backgroundColor = '#000000'

lightMode = false

}

} else {

if (!lightMode) {

document.getElementsByClassName('page')[0].style.color = '#000000'

document.getElementsByClassName('page')[0].style.backgroundColor = '#ffffff'

lightMode = true

}

}

var apm = '上
午'

if (hour > 12) {

apm = '下
午'

hour -= 12

}

var timeString = hour + ':' + ('0' + date.getMinutes()).slice(-2)

var dateString = (date.getMonth() + 1) + '月' + date.getDate() + '日'

var weekList = ['日', '一', '二', '三', '四', '五', '六']

var weekString = '星期' + weekList[date.getDay()]

document.getElementById('apm').innerHTML = apm

document.getElementById("time").innerHTML = timeString

document.getElementById("date").innerHTML = dateString + " " + weekString

}

clock()

setInterval("clock()", 60 * 1000)

// 天气模块

// 固定9种类型: xue、lei、shachen、wu、bingbao、yun、yu、yin、qing

var weaImgs = {

xue: ['', ''],

lei: ['', ''],

shachen: ['', ''],

wu: ['', ''],

bingbao: ['', ''],

yun: ['', ''],

duoyun: ['', ''],

yu: ['', ''],

yin: ['', ''],

qing: ['', ''],

weizhi: ['', '']

}

function weather() {

console.log('weather update')

var xhr = createXHR();

xhr.open('GET', 'https://v2.alapi.cn/api/tianqi?token=pBsICqbRV2eVtGiI&ip=' + returnCitySN.cip, true);

// xhr.open('GET', 'https://tianqiapi.com/free/day?appid=48353766&appsecret=VjZ4oxd5', true);

// xhr.open('GET','https://tianqiapi.com/free/day?appid=48373524&appsecret=5iHwLsS8',true);

xhr.onreadystatechange = function() {

if (this.readyState == 4) {

var data = JSON.parse(this.responseText)

if (data.code === 200) {

weather_data = data.data

// 获取天气图标信息

var imgs = weaImgs[weather_data.weather_code]

var img = imgs[0]

var date = new Date()

var utc8DiffMinutes = date.getTimezoneOffset() + 480

date.setMinutes(date.getMinutes() + utc8DiffMinutes)

var hour = date.getHours()

// nightHour后天气使用夜间天气图标

if (hour > 19 || hour < 6) {

img = imgs[1]

}

var weaImg = '' + img + '' + '

天气:' + weather_data.weather + '
';

var weaTemp = '

' + weather_data.temp + '
' +

'

当前气温
';

var highTemp = weather_data.max_temp // 日间气温/最高气温

var lowTemp = weather_data.min_temp // 夜间气温/最低气温

var air = weather_data.aqi.air

air = air ? air : '未知'

var airLevel = weather_data.aqi.air_level // 空气质量,air_level为alapi独有

airLevel = airLevel && air ? airLevel : ''

var updateTime = weather_data.update_time.split(' ') // 更新时间,alapi格式为'年-月-日 时-分-秒',tianqiapi格式为'时-分'

updateTime = updateTime[updateTime.length - 1]

var weaInfo = '

最高/低气温:' + highTemp + '/' + lowTemp + '℃
' +

'

湿度:' + weather_data.humidity + '
' +

'

空气质量:' + air + airLevel + '
' +

'

风向:' + weather_data.wind + '
' +

'

风速:' + weather_data.wind_speed + ' ' + weather_data.wind_scale + '
' +

'

更新时间:' + updateTime + '
';

document.getElementById('weaTitle').innerHTML = weather_data.city + '当前天气'

document.getElementById('weaImg').innerHTML = weaImg

document.getElementById('weaTemp').innerHTML = weaTemp

document.getElementById('weaInfo').innerHTML = weaInfo

} else {

console.error('天气数据获取失败: ' + weather_data.msg)

document.getElementById("weaTitle").innerHTML = '数据获取失败,请稍后再试~';

}

}

}

xhr.send(null);

}

weather();

setInterval("weather()", 60 * 1000 * 20);

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值