From 477be786935a52b374923ebc094c867c3c0c74b8 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 20 Oct 2022 22:14:37 +0800 Subject: [PATCH] Clean up --- src/model.js | 12 +++++++++++- src/waifu-tips.js | 26 +------------------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/model.js b/src/model.js index ca8653c..23b036a 100644 --- a/src/model.js +++ b/src/model.js @@ -2,7 +2,17 @@ import showMessage from "./message.js"; import randomSelection from "./utils.js"; class Model { - constructor(useCDN, apiPath, cdnPath) { + constructor(config) { + let { apiPath, cdnPath } = config; + let useCDN = false; + if (typeof cdnPath === "string") { + useCDN = true; + if (!cdnPath.endsWith("/")) cdnPath += "/"; + } else if (typeof apiPath === "string") { + if (!apiPath.endsWith("/")) apiPath += "/"; + } else { + throw "Invalid initWidget argument!"; + } this.useCDN = useCDN; this.apiPath = apiPath; this.cdnPath = cdnPath; diff --git a/src/waifu-tips.js b/src/waifu-tips.js index 63026df..ea54ad2 100755 --- a/src/waifu-tips.js +++ b/src/waifu-tips.js @@ -9,18 +9,7 @@ import randomSelection from "./utils.js"; import tools from "./tools.js"; function loadWidget(config) { - let { apiPath, cdnPath } = config; - let useCDN = false; - if (typeof cdnPath === "string") { - useCDN = true; - if (!cdnPath.endsWith("/")) cdnPath += "/"; - } else if (typeof apiPath === "string") { - if (!apiPath.endsWith("/")) apiPath += "/"; - } else { - console.error("Invalid initWidget argument!"); - return; - } - const model = new Model(useCDN, apiPath, cdnPath); + const model = new Model(config); localStorage.removeItem("waifu-display"); sessionStorage.removeItem("waifu-text"); document.body.insertAdjacentHTML("beforeend", `
@@ -111,19 +100,6 @@ function loadWidget(config) { }; showMessage(welcomeMessage(), 7000, 8); - function showHitokoto() { - // 增加 hitokoto.cn 的 API - fetch("https://v1.hitokoto.cn") - .then(response => response.json()) - .then(result => { - const text = `这句一言来自 「${result.from}」,是 ${result.creator} 在 hitokoto.cn 投稿的。`; - showMessage(result.hitokoto, 6000, 9); - setTimeout(() => { - showMessage(text, 4000, 9); - }, 6000); - }); - } - (function initModel() { let modelId = localStorage.getItem("modelId"), modelTexturesId = localStorage.getItem("modelTexturesId");