Twitch Adblock

[Working as of 11/19/2020] Blocks Twitch livestream ads

Versão de: 19/11/2020. Veja: a última versão.

  1. // ==UserScript==
  2. // @name Twitch Adblock
  3. // @namespace https://greasyfork.org/en/users/9694-croned
  4. // @version 1.1.3
  5. // @description [Working as of 11/19/2020] Blocks Twitch livestream ads
  6. // @author FTwitch
  7. // @include https://www.twitch.tv/*
  8. // @include https://cdn.embedly.com/*
  9. // @grant none
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. if (window.location.origin == "https://cdn.embedly.com") {
  15. document.getElementsByTagName("html")[0].style = "overflow: hidden";
  16. return;
  17. }
  18.  
  19. var lastStreamer, oldHtml;
  20.  
  21. var observer = new MutationObserver(function (mutations, observer) {
  22. var container = document.querySelector(".video-player .tw-absolute");
  23.  
  24. if (!container)
  25. return;
  26.  
  27. if (window.location.pathname.indexOf("/directory") == 0)
  28. return;
  29.  
  30. var streamerName = window.location.pathname.replace("/", "");
  31. var iframeUrl = `https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.twitch.tv%2F%3Fchannel%3D${streamerName}%26muted%3Dfalse%26parent%3Dcdn.embedly.com&type=text%2Fhtml&card=1&schema=twitch`;
  32. var existingIframe = document.getElementById("embed-adblock");
  33.  
  34. if ((!streamerName && !lastStreamer) || streamerName.indexOf("videos/") == 0) {
  35. lastStreamer = null;
  36.  
  37. for (let el of container.children)
  38. el.hidden = false;
  39.  
  40. if (existingIframe) {
  41. existingIframe.src = "";
  42. existingIframe.hidden = true;
  43. }
  44.  
  45. return;
  46. }
  47. else if (!streamerName)
  48. return;
  49.  
  50. for (let el of container.children) {
  51. if (el.tagName != "IFRAME")
  52. el.hidden = true;
  53.  
  54. if (el.tagName == "VIDEO")
  55. el.src = "";
  56. }
  57.  
  58. if (!existingIframe) {
  59. existingIframe = document.createElement("iframe");
  60. existingIframe.id = "embed-adblock";
  61. existingIframe.src = iframeUrl;
  62. existingIframe.style = "width: 100%; height: 100%";
  63. container.appendChild(existingIframe);
  64. }
  65. else if (streamerName != lastStreamer) {
  66. existingIframe.src = iframeUrl;
  67. existingIframe.hidden = false;
  68. }
  69.  
  70. lastStreamer = streamerName
  71. });
  72.  
  73. observer.observe(document.getElementsByClassName("root-scrollable__wrapper tw-full-width tw-relative")[0], { attributes: false, childList: true, subtree: true });
  74. })();