mirror of
https://github.com/caojiezi2003/live2d-widget.git
synced 2024-11-10 04:49:47 +00:00
Update CDN URL
This commit is contained in:
parent
5ead210907
commit
59dbbf85e1
@ -64,8 +64,8 @@ function loadWidget(config) {
|
|||||||
if (!window.ASTEROIDSPLAYERS) window.ASTEROIDSPLAYERS = [];
|
if (!window.ASTEROIDSPLAYERS) window.ASTEROIDSPLAYERS = [];
|
||||||
window.ASTEROIDSPLAYERS.push(new Asteroids());
|
window.ASTEROIDSPLAYERS.push(new Asteroids());
|
||||||
} else {
|
} else {
|
||||||
let script = document.createElement("script");
|
const script = document.createElement("script");
|
||||||
script.src = "https://cdn.jsdelivr.net/gh/GalaxyMimi/CDN/asteroids.js";
|
script.src = "https://cdn.jsdelivr.net/gh/stevenjoezhang/asteroids/asteroids.js";
|
||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -88,7 +88,7 @@ function loadWidget(config) {
|
|||||||
document.getElementById("waifu-toggle").classList.add("waifu-toggle-active");
|
document.getElementById("waifu-toggle").classList.add("waifu-toggle-active");
|
||||||
}, 3000);
|
}, 3000);
|
||||||
});
|
});
|
||||||
let devtools = () => {};
|
const devtools = () => {};
|
||||||
console.log("%c", devtools);
|
console.log("%c", devtools);
|
||||||
devtools.toString = () => {
|
devtools.toString = () => {
|
||||||
showMessage("哈哈,你打开了控制台,是想要看看我的小秘密吗?", 6000, 9);
|
showMessage("哈哈,你打开了控制台,是想要看看我的小秘密吗?", 6000, 9);
|
||||||
@ -104,7 +104,7 @@ function loadWidget(config) {
|
|||||||
(function welcomeMessage() {
|
(function welcomeMessage() {
|
||||||
let text;
|
let text;
|
||||||
if (location.pathname === "/") { // 如果是主页
|
if (location.pathname === "/") { // 如果是主页
|
||||||
let now = new Date().getHours();
|
const now = new Date().getHours();
|
||||||
if (now > 5 && now <= 7) text = "早上好!一日之计在于晨,美好的一天就要开始了。";
|
if (now > 5 && now <= 7) text = "早上好!一日之计在于晨,美好的一天就要开始了。";
|
||||||
else if (now > 7 && now <= 11) text = "上午好!工作顺利嘛,不要久坐,多起来走动走动哦!";
|
else if (now > 7 && now <= 11) text = "上午好!工作顺利嘛,不要久坐,多起来走动走动哦!";
|
||||||
else if (now > 11 && now <= 13) text = "中午了,工作了一个上午,现在是午餐时间!";
|
else if (now > 11 && now <= 13) text = "中午了,工作了一个上午,现在是午餐时间!";
|
||||||
@ -114,7 +114,7 @@ function loadWidget(config) {
|
|||||||
else if (now > 21 && now <= 23) text = ["已经这么晚了呀,早点休息吧,晚安~", "深夜时要爱护眼睛呀!"];
|
else if (now > 21 && now <= 23) text = ["已经这么晚了呀,早点休息吧,晚安~", "深夜时要爱护眼睛呀!"];
|
||||||
else text = "你是夜猫子呀?这么晚还不睡觉,明天起的来嘛?";
|
else text = "你是夜猫子呀?这么晚还不睡觉,明天起的来嘛?";
|
||||||
} else if (document.referrer !== "") {
|
} else if (document.referrer !== "") {
|
||||||
let referrer = new URL(document.referrer),
|
const referrer = new URL(document.referrer),
|
||||||
domain = referrer.hostname.split(".")[1];
|
domain = referrer.hostname.split(".")[1];
|
||||||
if (location.hostname === referrer.hostname) text = `欢迎阅读<span>「${document.title.split(" - ")[0]}」</span>`;
|
if (location.hostname === referrer.hostname) text = `欢迎阅读<span>「${document.title.split(" - ")[0]}」</span>`;
|
||||||
else if (domain === "baidu") text = `Hello!来自 百度搜索 的朋友<br>你是搜索 <span>${referrer.search.split("&wd=")[1].split("&")[0]}</span> 找到的我吗?`;
|
else if (domain === "baidu") text = `Hello!来自 百度搜索 的朋友<br>你是搜索 <span>${referrer.search.split("&wd=")[1].split("&")[0]}</span> 找到的我吗?`;
|
||||||
@ -132,7 +132,7 @@ function loadWidget(config) {
|
|||||||
fetch("https://v1.hitokoto.cn")
|
fetch("https://v1.hitokoto.cn")
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
let text = `这句一言来自 <span>「${result.from}」</span>,是 <span>${result.creator}</span> 在 hitokoto.cn 投稿的。`;
|
const text = `这句一言来自 <span>「${result.from}」</span>,是 <span>${result.creator}</span> 在 hitokoto.cn 投稿的。`;
|
||||||
showMessage(result.hitokoto, 6000, 9);
|
showMessage(result.hitokoto, 6000, 9);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
showMessage(text, 4000, 9);
|
showMessage(text, 4000, 9);
|
||||||
@ -148,7 +148,7 @@ function loadWidget(config) {
|
|||||||
}
|
}
|
||||||
text = randomSelection(text);
|
text = randomSelection(text);
|
||||||
sessionStorage.setItem("waifu-text", priority);
|
sessionStorage.setItem("waifu-text", priority);
|
||||||
let tips = document.getElementById("waifu-tips");
|
const tips = document.getElementById("waifu-tips");
|
||||||
tips.innerHTML = text;
|
tips.innerHTML = text;
|
||||||
tips.classList.add("waifu-tips-active");
|
tips.classList.add("waifu-tips-active");
|
||||||
messageTimer = setTimeout(() => {
|
messageTimer = setTimeout(() => {
|
||||||
@ -188,7 +188,7 @@ function loadWidget(config) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
result.seasons.forEach(tips => {
|
result.seasons.forEach(tips => {
|
||||||
let now = new Date(),
|
const now = new Date(),
|
||||||
after = tips.date.split("-")[0],
|
after = tips.date.split("-")[0],
|
||||||
before = tips.date.split("-")[1] || after;
|
before = tips.date.split("-")[1] || after;
|
||||||
if ((after.split("/")[0] <= now.getMonth() + 1 && now.getMonth() + 1 <= before.split("/")[0]) && (after.split("/")[1] <= now.getDate() && now.getDate() <= before.split("/")[1])) {
|
if ((after.split("/")[0] <= now.getMonth() + 1 && now.getMonth() + 1 <= before.split("/")[0]) && (after.split("/")[1] <= now.getDate() && now.getDate() <= before.split("/")[1])) {
|
||||||
@ -202,9 +202,8 @@ function loadWidget(config) {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
async function loadModelList() {
|
async function loadModelList() {
|
||||||
let response = await fetch(`${cdnPath}model_list.json`);
|
const response = await fetch(`${cdnPath}model_list.json`);
|
||||||
let result = await response.json();
|
modelList = await response.json();
|
||||||
modelList = result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadModel(modelId, modelTexturesId, message) {
|
async function loadModel(modelId, modelTexturesId, message) {
|
||||||
@ -213,7 +212,7 @@ function loadWidget(config) {
|
|||||||
showMessage(message, 4000, 10);
|
showMessage(message, 4000, 10);
|
||||||
if (useCDN) {
|
if (useCDN) {
|
||||||
if (!modelList) await loadModelList();
|
if (!modelList) await loadModelList();
|
||||||
let target = randomSelection(modelList.models[modelId]);
|
const target = randomSelection(modelList.models[modelId]);
|
||||||
loadlive2d("live2d", `${cdnPath}model/${target}/index.json`);
|
loadlive2d("live2d", `${cdnPath}model/${target}/index.json`);
|
||||||
} else {
|
} else {
|
||||||
loadlive2d("live2d", `${apiPath}get/?id=${modelId}-${modelTexturesId}`);
|
loadlive2d("live2d", `${apiPath}get/?id=${modelId}-${modelTexturesId}`);
|
||||||
@ -222,11 +221,11 @@ function loadWidget(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadRandModel() {
|
async function loadRandModel() {
|
||||||
let modelId = localStorage.getItem("modelId"),
|
const modelId = localStorage.getItem("modelId"),
|
||||||
modelTexturesId = localStorage.getItem("modelTexturesId");
|
modelTexturesId = localStorage.getItem("modelTexturesId");
|
||||||
if (useCDN) {
|
if (useCDN) {
|
||||||
if (!modelList) await loadModelList();
|
if (!modelList) await loadModelList();
|
||||||
let target = randomSelection(modelList.models[modelId]);
|
const target = randomSelection(modelList.models[modelId]);
|
||||||
loadlive2d("live2d", `${cdnPath}model/${target}/index.json`);
|
loadlive2d("live2d", `${cdnPath}model/${target}/index.json`);
|
||||||
showMessage("我的新衣服好看嘛?", 4000, 10);
|
showMessage("我的新衣服好看嘛?", 4000, 10);
|
||||||
} else {
|
} else {
|
||||||
@ -244,7 +243,7 @@ function loadWidget(config) {
|
|||||||
let modelId = localStorage.getItem("modelId");
|
let modelId = localStorage.getItem("modelId");
|
||||||
if (useCDN) {
|
if (useCDN) {
|
||||||
if (!modelList) await loadModelList();
|
if (!modelList) await loadModelList();
|
||||||
let index = (++modelId >= modelList.models.length) ? 0 : modelId;
|
const index = (++modelId >= modelList.models.length) ? 0 : modelId;
|
||||||
loadModel(index, 0, modelList.messages[index]);
|
loadModel(index, 0, modelList.messages[index]);
|
||||||
} else {
|
} else {
|
||||||
fetch(`${apiPath}switch/?id=${modelId}`)
|
fetch(`${apiPath}switch/?id=${modelId}`)
|
||||||
@ -266,7 +265,7 @@ function initWidget(config, apiPath) {
|
|||||||
document.body.insertAdjacentHTML("beforeend", `<div id="waifu-toggle">
|
document.body.insertAdjacentHTML("beforeend", `<div id="waifu-toggle">
|
||||||
<span>看板娘</span>
|
<span>看板娘</span>
|
||||||
</div>`);
|
</div>`);
|
||||||
let toggle = document.getElementById("waifu-toggle");
|
const toggle = document.getElementById("waifu-toggle");
|
||||||
toggle.addEventListener("click", () => {
|
toggle.addEventListener("click", () => {
|
||||||
toggle.classList.remove("waifu-toggle-active");
|
toggle.classList.remove("waifu-toggle-active");
|
||||||
if (toggle.getAttribute("first-time")) {
|
if (toggle.getAttribute("first-time")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user