Advertisement
kodish2

crunch

Aug 23rd, 2022
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.69 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Crunchyroll iFrame Player
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.3
  5.  
  6. // @description Este script Permite ver todos os vídeos do site crunchyroll gratuitamente. Nota(JarEd): Apenas modifiquei um pouco do código para UserScript, o código original já não é mais disponibilizado pelos desenvolvedores, contudo, só está aqui nessa comunidade pois o código está disponível na web em vários sites e ele é de domínio público, colocando em ênfase que não me beneficio com o mesmo.
  7.  
  8. // @author JarEdMaster
  9. // @license MIT
  10. // @match http://www.crunchyroll.com/*
  11. // @match https://www.crunchyroll.com/*
  12. // @icon https://www.crunchyroll.com/favicons/favicon-32x32.png
  13. // @grant GM_webRequest
  14. // @grant GM_addStyle
  15. // @grant GM.listValues
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @webRequest [{"selector":"*dg/dg.js*","action":"cancel"}]
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23.  
  24. var HTML = document.documentElement.innerHTML;
  25. var new_str;
  26. var ifrm;
  27. var width = 0;
  28.  
  29. function pegaString(str, first_character, last_character) {
  30. if(str.match(first_character + "(.*)" + last_character) == null){
  31. return null;
  32. }else{
  33. new_str = str.match(first_character + "(.*)" + last_character)[1].trim();
  34. return(new_str);
  35. }
  36. }
  37.  
  38. function optimize_for_mobile() {
  39.  
  40. console.log("[CR Premium] Optimizando página para mobile...");
  41. width = document.body.offsetWidth;
  42. var carousel_move_times = 0;
  43. var carousel_videos_count = 0;
  44. var carousel_arrow_limit = 0;
  45.  
  46. switch (true) {
  47. case (width < 622 && width > 506):
  48. carousel_move_times = 4;
  49. break;
  50. case (width < 506 && width > 390):
  51. carousel_move_times = 3;
  52. break;
  53. case (width < 390 && width > 274):
  54. carousel_move_times = 2;
  55. break;
  56. case (width < 274 && width > 0):
  57. carousel_move_times = 1;
  58. break;
  59. default:
  60. carousel_move_times = 5;
  61. }
  62. function getChildNodes(node) {
  63. var children = new Array();
  64. for(var child in node.childNodes) {
  65. if(node.childNodes[child].nodeName == "DIV" && node.childNodes[child].attributes.media_id != null) {
  66. children.push(child);
  67. }
  68. }
  69. return children;
  70. }
  71. carousel_videos_count = getChildNodes(document.body.querySelector('div.collection-carousel-scrollable'));
  72.  
  73. carousel_arrow_limit = Number(pegaString(
  74. document.body.querySelector('div.white-wrapper.container-shadow.large-margin-bottom').childNodes[3].innerHTML
  75. , "Math.min", ","
  76. ).replace("(", ""));
  77.  
  78. var carousel_script = document.body.querySelector('div.white-wrapper.container-shadow.large-margin-bottom').childNodes[3].innerText
  79. .replace(".data()['first_visible'] - 5", ".data()['first_visible'] - " + carousel_move_times)
  80. .replace(".data()['first_visible'] + 5", ".data()['first_visible'] + " + carousel_move_times)
  81. .replace("Math.min(" + carousel_arrow_limit + ",", "Math.min(" + (carousel_videos_count.length - carousel_move_times) + ",")
  82. .replace(".data()['first_visible'] < " + carousel_arrow_limit, ".data()['first_visible'] < " + (carousel_videos_count.length - carousel_move_times))
  83. .replace(".data()['first_visible'] >= " + carousel_arrow_limit, ".data()['first_visible'] >= " + (carousel_videos_count.length - carousel_move_times))
  84. .replace(".data()['first_visible'] >= " + carousel_arrow_limit, ".data()['first_visible'] >= " + (carousel_videos_count.length - carousel_move_times));
  85.  
  86. var old_element = document.querySelector(".collection-carousel-leftarrow");
  87. var new_element = old_element.cloneNode(true);
  88. old_element.parentNode.replaceChild(new_element, old_element);
  89.  
  90. old_element = document.querySelector(".collection-carousel-rightarrow");
  91. new_element = old_element.cloneNode(true);
  92. old_element.parentNode.replaceChild(new_element, old_element);
  93.  
  94. var head = document.getElementsByTagName('head')[0];
  95. var script = document.createElement('script');
  96. script.type = 'text/javascript';
  97. script.onload = function() {
  98. callFunctionFromScript();
  99. };
  100. script.text = carousel_script;
  101. head.appendChild(script);
  102.  
  103. if(document.getElementById('showmedia_video_box_wide') != null) {
  104. document.getElementById('showmedia_video_box_wide').id = 'showmedia_video_box';
  105. }
  106.  
  107. if(document.body.querySelector('div.collection-carousel-scrollable').lastElementChild.childNodes[1] != undefined) {
  108. if(document.body.querySelector('div.collection-carousel-scrollable').lastElementChild.childNodes[1].classList.value.indexOf('collection-carousel-media-link-current') == -1) {
  109. if(carousel_move_times == 4) {
  110. if(document.body.querySelector('div.collection-carousel-scrollable').lastElementChild.previousElementSibling.childNodes[1].classList.value.indexOf('collection-carousel-media-link-current') == -1) {
  111. document.body.querySelector('a.collection-carousel-rightarrow').classList = "collection-carousel-arrow collection-carousel-rightarrow";
  112. }
  113. }else{
  114. document.body.querySelector('a.collection-carousel-rightarrow').classList = "collection-carousel-arrow collection-carousel-rightarrow";
  115. }
  116. }else{
  117. if(carousel_move_times == 2){
  118. document.body.querySelector('a.collection-carousel-rightarrow').classList = "collection-carousel-arrow collection-carousel-rightarrow";
  119. }
  120. }
  121. }
  122. }
  123.  
  124.  
  125. function importPlayer() {
  126.  
  127. console.log("[CR Premium] Removendo player da Crunchyroll...");
  128. var elem = document.getElementById('showmedia_video_player');
  129. elem.parentNode.removeChild(elem);
  130.  
  131. console.log("[CR Premium] Pegando dados da stream...");
  132. var video_config_media = JSON.parse(pegaString(HTML, "vilos.config.media = ", ";"));
  133.  
  134. console.log("[CR Premium] Adicionando o jwplayer...");
  135. var ifrm = document.createElement("iframe");
  136. ifrm.setAttribute("id", "frame");
  137. ifrm.setAttribute("src", "https://mateus7g.github.io/crp-iframe-player/");
  138. ifrm.setAttribute("width","100%");
  139. ifrm.setAttribute("height","100%");
  140. ifrm.setAttribute("frameborder","0");
  141. ifrm.setAttribute("scrolling","no");
  142. ifrm.setAttribute("allowfullscreen","allowfullscreen");
  143. ifrm.setAttribute("allow","autoplay; encrypted-media *");
  144.  
  145.  
  146. if(document.body.querySelector("#showmedia_video_box") != null){
  147. document.body.querySelector("#showmedia_video_box").appendChild(ifrm);
  148. }else{
  149. document.body.querySelector("#showmedia_video_box_wide").appendChild(ifrm);
  150. }
  151.  
  152. if (document.body.querySelector(".freetrial-note") != null) {
  153. console.log("[CR Premium] Removendo Free Trial Note...");
  154. document.body.querySelector(".freetrial-note").style.display = "none";
  155. }
  156.  
  157. if(document.body.querySelector(".showmedia-trailer-notice") != null){
  158. console.log("[CR Premium] Removendo Trailer Notice...");
  159. document.body.querySelector(".showmedia-trailer-notice").style.textDecoration = "line-through";
  160. }
  161.  
  162. if(document.body.querySelector("#showmedia_free_trial_signup") != null){
  163. console.log("[CR Premium] Removendo Free Trial Signup...");
  164. document.body.querySelector("#showmedia_free_trial_signup").style.display = "none";
  165. }
  166.  
  167. var element = document.getElementById("template_scroller");
  168. if (element) element.click();
  169.  
  170. const series = document.querySelector('meta[property="og:title"]');
  171. const up_next = document.querySelector('link[rel=next]');
  172. ifrm.onload = function(){
  173. ifrm.contentWindow.postMessage({
  174. 'tampermonkey': true,
  175. 'video_config_media': [JSON.stringify(video_config_media)],
  176. 'lang': [pegaString(HTML, 'LOCALE = "', '",')],
  177. 'series': series ? series.content : undefined,
  178. 'up_next': up_next ? up_next.href : undefined,
  179. 'version': "2"
  180. },"*");
  181. };
  182.  
  183. console.log(video_config_media);
  184.  
  185. if(width < 796) {
  186. optimize_for_mobile();
  187. }
  188. }
  189.  
  190. function onloadfunction() {
  191.  
  192. if(window.location.href == "https://www.crunchyroll.com/interstitial/android") {
  193. window.location.href = "https://www.crunchyroll.com/interstitial/android?skip=1";
  194. }
  195.  
  196. var metaTag = document.createElement('meta');
  197. metaTag.name = "viewport"
  198. metaTag.content = "width=device-width, initial-scale=1.0, shrink-to-fit=no, user-scalable=no"
  199. document.getElementsByTagName('head')[0].appendChild(metaTag);
  200.  
  201. window.scrollTo(0, 0);
  202.  
  203. if(pegaString(HTML, "vilos.config.media = ", ";") != null){
  204. importPlayer();
  205. }
  206. }
  207. document.addEventListener("DOMContentLoaded", onloadfunction());
  208. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement