|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <link rel="stylesheet" href="tailwind.css"> |
| 7 | + <title>Unbox Overlay</title> |
| 8 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script> |
| 9 | + <script> |
| 10 | + document.addEventListener('DOMContentLoaded', () => { |
| 11 | + const items = [{"id": 5, "contentType": "Album Art", "selector": ".sweep-text-artwork"}]; |
| 12 | + items.forEach(item => { |
| 13 | + item.element = document.querySelector(item.selector); |
| 14 | + }); |
| 15 | + |
| 16 | + const applyAnimation = (element, animationName, duration) => { |
| 17 | + if (!element) return; |
| 18 | + const translateYValue = animationName === 'fadeIn' ? [100, 0] : [0, -100]; |
| 19 | + const opacityValue = animationName === 'fadeIn' ? [0, 1] : [1, 0]; |
| 20 | + return anime({ |
| 21 | + targets: element, |
| 22 | + translateY: translateYValue, |
| 23 | + opacity: opacityValue, |
| 24 | + easing: 'easeOutExpo', |
| 25 | + duration: duration * 1000 |
| 26 | + }); |
| 27 | + } |
| 28 | + |
| 29 | + const setupWebSocket = (elements) => { |
| 30 | + const socket = new WebSocket('ws://10.0.0.162:3000'); |
| 31 | + |
| 32 | + socket.addEventListener('message', (event) => { |
| 33 | + const trackDetails = JSON.parse(event.data); |
| 34 | + |
| 35 | + elements.forEach((item) => { |
| 36 | + if (item.element.firstChild && item.contentType === 'Album Art') { |
| 37 | + let animation = applyAnimation(item.element.firstChild, 'fadeOut', 1 + item.id * 0.1); |
| 38 | + animation.finished.then(() => { |
| 39 | + item.element.removeChild(item.element.firstChild); |
| 40 | + if (trackDetails.artwork) { |
| 41 | + const img = document.createElement('img'); |
| 42 | + img.src = trackDetails.artwork; |
| 43 | + img.className = 'sweep-text-artwork'; |
| 44 | + item.element.appendChild(img); |
| 45 | + applyAnimation(img, 'fadeIn', 1 + item.id * 0.1); |
| 46 | + } |
| 47 | + }); |
| 48 | + } else if (trackDetails.artwork) { |
| 49 | + const img = document.createElement('img'); |
| 50 | + img.src = trackDetails.artwork; |
| 51 | + img.className = 'sweep-text-artwork'; |
| 52 | + item.element.appendChild(img); |
| 53 | + applyAnimation(img, 'fadeIn', 1 + item.id * 0.1); |
| 54 | + } |
| 55 | + }); |
| 56 | + }); |
| 57 | + } |
| 58 | + |
| 59 | + setupWebSocket(items); |
| 60 | + }); |
| 61 | + </script> |
| 62 | +</head> |
| 63 | +<body> |
| 64 | +<div class="relative w-full h-full"> |
| 65 | + <div class="overflow-hidden rounded-lg"> |
| 66 | + <div class="px-4 py-5 sm:p-6"> |
| 67 | + <div class="mx-auto max-w-fit min-w-fit"> |
| 68 | + <div class="flex items-stretch"> |
| 69 | + <div class="w-1/8 flex-shrink-0 self-center"> |
| 70 | + <div class="mr-2 h-32 w-32 flex items-center sweep-text-artwork sweep-text-item"></div> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | +</div> |
| 77 | +</body> |
| 78 | +</html> |
0 commit comments