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

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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();