Skip to content

Instantly share code, notes, and snippets.

View coo11's full-sized avatar

coo11

  • Future Gadget Laboratory
  • China
View GitHub Profile
@coo11
coo11 / toast.js
Last active July 21, 2024 19:45 — forked from superRaytin/simpleToast.js
Simple Toast
function toast(text, duration) {
window.simpleToastTimer && clearTimeout(window.simpleToastTimer);
const wrapStyle =
"display: flex; justify-content: center; padding: 0.6rem 1rem; font-size: 1.5rem; color: #fff; background: rgba(0, 0, 0, 0.7); border-radius: 0.4rem; position: fixed; top: 50%; left: 50%; z-index: 100; transform: translate3d(-50%, -50%, 1px);",
contentStyle = "max-width: calc(96vw - 2rem); overflow-wrap: break-word;",
toastEleId = "__GM_toast",
toastInnerHTML = `<div style="${wrapStyle}"><div style="${contentStyle}">${text}</div></div>`;
let toastEl = document.getElementById(toastEleId);
if (toastEl) toastEl.innerHTML = toastInnerHTML;
else {