TMGStudio M3U8 URL Grabber

Copies the M3U8 for the specific video / audio to clipboard for use in other viewing programs such as MPV or VLC

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name TMGStudio M3U8 URL Grabber
// @match *://*.tmgstudios.tv/supporters
// @version 1.0
// @description Copies the M3U8 for the specific video / audio to clipboard for use in other viewing programs such as MPV or VLC
// @run-at document-end
// @license MIT
// @namespace https://greasyfork.org/users/784940
// ==/UserScript==

// Constants
const obsnode = document.querySelector('#posts_list');
const obsOpt = {childList: true};
const btnColor = "var(--color-primary)";
const btnColorText = "var(--color-on-primary)";
const btnStyle = `margin-left:auto; color:${btnColorText}; background-color:${btnColor}; align-self:center; cursor:pointer`;
const btnClass = "badge badge--pale badge--large M3U8";
const btnText = "Copy M3U8 to clipboard";

// Functions
function copyStream(e) {
    let el = e.currentTarget;
    let m3u8Link = el.parentNode.parentNode.parentNode.parentNode.querySelector("[data-source]").getAttribute("data-source");
    navigator.clipboard.writeText(m3u8Link);
}

function addCopyButton() {
let tagSec = document.querySelectorAll(".post__tags");
for (let sec of tagSec) {
    if (sec.parentNode.querySelector(".M3U8")) continue;
    sec.parentNode.style.display="flex";
    let btn = document.createElement("div");
    btn.classList = btnClass;
    btn.style = btnStyle;
    btn.innerText = btnText;
    sec.parentNode.appendChild(btn);
    btn.addEventListener("click", copyStream);
    }
}


// Entry Point
let mut = new MutationObserver(addCopyButton);
mut.observe(obsnode, obsOpt);
addCopyButton();