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