home/js/set.js
2022-07-27 10:53:34 +08:00

159 lines
5.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
作者: imsyy
主页https://www.imsyy.top/
GitHubhttps://github.com/imsyy/home
版权所有,请勿删除
*/
/* 自定义配置 */
/* 尚未完善 */
$(function () {
var url = "../setting.json"
$.getJSON(
url,
function (data) {
/* 页头数据 */
$('title').text(data.title);
$('#loading-title').html(data.title);
$("meta[name='description']").attr('content', data.description);
$("meta[name='keywords']").attr('content', data.keywords);
$("meta[name='author']").attr('content', data.author);
/* 基础信息 */
$("#logo-img").attr("src", data.logo_img);
$('#logo-text-1').html(data.logo_text_1);
$('#logo-text-2').html("." + data.logo_text_2);
$('#logo-title-other').html(data.logo_text_1);
$('#logo-title-other-small').html("." + data.logo_text_2);
$('#logo-text-small').html(data.logo_text_1 + "." + data.logo_text_2);
/* 社交链接 */
$('#github').attr('href', "https://github.com/" + data.github);
$('#qq').attr('href', "https://wpa.qq.com/msgrd?v=3&uin=" + data.qq + "&site=qq&menu=yes");
$('#email').attr('href', "mailto:" + data.email);
$('#bilibili').attr('href', "https://space.bilibili.com/" + data.bilibili);
$('#telegram').attr('href', "https://t.me/" + data.telegram);
/* 快捷链接 */
$('#link-url-1').attr('href', data.link_1[0]);
$('#link-icon-1').attr('class', data.link_1[1]);
$('#link-name-1').html(data.link_1[2]);
$('#link-url-2').attr('href', data.link_2[0]);
$('#link-icon-2').attr('class', data.link_2[1]);
$('#link-name-2').html(data.link_2[2]);
$('#link-url-3').attr('href', data.link_3[0]);
$('#link-icon-3').attr('class', data.link_3[1]);
$('#link-name-3').html(data.link_3[2]);
$('#link-url-4').attr('href', data.link_4[0]);
$('#link-icon-4').attr('class', data.link_4[1]);
$('#link-name-4').html(data.link_4[2]);
$('#link-url-5').attr('href', data.link_5[0]);
$('#link-icon-5').attr('class', data.link_5[1]);
$('#link-name-5').html(data.link_5[2]);
$('#link-url-6').attr('href', data.link_6[0]);
$('#link-icon-6').attr('class', data.link_6[1]);
$('#link-name-6').html(data.link_6[2]);
//页脚版权
$('#power-text').html(data.Copyright_text);
$('#beian').html("& " + data.beian);
}
)
});
// 背景图片 Cookies
function setBgImg(bg_img) {
if (bg_img) {
Cookies.set('bg_img', bg_img, {
expires: 36500
});
return true;
}
return false;
};
// 获取背景图片 Cookies
function getBgImg() {
var bg_img_local = Cookies.get('bg_img');
if (bg_img_local && bg_img_local !== "{}") {
return JSON.parse(bg_img_local);
} else {
setBgImg(bg_img_preinstall);
return bg_img_preinstall;
}
}
var bg_img_preinstall = {
"type": "1", // 1:默认背景 2:每日一图 3:随机风景 4:随机动漫
"2": "https://api.dujin.org/bing/1920.php", // 每日一图
"3": "https://api.ixiaowai.cn/gqapi/gqapi.php", // 随机风景
"4": "https://api.ixiaowai.cn/api/api.php" // 随机动漫
};
// 更改背景图片
function setBgImgInit() {
var bg_img = getBgImg();
$("input[name='wallpaper-type'][value=" + bg_img["type"] + "]").click();
switch (bg_img["type"]) {
case "1":
$('#bg').attr('src', `./img/background${1 + ~~(Math.random() * 10)}.webp`) //随机默认壁纸
break;
case "2":
$('#bg').attr('src', bg_img_preinstall[2]); //必应每日
break;
case "3":
$('#bg').attr('src', bg_img_preinstall[3]); //随机风景
break;
case "4":
$('#bg').attr('src', bg_img_preinstall[4]); //随机动漫
break;
}
};
$(document).ready(function () {
// 壁纸数据加载
setBgImgInit();
// 设置背景图片
$("#wallpaper").on("click", ".set-wallpaper", function () {
var type = $(this).val();
var bg_img = getBgImg();
bg_img["type"] = type;
if (type === "1") {
setBgImg(bg_img);
$('#bg').attr('src', `./img/background${1 + ~~(Math.random() * 10)}.webp`) //随机默认壁纸
iziToast.show({
icon: "fa-solid fa-image",
timeout: 2500,
message: '壁纸设置成功',
});
};
if (type === "2") {
setBgImg(bg_img);
$('#bg').attr('src', bg_img_preinstall[2]); //必应每日
iziToast.show({
icon: "fa-solid fa-image",
timeout: 2500,
message: '壁纸设置成功',
});
};
if (type === "3") {
setBgImg(bg_img);
$('#bg').attr('src', bg_img_preinstall[3]); //随机风景
iziToast.show({
icon: "fa-solid fa-image",
timeout: 2500,
message: '壁纸设置成功',
});
};
if (type === "4") {
setBgImg(bg_img);
$('#bg').attr('src', bg_img_preinstall[4]); //随机动漫
iziToast.show({
icon: "fa-solid fa-image",
timeout: 2500,
message: '壁纸设置成功',
});
};
});
});