Greasy Fork镜像 支持简体中文。

画世界下载原图

从画世界网页版(PC端UA)下载原图的脚本

  1. // ==UserScript==
  2. // @name 画世界下载原图
  3. // @name:zh-CN 画世界下载原图
  4. // @namespace 画世界下载原图
  5. // @homepage https://gist.github.com/kaixinol/a7521662de470d427db2eb9d45cd843e/
  6. // @version 0.4
  7. // @license MIT
  8. // @description:zh-cn 从画世界网页版(PC端UA)下载原图的脚本
  9. // @description 从画世界网页版(PC端UA)下载原图的脚本
  10. // @author Kaesinol
  11. // @match https://*.huashijie.art/work/detail/*
  12. // @grant GM_xmlhttpRequest
  13. // @grant GM_download
  14. // @connect app.huashijie.art
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. "use strict";
  19.  
  20. // 存储拦截到的图片URL和作品信息
  21. let interceptedImages = [];
  22. let workInfo = null;
  23.  
  24. // 获取作品ID
  25. function getWorkId() {
  26. const path = window.location.pathname;
  27. return path.split("/").pop();
  28. }
  29.  
  30. // 获取文件扩展名
  31. function getFileExtension(url) {
  32. const match = url.match(/\.([^.]+)(?:\?|$)/);
  33. return match ? match[1].toLowerCase() : "jpg";
  34. }
  35.  
  36. // 从API获取作品信息
  37. async function fetchWorkInfo(workId) {
  38. return new Promise((resolve, reject) => {
  39. GM_xmlhttpRequest({
  40. method: "GET",
  41. url: `https://app.huashijie.art/api/work/detailV2?workId=${workId}`,
  42. headers: {
  43. Accept: "application/json",
  44. },
  45. onload: function (response) {
  46. try {
  47. const data = JSON.parse(response.responseText);
  48. if (data && data.data) {
  49. resolve(data.data);
  50. } else {
  51. reject("Invalid API response");
  52. }
  53. } catch (e) {
  54. reject(e);
  55. }
  56. },
  57. onerror: reject,
  58. });
  59. });
  60. }
  61.  
  62. // 拦截 canvas.drawImage()
  63. const originalDrawImage = CanvasRenderingContext2D.prototype.drawImage;
  64. CanvasRenderingContext2D.prototype.drawImage = function (img, ...args) {
  65. if (
  66. img instanceof HTMLImageElement &&
  67. !interceptedImages.includes(img.src)
  68. ) {
  69. interceptedImages.push(img.src);
  70. console.log("Intercepted image:", img.src);
  71. }
  72. return originalDrawImage.apply(this, [img, ...args]);
  73. };
  74.  
  75. // 添加下载按钮
  76. async function addDownloadButton() {
  77. const likeButton = document.querySelector(".common-like.click-hover");
  78. if (!likeButton) {
  79. setTimeout(addDownloadButton, 1000);
  80. return;
  81. }
  82.  
  83. // 获取作品信息
  84. const workId = getWorkId();
  85. try {
  86. workInfo = await fetchWorkInfo(workId);
  87. } catch (error) {
  88. console.error("Failed to fetch work info:", error);
  89. }
  90.  
  91. const downloadButton = document.createElement("button");
  92. downloadButton.textContent = "下载图片";
  93. downloadButton.style.cssText = `
  94. margin-left: 10px;
  95. padding: 5px 10px;
  96. background-color: #4CAF50;
  97. color: white;
  98. border: none;
  99. border-radius: 4px;
  100. cursor: pointer;
  101. `;
  102.  
  103. downloadButton.addEventListener("click", async () => {
  104. if (interceptedImages.length === 0) {
  105. alert("未检测到图片,请先浏览作品");
  106. return;
  107. }
  108.  
  109. if (!workInfo) {
  110. alert("未能获取作品信息,将使用默认文件名");
  111. }
  112.  
  113. let filename = null;
  114. for (let i = 0; i < interceptedImages.length; i++) {
  115. const url = interceptedImages[i];
  116. const extension = getFileExtension(url);
  117. if (!workInfo) {
  118. filename = `${Date.now()} - ${i + 1}.${extension}`;
  119. } else {
  120. filename = `${workInfo.user.nick} - ${workInfo.id} - ${
  121. workInfo.userId
  122. } - ${i + 1}.${extension}`;
  123. }
  124.  
  125. GM_download({
  126. url: url,
  127. name: filename,
  128. saveAs: false,
  129. onerror: (error) => {
  130. console.error("Download failed:", error);
  131. alert(`下载失败: ${error}`);
  132. },
  133. });
  134. }
  135. console.log(`开始下载 ${interceptedImages.length} 张图片`);
  136. });
  137.  
  138. likeButton.parentNode.insertBefore(downloadButton, likeButton.nextSibling);
  139. }
  140.  
  141. // 页面加载完成后添加按钮
  142. window.addEventListener("load", addDownloadButton);
  143. })();

QingJ © 2025

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