crunchyroll_no_free

enable subs on crunchyroll by default

  1. // ==UserScript==
  2. // @name crunchyroll_no_free
  3. // @version 0.1
  4. // @description enable subs on crunchyroll by default
  5. // @author crts
  6. // @match https://www.crunchyroll.com/*
  7. // @grant none
  8. // @run-at document-start
  9. // @namespace https://gf.qytechs.cn/users/675256
  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 profilelang = e.script.textContent.match(/vilos\.config\.player\.language = \"(.*)\"/m)[1];
  100. var newscript = e.script.textContent;
  101. newscript = newscript.replace(/\\\/clipFrom\\\/[0-9]+\\\/clipTo\\\/[0-9]+/g, '');
  102. e.replacePayload(newscript);
  103. }
  104. }
  105. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址