Skip to content

Commit e4037cd

Browse files
Skip script loading when screen width is narrow
1 parent 7c604ae commit e4037cd

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

autoload.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ function loadExternalResource(url, type) {
2525
}
2626

2727
// 加载 waifu.css live2d.min.js waifu-tips.js
28-
Promise.all([
29-
loadExternalResource(live2d_path + "waifu.css", "css"),
30-
loadExternalResource(live2d_path + "live2d.min.js", "js"),
31-
loadExternalResource(live2d_path + "waifu-tips.js", "js")
32-
]).then(() => {
33-
initWidget(live2d_path + "waifu-tips.json", "https://live2d.fghrsh.net/api");
34-
});
28+
if (screen.width >= 768) {
29+
Promise.all([
30+
loadExternalResource(live2d_path + "waifu.css", "css"),
31+
loadExternalResource(live2d_path + "live2d.min.js", "js"),
32+
loadExternalResource(live2d_path + "waifu-tips.js", "js")
33+
]).then(() => {
34+
initWidget(live2d_path + "waifu-tips.json", "https://live2d.fghrsh.net/api");
35+
});
36+
}
3537
// initWidget 第一个参数为 waifu-tips.json 的路径,第二个参数为 API 地址
3638
// API 后端可自行搭建,参考 https://github.com/fghrsh/live2d_api
3739
// 初始化看板娘会自动加载指定目录下的 waifu-tips.json

waifu-tips.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ function loadWidget(waifuPath, apiPath) {
221221
}
222222

223223
function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") {
224-
if (screen.width <= 768) return;
225224
document.body.insertAdjacentHTML("beforeend", `<div id="waifu-toggle">
226225
<span>看板娘</span>
227226
</div>`);

waifu-tips.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"text": ["猜猜我要说些什么?", "我从青蛙王子那里听到了不少人生经验。"]
88
}, {
99
"selector": "#waifu-tool .fa-paper-plane",
10-
"text": ["要不要来玩飞机大战?", "这个按钮上写着不要点击", "怎么,你想来和我玩个游戏?", "听说这样可以蹦迪!"]
10+
"text": ["要不要来玩飞机大战?", "这个按钮上写着不要点击", "怎么,你想来和我玩个游戏?", "听说这样可以蹦迪!"]
1111
}, {
1212
"selector": "#waifu-tool .fa-user-circle",
1313
"text": ["你是不是不爱人家了呀,呜呜呜~", "要见见我的姐姐嘛?", "想要看我妹妹嘛?", "要切换看板娘吗?"]

0 commit comments

Comments
 (0)