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-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Replace Kick Embed with Channel Page and Enable Theatre Mode
// @namespace    https://player.kick.com/
// @version      1.3
// @description  Replaces Kick embed with a full channel page and enables theatre mode on Kick.com only when loaded as an embed replacement
// @author       nobody
// @match        *://player.kick.com/*
// @match        *://kick.com/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_addStyle
// @license      GPL-3.0-or-later
// ==/UserScript==

if (window.location.host.includes("player.kick.com")) {
    // Code for the embed page: Replace the Kick player with a full channel page
    const observer = new MutationObserver(() => {
        const playerContainer = document.querySelector(".video-container");
        if (playerContainer) {
            // Extract channel information from the URL
            const channelUrl = window.location.href;
            console.log("Channel URL:", channelUrl);
            const channelId = channelUrl.split("/")[3]; // Assumes URL is like: https://player.kick.com/channel/{channelId}
            console.log("Channel ID:", channelId);

            // Create an iframe for the full Kick channel page
            const iframe = document.createElement("iframe");
            iframe.src = `https://kick.com/${channelId}`;
            iframe.style.width = "100%";
            iframe.style.height = "100vh"; // Full viewport height
            iframe.style.border = "none";

            // Replace the embed with the full channel page
            playerContainer.innerHTML = "";
            playerContainer.appendChild(iframe);

            // Stop observing and mark that we replaced the embed
            observer.disconnect();
            GM_setValue("embedReplaced", true);
        }
    });
    observer.observe(document.body, {
        subtree: true,
        childList: true,
    });
} else if (window.location.host.includes("kick.com")) {
    // Code for kick.com: Only run if the embed was replaced and the referrer indicates it came from player.kick.com
    const embedReplacedValue = GM_getValue("embedReplaced", false);
    if (embedReplacedValue && document.referrer.includes("player.kick.com")) {
        console.log("Embed replacement detected via referrer. Enabling theatre mode...");
        const observer2 = new MutationObserver(() => {
            const el = document.querySelector('[data-sidebar]');
            el.dataset.sidebar = 'false';
            el.dataset.chat = 'false';
            el.dataset.theatre = 'true';

            GM_addStyle(`
              [data-sidebar] > .w-xvw {
                padding-top: unset !important;
              }

              #channel-content {
                display: none;
              }
            `);

            observer2.disconnect();
            // Clear the flag so subsequent direct visits to kick.com don't trigger theatre mode
            GM_setValue("embedReplaced", false);
        });
        observer2.observe(document.body, {
            subtree: true,
            childList: true,
        });
    }
}