mirror of
https://github.com/caojiezi2003/live2d-widget.git
synced 2024-11-10 04:49:47 +00:00
23 lines
722 B
JavaScript
23 lines
722 B
JavaScript
|
import randomSelection from "./utils.js";
|
||
|
|
||
|
let messageTimer;
|
||
|
|
||
|
function showMessage(text, timeout, priority) {
|
||
|
if (!text || (sessionStorage.getItem("waifu-text") && sessionStorage.getItem("waifu-text") > priority)) return;
|
||
|
if (messageTimer) {
|
||
|
clearTimeout(messageTimer);
|
||
|
messageTimer = null;
|
||
|
}
|
||
|
text = randomSelection(text);
|
||
|
sessionStorage.setItem("waifu-text", priority);
|
||
|
const tips = document.getElementById("waifu-tips");
|
||
|
tips.innerHTML = text;
|
||
|
tips.classList.add("waifu-tips-active");
|
||
|
messageTimer = setTimeout(() => {
|
||
|
sessionStorage.removeItem("waifu-text");
|
||
|
tips.classList.remove("waifu-tips-active");
|
||
|
}, timeout);
|
||
|
}
|
||
|
|
||
|
export default showMessage;
|