"use strict"; (() => { // scripts/title-animation.js var TitleAnimation = class { constructor(faviconUrl, emojiFavico, messages, animationType, speed, targetElement) { var _a; this.messages = animationType === "blinking" ? [...messages, document.title] : [...messages, " "]; this.animationType = animationType; this.speed = speed; this.emojiFavicon = `data:image/svg+xml,${emojiFavico}`; this.faviconUrl = faviconUrl ? faviconUrl : this.emojiFavicon; this.targetElement = targetElement || document.querySelector("title"); this.originalTitle = document.title; this.favicon = document.querySelector('link[rel*="icon"]'); this.originalFaviconUrl = ((_a = document.querySelector('link[rel*="icon"]')) == null ? void 0 : _a.getAttribute("href")) || this.faviconUrl; this.workerUrl = this.getWorkerURL(); this.worker = new Worker(this.workerUrl); this.worker.postMessage({ messageType: "configure", messageContent: { messages: this.messages, animationType: this.animationType, speed: this.speed } }); this.worker.onmessage = (e) => { const { messageType, messageContent } = e.data; switch (messageType) { case "updateContent": this.updateContent(messageContent); break; case "startAnimation": this.startAnimation(); break; case "clearAnimation": this.clearAnimation(); break; default: console.error("Invalid message type from worker:", messageType); break; } }; } getWorkerURL() { var _a; const url = (_a = document.querySelector("#animation-worker-tr")) == null ? void 0 : _a.getAttribute("data-src"); if (!url) { return `/assets/animation-worker.js`; } const content = `importScripts( "${url}" );`; const blobUrl = URL.createObjectURL( new Blob([content], { type: "text/javascript" }) ); return blobUrl; } createNewFavicon() { const favicon = document.createElement("link"); favicon.rel = "icon"; document.head.appendChild(favicon); return favicon; } updateEmojiFavicon() { if (!this.favicon) { this.favicon = this.createNewFavicon(); } this.favicon.href = this.faviconUrl; } updateFaviconOriginal() { if (!this.favicon) { this.favicon = this.createNewFavicon(); } this.favicon.href = this.originalFaviconUrl; } updateContent(message) { this.updateEmojiFavicon(); this.targetElement.innerText = message; } startAnimation() { this.worker.postMessage({ messageType: "startAnimation" }); } clearAnimation() { this.worker.postMessage({ messageType: "clearAnimation" }); } destroy() { this.clearAnimation(); this.worker.terminate(); this.targetElement.innerText = this.originalTitle || " "; this.updateFaviconOriginal(); } pause() { this.clearAnimation(); } // initWorkerSrc() { // const workerBlob = new Blob( // Array.prototype.map.call( // document.querySelector("#animation-worker-tr"), // (script) => script.textContent // ), // { type: "text/javascript" } // ); // const workerSrc = window.URL.createObjectURL(workerBlob); // return workerSrc; // } }; // scripts/app.js var configs = window == null ? void 0 : window.TabRecover; var titleAnimation = null; var tabVisibleTimer = null; handleAnimation(configs); function handleAnimation(configs2) { const { animationType, animationSpeed, messages, isPublished, selectedEmoji: { emoji }, faviconUrl } = configs2; if (!isPublished) { return; } function startAnimation() { if (!titleAnimation) { titleAnimation = new TitleAnimation( faviconUrl, emoji, messages, animationType, animationSpeed, null ); titleAnimation.startAnimation(); } } function stopAnimation() { if (titleAnimation) { titleAnimation.destroy(); titleAnimation = null; } } document.addEventListener("visibilitychange", () => { if (document.visibilityState === "hidden") { clearTimeout(tabVisibleTimer); tabVisibleTimer = setTimeout(startAnimation, 200); } else { stopAnimation(); clearTimeout(tabVisibleTimer); } }); } })();