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/",