TikTok Live Guest

View TikTok Live without Login as Guest

  1. // ==UserScript==
  2. // @name TikTok Live Guest
  3. // @name:de TikTok Live Gast
  4. // @version 1.1.1
  5. // @description View TikTok Live without Login as Guest
  6. // @description:de TikTok Live schauen ohne Login als Gast
  7. // @icon https://www.tiktok.com/favicon.ico
  8. // @author TalkLounge (https://github.com/TalkLounge)
  9. // @namespace https://github.com/TalkLounge/tiktok-live-guest
  10. // @license MIT
  11. // @match https://www.tiktok.com/*
  12. // @require https://unpkg.com/mpegts.js@1.7.3/dist/mpegts.js
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. // 24/7 Stream: https://www.tiktok.com/@livehaf.official/live
  17. (async () => {
  18. let player;
  19.  
  20. const div = document.createElement("div"); // Parent Div
  21. div.style.display = "flex";
  22. div.style.justifyContent = "center";
  23.  
  24. const divResize = document.createElement("div"); // Resize Video Div
  25. divResize.style.resize = "vertical";
  26. divResize.style.overflow = "hidden";
  27. divResize.style.height = "50vh";
  28. div.append(divResize);
  29.  
  30. async function removePopups() {
  31. for (let i = 0; i < 10 * 4; i++) {
  32. document.querySelector("#login-modal")?.parentNode?.parentNode?.parentNode?.remove(); // Remove Login Modal
  33. document.querySelector("tiktok-cookie-banner")?.remove(); // Remove Cookie Banner
  34. document.body.classList.remove("hidden");
  35. await new Promise(r => setTimeout(r, 250));
  36. }
  37. }
  38.  
  39. function initPlayer(url, video) {
  40. player = mpegts.createPlayer({
  41. type: "mse",
  42. isLive: true,
  43. url
  44. });
  45. player.attachMediaElement(video);
  46. player.load();
  47. player.play();
  48. }
  49.  
  50. async function initLive() {
  51. if (!window.location.pathname.startsWith("/@") || !window.location.pathname.endsWith("/live")) {
  52. return;
  53. }
  54.  
  55. const room_id = document.querySelector('[property="al:ios:url"]').getAttribute("content").split("=")[1];
  56. let data = await fetch(`https://webcast.tiktok.com/webcast/room/info/?aid=1988&room_id=${room_id}`);
  57. data = await data.json();
  58. console.log("[TikTok Live Gast]: Stream URLs", data.data.stream_url);
  59. data = data.data.stream_url.flv_pull_url;
  60. data = data.pm_mt_video_1080p60 || data.FULL_HD1 || data.pm_mt_video_720p60 || data.HD1 || data.SD2 || data.SD1;
  61.  
  62. if (!mpegts.getFeatureList().mseLivePlayback) {
  63. return;
  64. }
  65.  
  66. div.style.position = "absolute";
  67. div.style.width = "90%";
  68. div.style.zIndex = 2;
  69. div.style.marginTop = `${document.querySelector("[class*=DivLiveRoomBanner]").getBoundingClientRect().height}px`;
  70.  
  71. const parent = document.querySelector("[class*=DivLiveContainer]");
  72. parent.insertBefore(div, parent.firstChild);
  73.  
  74. const video = document.createElement("video");
  75. video.style.height = "100%";
  76. video.controls = true;
  77. video.volume = 0.5;
  78.  
  79. divResize.style.height = "75vh";
  80. divResize.append(video);
  81.  
  82. document.querySelector("[class*=DivFeedLivePlayerCoreContainer]").remove();
  83. document.querySelector("[class*=DivChatRoomAnimationContainer]").remove();
  84.  
  85. initPlayer(data, video);
  86.  
  87. video.addEventListener("ended", () => { // [MSEController] > MediaSource onSourceEnded
  88. player.destroy();
  89. initPlayer(data, video);
  90. });
  91. }
  92.  
  93. async function initProfile() {
  94. for (let i = 0; i < 10 * 4; i++) {
  95. await new Promise(r => setTimeout(r, 250));
  96.  
  97. if (!window.location.pathname.startsWith("/@")) {
  98. continue;
  99. }
  100.  
  101. if (document.querySelector("[data-e2e=user-post-item-list] a[target=tiktok_live_view_window] video")) {
  102. console.log("[TikTok Live Gast]: Detected Live in List");
  103. await new Promise(r => setTimeout(r, 2500));
  104.  
  105. const parent = document.querySelector("#main-content-others_homepage");
  106. parent.insertBefore(div, parent.firstChild);
  107.  
  108. const video = document.querySelector("[data-e2e=user-post-item-list] a[target=tiktok_live_view_window] video");
  109. video.style.height = "100%";
  110. video.style.transform = "";
  111. video.controls = true;
  112. video.muted = false;
  113. video.volume = 0.5;
  114. divResize.append(video);
  115.  
  116. break;
  117. } else if (document.querySelector("#main-content-others_homepage").parentNode.firstChild.target == "tiktok_live_view_window" && document.querySelector("#main-content-others_homepage").parentNode.firstChild.querySelector("video")) {
  118. console.log("[TikTok Live Gast]: Detected Live in Banner");
  119. await new Promise(r => setTimeout(r, 3000));
  120.  
  121. const a = document.querySelector("a[target=tiktok_live_view_window]");
  122. a.querySelector("div").style.height = "100%";
  123. a.parentNode.insertBefore(div, a.parentNode.firstChild);
  124.  
  125. const video = a.querySelector("video");
  126. video.style.height = "100%";
  127. video.style.transform = "";
  128. video.controls = true;
  129. video.muted = false;
  130. video.volume = 0.5;
  131. divResize.append(video);
  132.  
  133. div.append(a);
  134.  
  135. break;
  136. }
  137. }
  138. }
  139.  
  140. initLive();
  141. initProfile();
  142. removePopups();
  143. })()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址