Guest User

Crunchyroll Premium Free

a guest
Mar 31st, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         crunchyroll_nosubs
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.3
  5. // @description  disable subs on crunchyroll by default
  6. // @author       mescyn
  7. // @match        https://www.crunchyroll.com/*
  8. // @grant        none
  9. // @run-at       document-start
  10. // ==/UserScript==
  11. (function() {
  12.     'use strict';
  13.     const Event = class {
  14.         constructor(script, target) {
  15.             this.script = script;
  16.             this.target = target;
  17.  
  18.             this._cancel = false;
  19.             this._replace = null;
  20.             this._stop = false;
  21.         }
  22.  
  23.         preventDefault() {
  24.             this._cancel = true;
  25.         }
  26.         stopPropagation() {
  27.             this._stop = true;
  28.         }
  29.         replacePayload(payload) {
  30.             this._replace = payload;
  31.         }
  32.     };
  33.  
  34.     let callbacks = [];
  35.     window.addBeforeScriptExecuteListener = (f) => {
  36.         if (typeof f !== "function") {
  37.             throw new Error("Event handler must be a function.");
  38.         }
  39.         callbacks.push(f);
  40.     };
  41.     window.removeBeforeScriptExecuteListener = (f) => {
  42.         let i = callbacks.length;
  43.         while (i--) {
  44.             if (callbacks[i] === f) {
  45.                 callbacks.splice(i, 1);
  46.             }
  47.         }
  48.     };
  49.  
  50.     const dispatch = (script, target) => {
  51.         if (script.tagName !== "SCRIPT") {
  52.             return;
  53.         }
  54.  
  55.         const e = new Event(script, target);
  56.  
  57.         if (typeof window.onbeforescriptexecute === "function") {
  58.             try {
  59.                 window.onbeforescriptexecute(e);
  60.             } catch (err) {
  61.                 console.error(err);
  62.             }
  63.         }
  64.  
  65.         for (const func of callbacks) {
  66.             if (e._stop) {
  67.                 break;
  68.             }
  69.             try {
  70.                 func(e);
  71.             } catch (err) {
  72.                 console.error(err);
  73.             }
  74.         }
  75.  
  76.         if (e._cancel) {
  77.             script.textContent = "";
  78.             script.remove();
  79.         } else if (typeof e._replace === "string") {
  80.             script.textContent = e._replace;
  81.         }
  82.     };
  83.     const observer = new MutationObserver((mutations) => {
  84.         for (const m of mutations) {
  85.             for (const n of m.addedNodes) {
  86.                 dispatch(n, m.target);
  87.             }
  88.         }
  89.     });
  90.     observer.observe(document, {
  91.         childList: true,
  92.         subtree: true,
  93.     });
  94.     window.onbeforescriptexecute = (e) => {
  95.         if (!e.script.textContent) {
  96.             return;
  97.         }
  98.         if (e.script.textContent.includes("vilos.config.player.language =")) {
  99.             var newscript = e.script.textContent;
  100.  
  101.             newscript = newscript.replace(/\\\/clipFrom\\\/[0-9]+\\\/clipTo\\\/[0-9]+/g, '');
  102.             e.replacePayload(newscript);
  103.         }
  104.     }
  105. })();
Add Comment
Please, Sign In to add comment