[Closed Test] AMQ Accelerate Loading

Load media faster from alternative sources.

  1. // ==UserScript==
  2. // @name [Closed Test] AMQ Accelerate Loading
  3. // @namespace https://github.com/SlashNephy
  4. // @version 0.2.1
  5. // @author SlashNephy
  6. // @description Load media faster from alternative sources.
  7. // @description:ja メディアを代替ソースから高速にロードします。
  8. // @homepage https://scrapbox.io/slashnephy/AMQ_Accelerate_Loading
  9. // @homepageURL https://scrapbox.io/slashnephy/AMQ_Accelerate_Loading
  10. // @icon https://animemusicquiz.com/favicon-32x32.png
  11. // @supportURL https://github.com/SlashNephy/userscripts/issues
  12. // @match https://animemusicquiz.com/*
  13. // @require https://cdn.jsdelivr.net/gh/TheJoseph98/AMQ-Scripts@b97377730c4e8553d2dcdda7fba00f6e83d5a18a/common/amqScriptInfo.js
  14. // @grant none
  15. // @license MIT license
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. 'use strict';
  20.  
  21. const awaitFor = async (predicate, timeout) => new Promise((resolve, reject) => {
  22. let timer;
  23. const interval = window.setInterval(() => {
  24. if (predicate()) {
  25. clearInterval(interval);
  26. clearTimeout(timer);
  27. resolve();
  28. }
  29. }, 500);
  30. if (timeout !== undefined) {
  31. timer = window.setTimeout(() => {
  32. clearInterval(interval);
  33. clearTimeout(timer);
  34. reject(new Error('timeout'));
  35. }, timeout);
  36. }
  37. });
  38.  
  39. const onReady = (callback) => {
  40. if (document.getElementById('startPage')) {
  41. return;
  42. }
  43. awaitFor(() => document.getElementById('loadingScreen')?.classList.contains('hidden') === true)
  44. .then(callback)
  45. .catch(console.error);
  46. };
  47.  
  48. const proxyHost = 'https://amq-proxy.starry.blue';
  49. async function checkSession() {
  50. try {
  51. const response = await fetch(`${proxyHost}/healthcheck`, {
  52. redirect: 'error',
  53. mode: 'cors',
  54. credentials: 'include',
  55. });
  56. return response.ok;
  57. }
  58. catch (e) {
  59. return false;
  60. }
  61. }
  62. function replaceUrl(url) {
  63. return `${proxyHost}/api/media?u=${encodeURIComponent(url)}`;
  64. }
  65. onReady(async () => {
  66. const isAuthenticated = await checkSession();
  67. if (!isAuthenticated) {
  68. setTimeout(() => {
  69. void swal({
  70. title: 'AMQ Accelerate Loading',
  71. text: 'この UserScript を使用するにはユーザ認証が必要です。認証後、AMQ に再度ログインしてください。',
  72. confirmButtonText: '認証',
  73. showCancelButton: true,
  74. cancelButtonText: 'キャンセル',
  75. allowOutsideClick: false,
  76. focusConfirm: true,
  77. showCloseButton: false,
  78. allowEscapeKey: false,
  79. }).then(() => {
  80. window.location.replace(proxyHost);
  81. });
  82. }, 5000);
  83. return;
  84. }
  85. else {
  86. popoutMessages.displayStandardMessage('AMQ Accelerate Loading', '認証成功! UserScript は正常に動作しています。');
  87. }
  88. const { getNextVideoId } = MoeVideoPlayer.prototype;
  89. MoeVideoPlayer.prototype.getNextVideoId = function () {
  90. const url = getNextVideoId.apply(this);
  91. if (!url) {
  92. return undefined;
  93. }
  94. return replaceUrl(url);
  95. };
  96. const { showVideoPreview } = ExpandQuestionBox.prototype;
  97. ExpandQuestionBox.prototype.showVideoPreview = function (url, ...args) {
  98. if (url) {
  99. showVideoPreview.apply(this, [replaceUrl(url), ...args]);
  100. }
  101. else {
  102. showVideoPreview.apply(this, [url, ...args]);
  103. }
  104. };
  105. AMQ_addScriptData({
  106. name: '[Closed Test] Accelerate Loading',
  107. author: 'SlashNephy <spica@starry.blue>',
  108. description: 'Load media faster from alternative sources.',
  109. });
  110. });
  111.  
  112. })();

QingJ © 2025

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