Update autoload.js

This commit is contained in:
nicocatxzc 2024-07-26 20:38:45 +08:00 committed by GitHub
parent eaaf4a9e5f
commit 269dde43a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,10 +24,20 @@ function loadExternalResource(url, type) {
}); });
} }
//判断移动端用户方法
function isMobile() {
var userAgent = navigator.userAgent || window.opera;
if (/android/i.test(userAgent) || /iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
return true;
}
}
// 加载 waifu.css live2d.min.js waifu-tips.js // 加载 waifu.css live2d.min.js waifu-tips.js
if (screen.width >= 768) { if (isMobile()) {
//移动端用户
Promise.all([ Promise.all([
loadExternalResource(live2d_path + "waifu.css", "css"), loadExternalResource(live2d_path + "waifu-mobie.css", "css"),
loadExternalResource(live2d_path + "live2d.min.js", "js"), loadExternalResource(live2d_path + "live2d.min.js", "js"),
loadExternalResource(live2d_path + "waifu-tips.js", "js") loadExternalResource(live2d_path + "waifu-tips.js", "js")
]).then(() => { ]).then(() => {
@ -35,20 +45,17 @@ if (screen.width >= 768) {
initWidget({ initWidget({
waifuPath: live2d_path + "waifu-tips.json", waifuPath: live2d_path + "waifu-tips.json",
//apiPath: "https://live2d.fghrsh.net/api/", //apiPath: "https://live2d.fghrsh.net/api/",
cdnPath: "https://fastly.jsdelivr.net/gh/fghrsh/live2d_api/", cdnPath: "/live2djs/",
tools: ["hitokoto", "asteroids", "switch-model", "switch-texture", "photo", "info", "quit"] tools: ["hitokoto", "asteroids", "switch-model", "switch-texture", "photo", "info", "quit"]
}); });
}); });
} } else {
//pc端用户
// 加载 waifu.css live2d.min.js waifu-tips-.js适配移动端
if (screen.width < 768) {
Promise.all([ Promise.all([
loadExternalResource(live2d_path + "waifu-mobie.css", "css"), loadExternalResource(live2d_path + "waifu.css", "css"),
loadExternalResource(live2d_path + "live2d.min.js", "js"), loadExternalResource(live2d_path + "live2d.min.js", "js"),
loadExternalResource(live2d_path + "waifu-tips.js", "js") loadExternalResource(live2d_path + "waifu-tips.js", "js")
]).then(() => { ]).then(() => {
// 配置选项的具体用法见 README.md
initWidget({ initWidget({
waifuPath: live2d_path + "waifu-tips.json", waifuPath: live2d_path + "waifu-tips.json",
//apiPath: "https://live2d.fghrsh.net/api/", //apiPath: "https://live2d.fghrsh.net/api/",