Advertisement
Guest User

crunchyroll tamper monkey changes

a guest
Aug 21st, 2019
8,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          Spoiler-free Crunchyroll
  3. // @description   Hide name and description of episodes
  4. // @author        TimeBomb
  5. // @namespace     https://greasyfork.org/users/160017
  6. // @version       0.3
  7. // @copyright     2018
  8. // @run-at        document-start
  9. // @match         https://www.crunchyroll.com/*
  10. // ==/UserScript==
  11.  
  12. // USER CONFIGS BEGIN
  13. var USER_CONFIG = {
  14.     // Filter for series episode listing pages (e.g. http://www.crunchyroll.com/naruto-shippuden)
  15.     FILTER_EPISODES: {
  16.         EPISODE_IMAGES: true, // true: Hide episode images
  17.         EPISODE_NAMES: true, // true: Hide episode names
  18.         EPISODE_HOVER: true, // true: Hide tooltip showing episode names and descriptions on hover
  19.     },
  20.  
  21.     // Filter for your Queue page (http://www.crunchyroll.com/home/queue)
  22.     FILTER_MY_QUEUE: {
  23.         EPISODE_IMAGES: true, // true: Hide episode images on main queue page
  24.         EPISODE_NAME: true, // true: Hide episode name
  25.         EPISODE_DESCRIPTION: true, // Hide episode description
  26.         EPISODES_CAROUSEL_IMAGES: true, // true: Hide images on series episode carousel (when clicking down arrow)
  27.         EPISODES_CAROUSEL_NAME: true, // true: Hide episode name on series episode carousel
  28.         EPISODES_CAROUSEL_HOVER: true, // true: Hide tooltip showing episode name and description when hovering over episode on series episode carousel
  29.     },
  30.  
  31.     // Filter for episode player pages (e.g. http://www.crunchyroll.com/rwby/episode-1-ruby-rose-643525)
  32.     FILTER_EPISODE_PLAYER: {
  33.         EPISODE_NAME: true, // true: Hide episode name in title above player and right sidebar below player
  34.         EPISODE_DESCRIPTION: true, // true: Hide episode description in right sidebar below player
  35.         EPISODES_CAROUSEL_IMAGES: true, // true: Hide images on episode carousel below player
  36.         EPISODES_CAROUSEL_NAME: true, // true: Hide episode names on episode carousel
  37.         EPISODES_CAROUSEL_HOVER: true, // true: Hide tooltip showing episode name and description when hovering over episode on episode carousel
  38.     }
  39. };
  40. // USER CONFIGS END, DO NOT EDIT ANYTHING BELOW
  41.  
  42. var DEBUG = false;
  43. var EPISODE_DELIMITER= '–'; // Not a normal hyphen, sometimes part of episode title+number, used for truncating episode title
  44. var QUEUE_URI = '/home/queue';
  45. var PAGES = {
  46.     EPISODES: 'EPISODES',
  47.     QUEUE: 'QUEUE',
  48.     PLAYER: 'PLAYER',
  49. };
  50.  
  51. // We very briefly hide the <html> tag here, to ensure the user doesn't see unfiltered content
  52. // The performance impact of applying our custom CSS is so minimal that users shouldn't notice this
  53. // Once we finish applying our CSS below, we show the page and apply some final filters to truncate episode names that contain the episode number or link
  54. document.documentElement.style.display = 'none';
  55.  
  56. var currentPage;
  57. var currentPath = window.location.pathname;
  58. var currentPathChunksLength = currentPath.split('/').length;
  59. // We could check the DOM to further identify the page, but we don't want to hamper performance; this is good enough. False positives shouldn't matter.
  60. if (currentPathChunksLength === 3) {
  61.     currentPage = PAGES.EPISODES;
  62. } else if (currentPath === QUEUE_URI) {
  63.     currentPage = PAGES.QUEUE;
  64. } else if (currentPathChunksLength === 4) {
  65.     currentPage = PAGES.PLAYER;
  66. }
  67.  
  68. // Developer Note:
  69. // We are extra performant because most of our filters are just CSS we apply to the <head> prior to loading.
  70. // We avoid jQuery and try to avoid function calls for performance's sake.
  71. // Previous, less optimized versions of this script noticably slowed down the page; our performance is great as of 0.3 though.
  72. // Super fragile custom CSS incoming, good luck if Crunchyroll changes their DOM.
  73.  
  74. if (currentPage === PAGES.EPISODES) {
  75.     var cssE = '';
  76.  
  77.     if (USER_CONFIG.FILTER_EPISODES.EPISODE_IMAGES) {
  78.         cssE = cssE + '.episode img { visibility: hidden }';
  79.     }
  80.  
  81.     if (USER_CONFIG.FILTER_EPISODES.EPISODE_NAMES) {
  82.         cssE = cssE + '.episode .short-desc { visibility: hidden }';
  83.     }
  84.  
  85.     if (USER_CONFIG.FILTER_EPISODES.EPISODE_HOVER) {
  86.         cssE = cssE + '.portrait-bubble { visibility: hidden }';
  87.     }
  88.  
  89.     try {
  90.         var $newStyleE = document.createElement('style');
  91.         var cssNodeE = document.createTextNode(cssE);
  92.         $newStyleE.appendChild(cssNodeE);
  93.         document.head.appendChild($newStyleE);
  94.     } catch (e) {
  95.         if (DEBUG) {
  96.             console.error('Episodes CSS Error:', e);
  97.         }
  98.     }
  99. }
  100.  
  101. if (currentPage === PAGES.QUEUE) {
  102.     var cssQ = '';
  103.  
  104.     // We hide the entire episode name and number, and add back in the episode number below, once the DOM loads
  105.     if (USER_CONFIG.FILTER_MY_QUEUE.EPISODE_NAME) {
  106.         cssQ = cssQ + '.episode .series-data { visibility: hidden }';
  107.     }
  108.  
  109.     if (USER_CONFIG.FILTER_MY_QUEUE.EPISODE_DESCRIPTION) {
  110.         cssQ = cssQ + '.episode .short-desc { visibility: hidden }';
  111.     }
  112.  
  113.     if (USER_CONFIG.FILTER_MY_QUEUE.EPISODE_IMAGES) {
  114.         cssQ = cssQ + '.episode img { visibility: hidden }';
  115.     }
  116.  
  117.     if (USER_CONFIG.FILTER_MY_QUEUE.EPISODES_CAROUSEL_HOVER) {
  118.         cssQ = cssQ + '.portrait-bubble { visibility: hidden }';
  119.     }
  120.  
  121.     if (USER_CONFIG.FILTER_MY_QUEUE.EPISODES_CAROUSEL_IMAGES) {
  122.         cssQ = cssQ + '.mug { visibility: hidden }';
  123.     }
  124.  
  125.     if (USER_CONFIG.FILTER_MY_QUEUE.EPISODES_CAROUSEL_NAME) {
  126.         cssQ = cssQ + '.collection-carousel-overlay-bottom { visibility: hidden }';
  127.     }
  128.  
  129.     try {
  130.         var $newStyleQ = document.createElement('style');
  131.         var cssNodeQ = document.createTextNode(cssQ);
  132.         $newStyleQ.appendChild(cssNodeQ);
  133.         document.head.appendChild($newStyleQ);
  134.     } catch (e) {
  135.         if (DEBUG) {
  136.             console.error('My Queue Filter Issue:', e);
  137.         }
  138.     }
  139. }
  140.  
  141. if (currentPage === PAGES.PLAYER) {
  142.     var cssP = '';
  143.  
  144.     if (USER_CONFIG.FILTER_EPISODE_PLAYER.EPISODES_CAROUSEL_NAME) {
  145.         cssP = cssP + '.collection-carousel-overlay-bottom { visibility: hidden }';
  146.     }
  147.  
  148.     if (USER_CONFIG.FILTER_EPISODE_PLAYER.EPISODES_CAROUSEL_IMAGES) {
  149.         cssP = cssP + '.collection-carousel-media-thumb img { visibility: hidden }';
  150.     }
  151.  
  152.     if (USER_CONFIG.FILTER_EPISODE_PLAYER.EPISODES_CAROUSEL_HOVER) {
  153.         cssP = cssP + '.portrait-bubble { visibility: hidden }';
  154.     }
  155.  
  156.     if (USER_CONFIG.FILTER_EPISODE_PLAYER.EPISODE_NAME) {
  157.         cssP = cssP + 'h1.ellipsis { visibility: hidden }' +
  158.             '#showmedia_about_name { visibility: hidden }';
  159.     }
  160.  
  161.     if (USER_CONFIG.FILTER_EPISODE_PLAYER.EPISODE_DESCRIPTION) {
  162.         cssP = cssP + '.description.medium-margin-bottom { visibility: hidden}';
  163.     }
  164.  
  165.     try {
  166.         var $newStyleP = document.createElement('style');
  167.         var cssNodeP = document.createTextNode(cssP);
  168.         $newStyleP.appendChild(cssNodeP);
  169.         document.head.appendChild($newStyleP);
  170.     } catch (e) {
  171.         if (DEBUG) {
  172.             console.error('Episode Player Filter Issue:', e);
  173.         }
  174.     }
  175. }
  176.  
  177. document.documentElement.style.display = '';
  178.  
  179. // This is faster than any sort of window.onload, as that waits for all scripts/images/etc to be loaded
  180. // where this is only waiting for the literal HTML to be loaded into the DOM
  181. document.addEventListener('DOMContentLoaded', function () {
  182.     if (currentPage === PAGES.QUEUE) {
  183.         try {
  184.             // Truncate episode name but keep episode number
  185.             if (USER_CONFIG.FILTER_MY_QUEUE.EPISODE_NAME) {
  186.                 var $episodesQ = document.getElementsByClassName('episode');
  187.                 var episodesLengthQ = $episodesQ.length;
  188.                 for (var q1 = 0; q1 < episodesLengthQ; q1++) {
  189.                     var $episodeQ = $episodesQ[q1];
  190.                     var $titleQ = $episodeQ.getElementsByClassName('series-data')[0];
  191.                     var textQ = $titleQ.innerHTML;
  192.                     var textTruncateIndexQ = textQ.indexOf(EPISODE_DELIMITER);
  193.                     if (textTruncateIndexQ > -1) {
  194.                         $titleQ.innerHTML = textQ.substr(0, textTruncateIndexQ);
  195.                     }
  196.  
  197.                     $titleQ.style.visibility = 'visible';
  198.                 }
  199.             }
  200.         } catch (e) {
  201.             console.error('My Queue DOM-Loaded Filter Issue:', e);
  202.         }
  203.     }
  204.  
  205.     if (currentPage === PAGES.PLAYER) {
  206.         try {
  207.             if (USER_CONFIG.FILTER_EPISODE_PLAYER.EPISODE_NAME) {
  208.                 // Hide episode name in title above player
  209.                 var $h1s = document.getElementsByTagName('h1');
  210.                 var h1sLen = $h1s.length;
  211.                 for (var p1 = 0; p1 < h1sLen; p1++) {
  212.                     var $h1 = $h1s[p1];
  213.                     if (!$h1.classList.contains('ellipsis')) {
  214.                         continue;
  215.                     }
  216.  
  217.                     var textP = $h1.innerHTML;
  218.                     if (!textP) {
  219.                         continue; // Slightly ugly way to handle errors, should clean this up...
  220.                     }
  221.                     var textTruncateIndexP = textP.indexOf(EPISODE_DELIMITER);
  222.                     if (textTruncateIndexP > -1) {
  223.                         $h1.innerHTML = textP.substr(0, textTruncateIndexP);
  224.                     }
  225.  
  226.                     $h1.style.visibility = 'visible';
  227.                 }
  228.             }
  229.         } catch (e) {
  230.             if (DEBUG) {
  231.                 console.error('Episode Player DOM-Loaded Filter Issue:', e);
  232.             }
  233.         }
  234.     }
  235. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement