From aab6246545a9eb8992aa9023dad98c7ecd22143d Mon Sep 17 00:00:00 2001 From: StevenJoeZhang <1119186082@qq.com> Date: Wed, 7 Aug 2019 01:12:42 +0800 Subject: [PATCH] Optimize the loading of Asteroids --- waifu-tips.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/waifu-tips.js b/waifu-tips.js index 5b054ac..75e95cf 100755 --- a/waifu-tips.js +++ b/waifu-tips.js @@ -24,9 +24,16 @@ function loadWidget(waifuPath, apiPath) { function registerEventListener() { $("#waifu-tool .fa-comment").click(showHitokoto); $("#waifu-tool .fa-paper-plane").click(function() { - var s = document.createElement("script"); - document.body.appendChild(s); - s.src = "https://cdn.jsdelivr.net/gh/GalaxyMimi/CDN/asteroids.js"; + if (window.Asteroids) { + if (!window.ASTEROIDSPLAYERS) window.ASTEROIDSPLAYERS = []; + window.ASTEROIDSPLAYERS.push(new Asteroids()); + } else { + $.ajax({ + url: "https://cdn.jsdelivr.net/gh/GalaxyMimi/CDN/asteroids.js", + dataType: "script", + cache: true + }); + } }); $("#waifu-tool .fa-user-circle").click(loadOtherModel); $("#waifu-tool .fa-street-view").click(loadRandModel);