pub / tw2html

Checks online status of streams on twitch.tv and lets you watch them
git clone https://src.jayvii.de/pub/tw2html.git
Home | Log | Files | Exports | Refs | README | RSS

twitch.js (1684B)


      1 function toggle_player(stream) {
      2 	var img = document.querySelector("#img-" + stream);
      3 	var ply = document.querySelector("#play-" + stream);
      4 	if (img != null) {
      5 		var player = document.createElement("iframe");
      6 		player.allowFullscreen = "true";
      7 		player.width = "100%";
      8 		player.height = "100%";
      9 		player.frameborder = "0";
     10 		player.scrolling = "no";
     11 		player.src = "https://player.twitch.tv/?channel=" +
     12 			stream +
     13 			"&parent=" +
     14 			window.location.hostname +
     15 			"&muted=false&volume=1&quality=auto";
     16 		player.id = "play-" + stream;
     17 		player.classList.add("preview");
     18 		img.replaceWith(player);
     19 	}
     20 	if (ply != null) {
     21 		var image = document.createElement("img");
     22 		image.src = "https://static-cdn.jtvnw.net/previews-ttv/live_user_" + stream + "-1280x720.jpg";
     23 		image.id = "img-" + stream;
     24 		image.classList.add("preview");
     25 		ply.replaceWith(image);
     26 	}
     27 }
     28 
     29 function toggle_chat(stream) {
     30 	var plho = document.querySelector("#chat-placeholder-" + stream);
     31 	var chat = document.querySelector("#chat-" + stream);
     32 	if (chat != null) {
     33 		var placeholder = document.createElement("div");
     34 		placeholder.id = "chat-placeholder-" + stream;
     35 		chat.replaceWith(placeholder);
     36 	}
     37 	if (plho != null) {
     38 		var chatembed = document.createElement("iframe");
     39 		chatembed.width = "100%";
     40 		chatembed.height = "100%";
     41 		chatembed.frameborder = "0";
     42 		chatembed.scrolling = "auto";
     43 		chatembed.src = "https://www.twitch.tv/embed/" +
     44 			stream +
     45 			"/chat?parent=" +
     46 			window.location.hostname;
     47 		// Check for dark mode
     48 		if (window.matchMedia('(prefers-color-scheme: dark)')) {
     49 			chatembed.src = chatembed.src + "&darkpopout";
     50 		}
     51 		chatembed.id = "chat-" + stream;
     52 		plho.replaceWith(chatembed);
     53 	}
     54 }
     55