From 269dde43a6d5d4958607074facc9a11804122fb6 Mon Sep 17 00:00:00 2001 From: nicocatxzc <114812330+nicocatxzc@users.noreply.github.com> Date: Fri, 26 Jul 2024 20:38:45 +0800 Subject: [PATCH] Update autoload.js --- autoload.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/autoload.js b/autoload.js index 8b6f70f..4bb8eb6 100644 --- a/autoload.js +++ b/autoload.js @@ -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 -if (screen.width >= 768) { +if (isMobile()) { + //移动端用户 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 + "waifu-tips.js", "js") ]).then(() => { @@ -35,20 +45,17 @@ if (screen.width >= 768) { initWidget({ waifuPath: live2d_path + "waifu-tips.json", //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"] }); }); -} - -// 加载 waifu.css live2d.min.js waifu-tips-.js,适配移动端 -if (screen.width < 768) { +} else { + //pc端用户 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 + "waifu-tips.js", "js") ]).then(() => { - // 配置选项的具体用法见 README.md initWidget({ waifuPath: live2d_path + "waifu-tips.json", //apiPath: "https://live2d.fghrsh.net/api/",