VGMLoaderX

Automatically downloads albums from KHInsider without an account.

目前为 2022-07-15 提交的版本。查看 最新版本

  1. // @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT
  2. /* eslint-env browser, greasemonkey */
  3. /* jshint asi: true, esversion: 11 */
  4. /* globals zip, saveAs */
  5.  
  6. // ==UserScript==
  7. // @name VGMLoaderX
  8. // @name:de VGMLoaderX
  9. // @name:en VGMLoaderX
  10. // @namespace TheLastZombie/userscripts
  11. // @version 1.0.10
  12. // @description Automatically downloads albums from KHInsider without an account.
  13. // @description:de Lädt Alben von KHInsider automatisch und ohne Account herunter.
  14. // @description:en Automatically downloads albums from KHInsider without an account.
  15. // @compatible chrome
  16. // @compatible edge
  17. // @compatible firefox
  18. // @compatible opera
  19. // @compatible safari
  20. // @homepageURL https://codeberg.org/sun/userscripts
  21. // @supportURL https://codeberg.org/sun/userscripts/issues/new
  22. // @contributionURL https://ko-fi.com/rcrsch
  23. // @contributionAmount €1.00
  24. // @author TheLastZombie <roesch.eric+userscripts@protonmail.com>
  25. // @include https://downloads.khinsider.com/game-soundtracks/album/*
  26. // @match https://downloads.khinsider.com/game-soundtracks/album/*
  27. // @connect vgmsite.com
  28. // @run-at document-end
  29. // @inject-into auto
  30. // @grant GM.xmlHttpRequest
  31. // @grant GM_xmlhttpRequest
  32. // @noframes
  33. // @require https://cdn.jsdelivr.net/gh/gildas-lormeau/zip.js@7949db15556ebdbd076e543fd77134286ad6e4fc/dist/zip.min.js
  34. // @require https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js@5bb701bd6ea05a02836daf8ef88ec350a1dd4d83/dist/FileSaver.min.js
  35. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  36. // @icon https://codeberg.org/sun/userscripts/raw/branch/main/icons/VGMLoaderX.ico
  37. // @copyright 2021-2022, TheLastZombie (https://eric.jetzt/)
  38. // @license MIT; https://codeberg.org/sun/userscripts/src/branch/main/LICENSE
  39. // ==/UserScript==
  40.  
  41. // ==OpenUserJS==
  42. // @author TheLastZombie
  43. // ==/OpenUserJS==
  44.  
  45. (function () {
  46. "use strict";
  47.  
  48. document.querySelectorAll('a[href^="/cp/add_album/"]').forEach((x) => {
  49. x.addEventListener("click", (e) => {
  50. e.preventDefault();
  51.  
  52. let format = Array(
  53. ...document.querySelectorAll("#songlist_header th[align=right]")
  54. ).map((x) => x.textContent);
  55. if (format.length === 1) {
  56. format = format[0];
  57. } else {
  58. const input = prompt(
  59. "Please enter your desired format (one of " +
  60. format.join(", ") +
  61. "):",
  62. format[0]
  63. );
  64. if (!format.includes(input.toUpperCase())) {
  65. format = format[0];
  66. alert("Invalid format supplied. Using " + format + " instead.");
  67. } else {
  68. format = input;
  69. }
  70. }
  71.  
  72. const element = document.getElementsByClassName("albumMassDownload")[0];
  73. element.style.height = "auto";
  74. element.style.marginBottom = "2em";
  75.  
  76. /* jshint ignore:start */
  77. // eslint-disable-next-line no-eval
  78. const input = eval(
  79. document
  80. .querySelector("#pageContent script")
  81. .textContent.slice(5, -3)
  82. .replace("function", "function x")
  83. .replace("return p}", "return p}x")
  84. );
  85. /* jshint ignore:end */
  86.  
  87. const mediaPath = input.match(/mediaPath='(.+?)'/)[1];
  88. const tracks = JSON.parse(
  89. input.match(/tracks=(\[.+?\])/)[1].replace(",]", "]")
  90. );
  91. const output = tracks.map(
  92. (x) =>
  93. mediaPath +
  94. x.file.split(".").slice(0, -1).join(".") +
  95. "." +
  96. format.toLowerCase()
  97. );
  98. const names = tracks.map((x) => x.name);
  99.  
  100. const blobWriter = new zip.BlobWriter("application/zip");
  101. const writer = new zip.ZipWriter(blobWriter);
  102.  
  103. function forSync(i) {
  104. element.innerHTML =
  105. "Downloading track " +
  106. (i + 1) +
  107. " of " +
  108. output.length +
  109. " (" +
  110. (names[i] || "Track " + (i + 1)) +
  111. ")…";
  112. GM.xmlHttpRequest({
  113. method: "GET",
  114. url: output[i],
  115. responseType: "blob",
  116. onload: async (response) => {
  117. await writer.add(
  118. decodeURIComponent(output[i].split("/").pop()),
  119. new zip.BlobReader(response.response)
  120. );
  121.  
  122. if (output[i + 1]) {
  123. forSync(i + 1);
  124. } else {
  125. await writer.close();
  126. const blob = await blobWriter.getData();
  127. saveAs(
  128. blob,
  129. document.getElementsByTagName("h2")[0].textContent + ".zip"
  130. );
  131. element.innerHTML =
  132. "Album successfully downloaded. ZIP file has been passed to the browser.";
  133. }
  134. },
  135. });
  136. }
  137. forSync(0);
  138. });
  139. });
  140. })();
  141.  
  142. // @license-end