2022-06-20 13:20:45 +00:00
|
|
|
|
/*
|
|
|
|
|
作者: imsyy
|
|
|
|
|
主页:https://www.imsyy.top/
|
|
|
|
|
GitHub:https://github.com/imsyy/home
|
|
|
|
|
版权所有,请勿删除
|
|
|
|
|
*/
|
|
|
|
|
|
2022-04-14 08:47:10 +00:00
|
|
|
|
// 背景图片 Cookies
|
|
|
|
|
function setBgImg(bg_img) {
|
|
|
|
|
if (bg_img) {
|
|
|
|
|
Cookies.set('bg_img', bg_img, {
|
|
|
|
|
expires: 36500
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2022-06-28 09:27:23 +00:00
|
|
|
|
};
|
2022-04-14 08:47:10 +00:00
|
|
|
|
|
|
|
|
|
// 获取背景图片 Cookies
|
|
|
|
|
function getBgImg() {
|
2022-08-02 02:25:29 +00:00
|
|
|
|
let bg_img_local = Cookies.get('bg_img');
|
2022-04-14 08:47:10 +00:00
|
|
|
|
if (bg_img_local && bg_img_local !== "{}") {
|
|
|
|
|
return JSON.parse(bg_img_local);
|
|
|
|
|
} else {
|
|
|
|
|
setBgImg(bg_img_preinstall);
|
|
|
|
|
return bg_img_preinstall;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-02 02:25:29 +00:00
|
|
|
|
let bg_img_preinstall = {
|
2022-04-14 08:47:10 +00:00
|
|
|
|
"type": "1", // 1:默认背景 2:每日一图 3:随机风景 4:随机动漫
|
2022-07-10 15:17:41 +00:00
|
|
|
|
"2": "https://api.dujin.org/bing/1920.php", // 每日一图
|
|
|
|
|
"3": "https://api.ixiaowai.cn/gqapi/gqapi.php", // 随机风景
|
|
|
|
|
"4": "https://api.ixiaowai.cn/api/api.php" // 随机动漫
|
2022-04-14 08:47:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 更改背景图片
|
|
|
|
|
function setBgImgInit() {
|
2022-08-02 02:25:29 +00:00
|
|
|
|
let bg_img = getBgImg();
|
2022-04-14 08:47:10 +00:00
|
|
|
|
$("input[name='wallpaper-type'][value=" + bg_img["type"] + "]").click();
|
|
|
|
|
|
|
|
|
|
switch (bg_img["type"]) {
|
|
|
|
|
case "1":
|
2022-07-10 15:17:41 +00:00
|
|
|
|
$('#bg').attr('src', `./img/background${1 + ~~(Math.random() * 10)}.webp`) //随机默认壁纸
|
2022-04-14 08:47:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case "2":
|
2022-07-10 15:17:41 +00:00
|
|
|
|
$('#bg').attr('src', bg_img_preinstall[2]); //必应每日
|
2022-04-14 08:47:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case "3":
|
2022-07-10 15:17:41 +00:00
|
|
|
|
$('#bg').attr('src', bg_img_preinstall[3]); //随机风景
|
2022-04-14 08:47:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case "4":
|
2022-07-10 15:17:41 +00:00
|
|
|
|
$('#bg').attr('src', bg_img_preinstall[4]); //随机动漫
|
2022-04-14 08:47:10 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-06-28 09:27:23 +00:00
|
|
|
|
};
|
2022-04-14 08:47:10 +00:00
|
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
// 壁纸数据加载
|
|
|
|
|
setBgImgInit();
|
|
|
|
|
// 设置背景图片
|
|
|
|
|
$("#wallpaper").on("click", ".set-wallpaper", function () {
|
2022-08-02 02:25:29 +00:00
|
|
|
|
let type = $(this).val();
|
|
|
|
|
let bg_img = getBgImg();
|
2022-04-14 08:47:10 +00:00
|
|
|
|
bg_img["type"] = type;
|
2022-08-02 02:25:29 +00:00
|
|
|
|
iziToast.show({
|
|
|
|
|
icon: "fa-solid fa-image",
|
|
|
|
|
timeout: 2500,
|
|
|
|
|
message: '壁纸设置成功,刷新后生效',
|
|
|
|
|
});
|
|
|
|
|
setBgImg(bg_img);
|
2022-04-14 08:47:10 +00:00
|
|
|
|
});
|
|
|
|
|
});
|