BH3_wallpapers

崩坏3壁纸批量下载

  1. // ==UserScript==
  2. // @name BH3_wallpapers
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.00
  5. // @description 崩坏3壁纸批量下载
  6. // @author backrock12
  7. // @match https://www.bh3.com/wallpapers
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=bh3.com
  9. // @grant GM_download
  10. // @grant GM_xmlhttpRequest
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. "use strict";
  16.  
  17. async function gethtml(url) {
  18. return new Promise((resolve, reject) => {
  19. GM_xmlhttpRequest({
  20. url: url,
  21. method: "GET",
  22. onload: function (response) {
  23. resolve(response.responseText);
  24. },
  25. });
  26. });
  27. }
  28.  
  29. async function GET_JSON() {
  30. const url =
  31. "https://www.bh3.com/content/bh3Cn/getContentList?pageSize=9999&pageNum=1&channelId=177";
  32. const jsontext = await gethtml(url);
  33.  
  34. var json = JSON.parse(jsontext);
  35. console.log(json);
  36.  
  37. const list = json.data.list;
  38. if (!list) alert("LIST is null");
  39.  
  40. console.log(list);
  41.  
  42. let oknum = 0;
  43. let errornum = 0;
  44.  
  45. for (let i = 0; i < list.length; i++) {
  46. const url = list[i].ext[0].value[0].url;
  47. const ext = list[i].ext[0].value[0].name;
  48. const name = list[i].ext[1].value;
  49.  
  50. if (!url) alert("url is null");
  51.  
  52. const title = name + ext.substring(ext.lastIndexOf("."));
  53. console.log(url);
  54. console.log(title);
  55.  
  56. GM_download({
  57. url: url,
  58. name: title,
  59. onerror: (error) => {
  60. errornum++;
  61. console.log("error",url);
  62. console.log("error",error);
  63. },
  64. onload: () => {
  65. oknum++;
  66. },
  67. });
  68. }
  69.  
  70. const time = list.length > 20 ? 2000 : 1000;
  71.  
  72. const IntervalId = setInterval(() => {
  73. if (list.length == oknum + errornum) {
  74. const msg = `下载完成,共${list.length}个文件,成功${oknum},失败${errornum}`;
  75. alert(msg);
  76. clearInterval(IntervalId);
  77. }
  78. }, time);
  79. }
  80.  
  81. function all_down() {
  82. //按键ID
  83. const h1_id = ".paper-pagination";
  84. const h1 = document.querySelector(h1_id);
  85. console.log(h1);
  86. if (!h1) {
  87. console.log(" h1 is null ");
  88. }
  89.  
  90. //创建按钮
  91. const ce = document.createElement("button");
  92. ce.id = "CDownBtn";
  93. ce.textContent = "全部下载";
  94. ce.className = "btn btn-md btn-default";
  95. ce.onclick = function () {
  96. //down_all();
  97. GET_JSON();
  98. };
  99. h1.append(ce);
  100. }
  101.  
  102. function add_down() {
  103. console.log("add_down");
  104.  
  105. //按键ID
  106. const h1_id = ".paper-pagination";
  107. const h1 = document.querySelector(h1_id);
  108. console.log(h1);
  109. if (!h1) {
  110. console.log(" h1 is null ");
  111. }
  112.  
  113. //创建按钮
  114. const ce = document.createElement("button");
  115. ce.id = "CDownBtn";
  116. ce.textContent = "本页下载";
  117. ce.className = "btn btn-md btn-default";
  118. ce.onclick = function () {
  119. down_all();
  120. };
  121. h1.append(ce);
  122.  
  123. //下载事件
  124. async function down_all() {
  125. // url
  126. const list = document.querySelectorAll(".paper-item a");
  127. console.log(list);
  128.  
  129. const tlist = document.querySelectorAll(".paper-item div");
  130. console.log(tlist);
  131.  
  132. let oknum = 0;
  133. let errornum = 0;
  134.  
  135. for (let i = 0; i < list.length; i++) {
  136. const url = list[i].href;
  137. const name = tlist[i].innerText + ".jpg"; //.replace(".", "_");
  138. GM_download({
  139. url: url,
  140. name: name,
  141. onerror: (error) => {
  142. errornum++;
  143. console.log("error",url);
  144. console.log("error",error);
  145. },
  146. onload: () => {
  147. oknum++;
  148. },
  149. });
  150. }
  151.  
  152. const time = list.length > 20 ? 2000 : 1000;
  153.  
  154. const IntervalId = setInterval(() => {
  155. if (list.length == oknum + errornum) {
  156. const msg = `下载完成,共${list.length}个文件,成功${oknum},失败${errornum}`;
  157. alert(msg);
  158. clearInterval(IntervalId);
  159. }
  160. }, time);
  161. }
  162. }
  163.  
  164. all_down();
  165. add_down();
  166. })();

QingJ © 2025

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