mirror of
https://github.com/caojiezi2003/live2d-widget.git
synced 2024-11-22 06:49:44 +00:00
Clean up
This commit is contained in:
parent
f9d16854f4
commit
477be78693
12
src/model.js
12
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;
|
||||
|
@ -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", `<div id="waifu">
|
||||
@ -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 = `这句一言来自 <span>「${result.from}」</span>,是 <span>${result.creator}</span> 在 hitokoto.cn 投稿的。`;
|
||||
showMessage(result.hitokoto, 6000, 9);
|
||||
setTimeout(() => {
|
||||
showMessage(text, 4000, 9);
|
||||
}, 6000);
|
||||
});
|
||||
}
|
||||
|
||||
(function initModel() {
|
||||
let modelId = localStorage.getItem("modelId"),
|
||||
modelTexturesId = localStorage.getItem("modelTexturesId");
|
||||
|
Loading…
Reference in New Issue
Block a user