gbtGame_Tool

GBT网站资源获取查询

  1. // ==UserScript==
  2. // @name gbtGame_Tool
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.1
  5. // @description GBT网站资源获取查询
  6. // @author byhgz
  7. // @license GNU GPLv3
  8. // @match http://gbtgame.ysepan.com/
  9. // @require https://gf.qytechs.cn/scripts/462234-message/code/Message.js?version=1170653
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=lanzouw.com
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_registerMenuCommand
  14. // ==/UserScript==
  15.  
  16. //对Qmsg工具进行二次封装
  17. const Tip = {
  18. success(text, config) {
  19. Qmsg.success(text, config);
  20. },
  21. info(text, config) {
  22. Qmsg.info(text, config);
  23. },
  24. error(text, config) {
  25. Qmsg.error(text, config);
  26. },
  27. loading(text, config) {
  28. return Qmsg.loading(text, config);
  29. },
  30. close(loading) {
  31. try {
  32. loading.close();
  33. } catch (e) {
  34. console.error(e);
  35. this.error("loading关闭失败!");
  36. }
  37. }
  38. };
  39.  
  40.  
  41. const Util = {
  42. /**
  43. * @returns {string} url
  44. */
  45. getWindowUrl() {
  46. return window.location.href;
  47. },
  48. /**
  49. * 导出文件
  50. * @param {String}content 内容
  51. * @param {String}fileName 文件名
  52. */
  53. fileDownload(content, fileName) {
  54. // 获取导出文件内容
  55. // 创建隐藏的下载文件链接
  56. const element = document.createElement('a');
  57. element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content));
  58. element.setAttribute('download', fileName);
  59. element.style.display = 'none';
  60. document.body.appendChild(element);
  61. // 手动触发下载
  62. element.click();
  63. // 清理dom
  64. document.body.removeChild(element);
  65. },
  66. /**
  67. *注册(不可用)一个菜单并返回菜单id,可在插件中点击油猴时看到对应脚本的菜单
  68. * @param {string}text 显示文本
  69. * @param {function}func 事件
  70. * @param {string}shortcutKey 快捷键
  71. * @return menu 菜单id
  72. */
  73. addGMMenu(text, func, shortcutKey = null) {
  74. return GM_registerMenuCommand(text, func, shortcutKey);
  75. },
  76. /**
  77. * 返回当前时间
  78. * @returns {String}
  79. */
  80. toTimeString() {
  81. return new Date().toLocaleString();
  82. },
  83. };
  84.  
  85.  
  86. const GBTGame = {
  87. data: {
  88. tempDataList: []
  89. },
  90. //验证数据
  91. verifyData() {
  92. if (this.data.tempDataList.length === 0) {
  93. const info = "请先获取页面所有游戏资源先!";
  94. Tip.error(info);
  95. alert(info);
  96. throw Error(info);
  97. }
  98. },
  99. init() {//初始化页面资源信息,用于获取资源操作
  100. if (!Util.getWindowUrl().includes("http://gbtgame.ysepan.com")) {
  101. alert("当前网站不是GBT乐赏游戏空间");
  102. return;
  103. }
  104. const loading = Tip.loading("正在获取中,请不要对当前网页进行其他操作!");
  105. const arrList = document.querySelectorAll("#menuList>*");
  106. let chickTempIndex = 0;
  107. this.data.tempDataList = [];
  108. const interval = setInterval(() => {
  109. if (arrList.length <= chickTempIndex) {
  110. loading.close();
  111. clearInterval(interval);
  112. alert("已点击完成!现在可以对资源进行获取和查找从操作了。ps:每次访问当前页面都需要初始化!");
  113. return;
  114. }
  115. const tempE = arrList[chickTempIndex++];
  116. const a = tempE.querySelector("a");
  117. const filesTime = a.text;
  118. a.click();
  119. const info = `已点击${filesTime}`;
  120. Tip.success(info);
  121. const p = new Promise((resolve) => {
  122. const interval01 = setInterval(() => {
  123. let menuItem = tempE.querySelectorAll(".menu>*:not(.lxts)");
  124. if (menuItem.length <= 1) {
  125. return;
  126. }
  127. clearInterval(interval01);
  128. resolve(menuItem);
  129. }, 15);
  130. });
  131. p.then((data) => {
  132. data.forEach((value) => {
  133. const tempE = value.querySelector("a");
  134. const data = {};
  135. let tempTitle = tempE.text.trim();
  136. data["title"] = tempTitle.substring(0, tempTitle.lastIndexOf("."));
  137. data["url"] = tempE.getAttribute("href");
  138. data["text"] = value.querySelector("b").textContent.trim();
  139. this.data.tempDataList.push(data);
  140. });
  141. });
  142. }, 1000);
  143. },
  144. find(key) {
  145. const dataList = this.data.tempDataList;
  146. const findDataList = [];
  147. dataList.forEach(value => {
  148. if (!value.title.includes(key)) return;
  149. findDataList.push(value);
  150. });
  151. return findDataList;
  152. },
  153. getData() {
  154. this.verifyData();
  155. return this.data.tempDataList;
  156. },
  157. outPutFile() {
  158. const data = this.getData();
  159. const info = `已获取到${data.length}个资源,并将其打印在控制台和输出面板上!`;
  160. alert(info);
  161. Tip.success(info);
  162. Util.fileDownload(JSON.stringify(data, null, 3), `GBT乐赏游戏空间游戏磁力地址${data.length}个资源(${Util.toTimeString()}).json`);
  163. },
  164. outPutConsole() {
  165. const data = this.getData();
  166. console.log("===============================================")
  167. const info = `已获取到${data.length}个资源,并将其打印在控制台和输出面板上!`;
  168. console.log(info);
  169. alert(info);
  170. console.log(data);
  171. console.log("===============================================")
  172. },
  173. /**
  174. * 查找输入框,如有结果,则返回结果,否则返回null
  175. */
  176. findInput() {
  177. this.verifyData();
  178. const val = prompt("搜索关键词");
  179. if (val === null || val.trim() === "") {
  180. return null;
  181. }
  182. const findDataList = this.find(val);
  183. if (findDataList.length === 0) {
  184. alert(`未查到到关键词${val}的资源!`)
  185. return null;
  186. }
  187. return {key: val, data: findDataList};
  188. },
  189. findInputAndOutPut() {
  190. const data = this.findInput();
  191. if (data === null) return;
  192. const size = data.data.length;
  193. alert(`已获取到${size}个资源,准备导出到文件!`)
  194. console.log("===============================================")
  195. Util.fileDownload(JSON.stringify(data.data, null, 3), `GBT乐赏游戏空间游戏磁力地址${data.key}关键词(${Util.toTimeString()}).json`);
  196. console.log("===============================================")
  197. },
  198. findInputAndOutPutConsole() {
  199. const data = this.findInput();
  200. if (data === null) return;
  201. const size = data.data.length;
  202. alert(`已获取到${size}个资源,并将其打印在控制台和输出面板上!`)
  203. console.log("===============================================")
  204. console.log(`关键词${data.key}\t资源数量${size}`);
  205. console.log(data.data);
  206. console.log("===============================================")
  207. }
  208. };
  209.  
  210.  
  211. (function () {
  212. 'use strict';
  213. Util.addGMMenu("初始化页面数据", () => GBTGame.init());
  214. Util.addGMMenu("导出页面数据到文件", () => GBTGame.outPutFile());
  215. Util.addGMMenu("导出页面数据到控制台", () => GBTGame.outPutConsole());
  216. Util.addGMMenu("查找资源并导出资源到文件", () => GBTGame.findInputAndOutPut());
  217. Util.addGMMenu("查找资源并导出资源到控制台", () => GBTGame.findInputAndOutPutConsole());
  218. })();

QingJ © 2025

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