Guest User

Meh

a guest
Nov 3rd, 2020
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.     'use strict';
  3.    
  4.     function rewriteURL(uri) {
  5.         var url = new URL(uri);
  6.         var parameters = url.searchParams;
  7.         if (parameters && parameters.get('token')) {
  8.             var jso = JSON.parse(parameters.get('token'));
  9.             if (!jso.server_ads && !jso.show_ads && jso.hide_ads) {
  10.                 return null;
  11.             }
  12.            
  13.             jso.adblock = false;
  14.             jso.authorization.forbidden = false;
  15.             jso.authorization.reason = "";
  16.             jso.hide_ads = true;
  17.             jso.player_type = "site";
  18.             jso.server_ads = false;
  19.             jso.show_ads = false;
  20.             jso.user_ip = "127.0.0.1";
  21.             jso.modified = true;
  22.             url.searchParams.set('token', JSON.stringify(jso));
  23.             return url.toString();
  24.         }
  25.         return null;
  26.       }
  27.  
  28.     let originalOpen = XMLHttpRequest.prototype.open;
  29.     XMLHttpRequest.prototype.open = function(method, url) {
  30.         this._url = url;
  31.         return originalOpen.apply(this, arguments);
  32.     };
  33.    
  34.     let originalSend = XMLHttpRequest.prototype.send;
  35.     XMLHttpRequest.prototype.send = function(data) {
  36.         var resp = originalSend.call(this, data);
  37.        
  38.         if (this._url && this._url.includes("adsystem")) {
  39.             console.log("ABORTING AD REQUEST");
  40.             this.abort();
  41.         }
  42.         return resp;
  43.     };
  44.  
  45.     let originalFetch = window.fetch;
  46.     window.fetch = function(resource, options) {
  47.         const args = arguments
  48.         var url = resource instanceof Request ? resource.url : resource
  49.         const method = options != null ? options.method : 'GET'
  50.         var body = options != null ? options.body : null
  51.         const referrer = options != null ? options.referrer : null
  52.  
  53.         if (url.includes("/access_token")) {
  54.             url = url.replace("player_type=site", "player_type=thunderdome");
  55.             console.log("ACCESS TOKEN REKT");
  56.         } else if (
  57.             url.includes("gql") && body.includes("PlaybackAccessToken")
  58.         ) {
  59.             const newBody = JSON.parse(body);
  60.             newBody.variables.playerType = "thunderdome";
  61.             body = JSON.stringify(newBody);
  62.         }
  63.  
  64.         return new Promise(function(resolve, reject) {
  65.             originalFetch.apply(this, args)
  66.             .then(function(response) {
  67.                 resolve(response);
  68.             })
  69.             .catch(function(error) {
  70.                 reject(error);
  71.             })
  72.         });
  73.     };
  74.  
  75.     function kill_ad(node, src) {
  76.         if (src.includes("blob")) {
  77.             console.log(node.duration !== node.duration ? 0.0 : node.duration);
  78.  
  79.             var timer = setInterval(function() {
  80.                 node.currentTime += 1.0;
  81.  
  82.                 //Need a better way to get the duration of the ad
  83.                 //rather than hardcoding or using REGEX..
  84.                 if (node.currentTime >= 13.0) {
  85.                     node.currentTime = 13.0;
  86.                     clearInterval(timer);
  87.                     console.log("DONE");
  88.                 }
  89.             }, 30);
  90.  
  91.             //node.currentTime = (node.duration !== node.duration ? 0.0 : node.duration);
  92.         } else {
  93.             console.log(src);
  94.         }
  95.     }
  96.  
  97.     function notifyNodeSource(node, src, mimeType) {
  98.         if (node == null) {
  99.             return;
  100.         }
  101.        
  102.         var name = node.title;
  103.         if (name == null || typeof name == 'undefined' || name == "") {
  104.             name = document.title;
  105.         }
  106.  
  107.         if (mimeType == null || typeof mimeType == 'undefined' || mimeType == "") {
  108.             if (node.constructor.name == 'HTMLVideoElement') {
  109.                 mimeType = 'video';
  110.             }
  111.  
  112.             if (node.constructor.name == 'HTMLAudioElement') {
  113.                 mimeType = 'audio';
  114.             }
  115.         }
  116.  
  117.         if (src != "") {
  118.             // Skip the video's currentTime
  119.             kill_ad(node, src);
  120.         }
  121.     }
  122.  
  123.     function notifyNode(node) {
  124.         notifyNodeSource(node, node.src, node.type);
  125.     }
  126.  
  127.     function observeNode(node) {
  128.         if (node.observer == null || node.observer === undefined) {
  129.             node.observer = new MutationObserver(function (mutations) {
  130.                 notifyNode(node);
  131.             });
  132.             node.observer.observe(node, { attributes: true, attributeFilter: ["src"] });
  133.             notifyNode(node);
  134.  
  135.             node.addEventListener('loadedmetadata', function() {
  136.                 notifyNode(node);
  137.             });
  138.         }
  139.     }
  140.  
  141.     function observeDocument(node) {
  142.         if (node.observer == null || node.observer === undefined) {
  143.             node.observer = new MutationObserver(function (mutations) {
  144.                 mutations.forEach(function (mutation) {
  145.                     mutation.addedNodes.forEach(function (node) {
  146.                         if (node.constructor.name == "HTMLVideoElement") {
  147.                             observeNode(node);
  148.                         }
  149.                         else if (node.constructor.name == "HTMLAudioElement") {
  150.                             observeNode(node);
  151.                         }
  152.                     });
  153.                 });
  154.             });
  155.             node.observer.observe(node, { subtree: true, childList: true });
  156.         }
  157.     }
  158.  
  159.     function observeDynamicElements(node) {
  160.         var original = node.createElement;
  161.         node.createElement = function (tag) {
  162.             if (tag === 'audio' || tag === 'video') {
  163.                 var result = original.call(node, tag);
  164.                
  165.                 /*Object.defineProperty(node, 'src', {
  166.                     get: function() {
  167.                         if (typeof this._props === 'undefined') {
  168.                             this._props = {};
  169.                             this._props.src = "";
  170.                         }
  171.                         return this._props.src;
  172.                     },
  173.                     set: function(val) {
  174.                         if (this.src === val) {
  175.                             return;
  176.                         }
  177.                         this._props.src = val;
  178.                     },
  179.                     configurable: true,
  180.                     writeable: true
  181.                 });*/
  182.                
  183.                 observeNode(result);
  184.                 notifyNode(result);
  185.                 return result;
  186.             }
  187.             return original.call(node, tag);
  188.         };
  189.     }
  190.  
  191.     function getAllVideoElements() {
  192.         return document.querySelectorAll('video');
  193.     }
  194.  
  195.     function getAllAudioElements() {
  196.         return document.querySelectorAll('audio');
  197.     }
  198.  
  199.     function onReady(fn) {
  200.         if (document.readyState === "complete" || document.readyState === "interactive") {
  201.             setTimeout(fn, 1);
  202.         } else {
  203.             document.addEventListener("DOMContentLoaded", fn);
  204.         }
  205.     }
  206.  
  207.     observeDynamicElements(document);
  208.     observeDocument(document);
  209. })();
  210.  
Add Comment
Please, Sign In to add comment