mirror of
https://github.com/stevenjoezhang/live2d-widget.git
synced 2024-11-24 13:50:33 +08: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";
|
import randomSelection from "./utils.js";
|
||||||
|
|
||||||
class Model {
|
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.useCDN = useCDN;
|
||||||
this.apiPath = apiPath;
|
this.apiPath = apiPath;
|
||||||
this.cdnPath = cdnPath;
|
this.cdnPath = cdnPath;
|
||||||
|
@ -9,18 +9,7 @@ import randomSelection from "./utils.js";
|
|||||||
import tools from "./tools.js";
|
import tools from "./tools.js";
|
||||||
|
|
||||||
function loadWidget(config) {
|
function loadWidget(config) {
|
||||||
let { apiPath, cdnPath } = config;
|
const model = new Model(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);
|
|
||||||
localStorage.removeItem("waifu-display");
|
localStorage.removeItem("waifu-display");
|
||||||
sessionStorage.removeItem("waifu-text");
|
sessionStorage.removeItem("waifu-text");
|
||||||
document.body.insertAdjacentHTML("beforeend", `<div id="waifu">
|
document.body.insertAdjacentHTML("beforeend", `<div id="waifu">
|
||||||
@ -111,19 +100,6 @@ function loadWidget(config) {
|
|||||||
};
|
};
|
||||||
showMessage(welcomeMessage(), 7000, 8);
|
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() {
|
(function initModel() {
|
||||||
let modelId = localStorage.getItem("modelId"),
|
let modelId = localStorage.getItem("modelId"),
|
||||||
modelTexturesId = localStorage.getItem("modelTexturesId");
|
modelTexturesId = localStorage.getItem("modelTexturesId");
|
||||||
|
Loading…
Reference in New Issue
Block a user