| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset='utf-8'>
- <meta http-equiv='X-UA-Compatible' content='IE=edge'>
- <title>OBS Twitch Points Alerts</title>
- <meta name='viewport' content='width=device-width, initial-scale=1'>
- <style>
- body {
- width: 100%;
- height: 100%;
- }
- * {
- color: white;
- }
- video {
- background-color: rgba(0, 0, 0, 0);
- height: 100vh;
- margin: 0 auto;
- display: block;
- z-index: -100;
- }
- h2 {
- display: none;
- position: absolute;
- top: 5em;
- left: 5em;
- z-index: 100;
- }
- </style>
- </head>
- <body>
- <video></video>
- <script>
- let video = document.querySelector("video");
- video.volume = 0.2;
- </script>
- <h2 id="ran">
- Random text
- </h2>
- <script>
- let el = document.querySelector("h2#ran");
- let randomnumber = Math.random() * 1000000;
- randomnumber = randomnumber.toString();
- el.textContent = "Random Number: " + randomnumber;
- </script>
- <script>
- function parseCommand(cmdObject){
- console.log(cmdObject.cmd);
- switch(cmdObject.cmd){
- case "reload":
- location.reload();
- break;
- case "stop":
- video.pause();
- break;
- case "start":
- video.play();
- break;
- case "vol":
- if(cmdObject.volume)
- video.volume = Number.parseFloat(cmdObject.volume)
- break;
- case "src":
- if(cmdObject.src){
- video.src=cmdObject.src
- }
- break;
- case "videoInQueue":
- if(video.src == ""){
- ws.send(JSON.stringify({
- action: "waitingForVideo"
- }))
- }
- break;
- case "abort":
- video.pause();
- video.src = "";
- video.removeAttribute("src");
- ws.send(JSON.stringify({
- action: "waitingForVideo"
- }))
- break;
- }
- }
- let ws = new WebSocket("ws://localhost:<$wsport$>");
- ws.onmessage = (msg)=>{
- let data = msg.data;
- let commandArray = JSON.parse(msg.data)
- if(commandArray instanceof Array){
- for(let it of commandArray){
- parseCommand(it);
- }
- }
- };
- video.addEventListener("ended", ()=>{
- video.src = "";
- video.removeAttribute("src");
- ws.send(JSON.stringify({
- action: "ended"
- }));
- })
- </script>
- <script>
- setInterval(()=>{
- if(!ws || ws.readyState != 1){
- location.reload();
- }
- }, 5000);
- </script>
- </body>
- </html>
|