Replace Kick Embed with Channel Page and Enable Theatre Mode

Replaces Kick embed with a full channel page and enables theatre mode on Kick.com only when loaded as an embed replacement

当前为 2025-03-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Replace Kick Embed with Channel Page and Enable Theatre Mode
  3. // @namespace https://player.kick.com/
  4. // @version 0.4.1
  5. // @description Replaces Kick embed with a full channel page and enables theatre mode on Kick.com only when loaded as an embed replacement
  6. // @author nobody
  7. // @match *://player.kick.com/*
  8. // @match *://kick.com/*
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @run-at document-start
  12. // @license GPL-3.0-or-later
  13. // ==/UserScript==
  14.  
  15. if (window.location.host.includes("player.kick.com")) {
  16. // Code for the embed page: Replace the Kick player with a full channel page
  17. const observer = new MutationObserver(() => {
  18. const playerContainer = document.querySelector(".video-container");
  19. if (playerContainer) {
  20. // Extract channel information from the URL
  21. const channelUrl = window.location.href;
  22. console.log("Channel URL:", channelUrl);
  23. const channelId = channelUrl.split("/")[3]; // Assumes URL is like: https://player.kick.com/channel/{channelId}
  24. console.log("Channel ID:", channelId);
  25.  
  26. // Create an iframe for the full Kick channel page
  27. const iframe = document.createElement("iframe");
  28. iframe.src = `https://kick.com/${channelId}`;
  29. iframe.style.width = "100%";
  30. iframe.style.height = "100vh"; // Full viewport height
  31. iframe.style.border = "none";
  32.  
  33. // Replace the embed with the full channel page
  34. playerContainer.innerHTML = "";
  35. playerContainer.appendChild(iframe);
  36.  
  37. // Stop observing and mark that we replaced the embed
  38. observer.disconnect();
  39. GM_setValue("embedReplaced", true);
  40. }
  41. });
  42. observer.observe(document.body, {
  43. subtree: true,
  44. childList: true,
  45. });
  46. } else if (window.location.host.includes("kick.com")) {
  47. // Code for kick.com: Only run if the embed was replaced and the referrer indicates it came from player.kick.com
  48. const embedReplacedValue = GM_getValue("embedReplaced", false);
  49. if (embedReplacedValue && document.referrer.includes("player.kick.com")) {
  50. console.log("Embed replacement detected via referrer. Enabling theatre mode...");
  51. const observer2 = new MutationObserver(() => {
  52.  
  53. setTimeout(() => {
  54. const clickEvent = new MouseEvent('click', {
  55. bubbles: true,
  56. cancelable: true
  57. });
  58. document.querySelector('#channel-chatroom > div:first-child > div > button').dispatchEvent(clickEvent);
  59. }, 200);
  60. setTimeout(() => {
  61. const keydownEvent = new KeyboardEvent('keydown', {
  62. key: 't',
  63. code: 'KeyT',
  64. keyCode: 84, // deprecated, but sometimes needed for compatibility
  65. which: 84, // deprecated, but sometimes needed for compatibility
  66. bubbles: true,
  67. cancelable: true
  68. });
  69. document.querySelector('#video-player')?.dispatchEvent(keydownEvent);
  70. }, 500);
  71.  
  72. observer2.disconnect();
  73. // Clear the flag so subsequent direct visits to kick.com don't trigger theatre mode
  74. GM_setValue("embedReplaced", false);
  75. });
  76. observer2.observe(document.body, {
  77. subtree: true,
  78. childList: true,
  79. });
  80. }
  81. }