From e4037cdcd6fd562a97afb4203553cc09f1a2b392 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Mon, 27 Jan 2020 12:07:54 +0800 Subject: [PATCH] Skip script loading when screen width is narrow --- autoload.js | 16 +++++++++------- waifu-tips.js | 1 - waifu-tips.json | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/autoload.js b/autoload.js index 4d5c3ed..b2020e7 100644 --- a/autoload.js +++ b/autoload.js @@ -25,13 +25,15 @@ function loadExternalResource(url, type) { } // 加载 waifu.css live2d.min.js waifu-tips.js -Promise.all([ - loadExternalResource(live2d_path + "waifu.css", "css"), - loadExternalResource(live2d_path + "live2d.min.js", "js"), - loadExternalResource(live2d_path + "waifu-tips.js", "js") -]).then(() => { - initWidget(live2d_path + "waifu-tips.json", "https://live2d.fghrsh.net/api"); -}); +if (screen.width >= 768) { + Promise.all([ + loadExternalResource(live2d_path + "waifu.css", "css"), + loadExternalResource(live2d_path + "live2d.min.js", "js"), + loadExternalResource(live2d_path + "waifu-tips.js", "js") + ]).then(() => { + initWidget(live2d_path + "waifu-tips.json", "https://live2d.fghrsh.net/api"); + }); +} // initWidget 第一个参数为 waifu-tips.json 的路径,第二个参数为 API 地址 // API 后端可自行搭建,参考 https://github.com/fghrsh/live2d_api // 初始化看板娘会自动加载指定目录下的 waifu-tips.json diff --git a/waifu-tips.js b/waifu-tips.js index 152eadf..f44a4b8 100755 --- a/waifu-tips.js +++ b/waifu-tips.js @@ -221,7 +221,6 @@ function loadWidget(waifuPath, apiPath) { } function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") { - if (screen.width <= 768) return; document.body.insertAdjacentHTML("beforeend", `