Better DGG Kick Embed

MIGHT NOT WORK WITH TAMPERMONKEY. VIOLENTMONKEY SHOULD WORK. Hacky solution to embed full kick site instead of the embed. I can't promise it will continue to work indefinitely. If it bugs out when resizing the window, try refreshing the page.

目前為 2025-02-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Better DGG Kick Embed
// @namespace   yuniDev.kickembed
// @match       https://kick.com/*
// @match       https://www.destiny.gg/bigscreen
// @match       https://destiny.gg/bigscreen
// @grant       none
// @version     1.1
// @author      yuniDev
// @license     MIT
// @description MIGHT NOT WORK WITH TAMPERMONKEY. VIOLENTMONKEY SHOULD WORK. Hacky solution to embed full kick site instead of the embed. I can't promise it will continue to work indefinitely. If it bugs out when resizing the window, try refreshing the page.
// ==/UserScript==

let prevHash = "";

function htmlToNode(html) {
    const template = document.createElement('template');
    template.innerHTML = html;
    const nNodes = template.content.childNodes.length;
    return template.content.firstChild;
}

function hideSurroundings() {
  [...document.querySelectorAll("nav")].forEach(el => el.style = "display: none;");
  const channelChatroom = document.getElementById("channel-chatroom");
  if (channelChatroom) channelChatroom.style = "display: none";

  const sidebarWrapper = document.getElementById("sidebar-wrapper");
  if (sidebarWrapper) sidebarWrapper.style = "display: none";

  const channelContent = document.getElementById("channel-content");
  if (channelContent) channelContent.style = "display: none";

  const injectedChannelPlayer = document.getElementById("injected-channel-player");
  if (injectedChannelPlayer) {
    injectedChannelPlayer.style = "padding: 0px; max-height: max-content;";
    injectedChannelPlayer.parentNode.style = "max-height: max-content;";
  }

  const bodyChild = document.body.firstChild;
  if (bodyChild) {
    bodyChild.style = "height: min-content;";
    [...bodyChild.children].forEach(el => el.style = el.getAttribute("style") ?? "" +  ";padding-top: 0px;");
  }
  document.body.style = "height: min-content;";
}

function loadDestinyGG() {
  const { origin, hash } = window.location;

  if (prevHash.startsWith("#kick/") && !hash.startsWith("#kick")) location.reload(); // Reload page if switching away from kick embed
  prevHash = hash;

  // Check if the URL starts with the desired base
  const isValidStart = hash.startsWith("#kick/") && window.location.pathname === "/bigscreen";

  // Extract the channel name
  const channel = isValidStart ? hash.split("/")[1] : null;

  if (channel && isValidStart) { // We are watching a kick embed on Destiny.gg
    document.body.appendChild(htmlToNode(`<script type="module" src="https://unpkg.com/x-frame-bypass"></script>`));
    const targetUrl = `https://kick.com/${channel}`;

    id = setInterval(() => {
      const embedContainer = document.getElementById("embed");
      const existingIframe = embedContainer.querySelector(".embed-frame");
      if (!existingIframe) return;

      existingIframe.remove();

      clearInterval(id);

      const iframe = htmlToNode(`<iframe is="x-frame-bypass" class="embed-frame" src="${targetUrl}" allow="fullscreen; autoplay; encrypted-media; picture-in-picture; web-share"></iframe>`);
      embedContainer.appendChild(iframe);
    }, 100);
  }
}

if (window.location.hostname === "kick.com" && window.self !== window.top) { // Kick inside of iframe
  hideSurroundings();
  setInterval(() => {
    if (![...document.querySelectorAll("nav")].find(el => el.getAttribute("style") && el.getAttribute("style").indexOf("display: none") > -1)) hideSurroundings();
  }, 200);
} else {
  loadDestinyGG();
  addEventListener('hashchange', loadDestinyGG);
}