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

  1. // ==UserScript==
  2. // @name TMGStudio M3U8 URL Grabber
  3. // @match *://*.tmgstudios.tv/supporters
  4. // @version 1.0
  5. // @description Copies the M3U8 for the specific video / audio to clipboard for use in other viewing programs such as MPV or VLC
  6. // @run-at document-end
  7. // @license MIT
  8. // @namespace https://greasyfork.org/users/784940
  9. // ==/UserScript==
  10.  
  11. // Constants
  12. const obsnode = document.querySelector('#posts_list');
  13. const obsOpt = {childList: true};
  14. const btnColor = "var(--color-primary)";
  15. const btnColorText = "var(--color-on-primary)";
  16. const btnStyle = `margin-left:auto; color:${btnColorText}; background-color:${btnColor}; align-self:center; cursor:pointer`;
  17. const btnClass = "badge badge--pale badge--large M3U8";
  18. const btnText = "Copy M3U8 to clipboard";
  19.  
  20. // Functions
  21. function copyStream(e) {
  22. let el = e.currentTarget;
  23. let m3u8Link = el.parentNode.parentNode.parentNode.parentNode.querySelector("[data-source]").getAttribute("data-source");
  24. navigator.clipboard.writeText(m3u8Link);
  25. }
  26.  
  27. function addCopyButton() {
  28. let tagSec = document.querySelectorAll(".post__tags");
  29. for (let sec of tagSec) {
  30. if (sec.parentNode.querySelector(".M3U8")) continue;
  31. sec.parentNode.style.display="flex";
  32. let btn = document.createElement("div");
  33. btn.classList = btnClass;
  34. btn.style = btnStyle;
  35. btn.innerText = btnText;
  36. sec.parentNode.appendChild(btn);
  37. btn.addEventListener("click", copyStream);
  38. }
  39. }
  40.  
  41.  
  42. // Entry Point
  43. let mut = new MutationObserver(addCopyButton);
  44. mut.observe(obsnode, obsOpt);
  45. addCopyButton();