行业洞察_类目

云图扩展工具

  1. // ==UserScript==
  2. // @name 行业洞察_类目
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description 云图扩展工具
  6. // @author siji-Xian
  7. // @match *://yuntu.oceanengine.com/yuntu_ng/product/industry/marketOverview?*
  8. // @icon https://lf3-static.bytednsdoc.com/obj/eden-cn/prhaeh7pxvhn/yuntu/yuntu-logo_default.svg
  9. // @grant none
  10. // @license MIT
  11. // @require https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.2.1/jquery.min.js
  12. // @require https://cdn.bootcss.com/moment.js/2.20.1/moment.min.js
  13. // @require https://gf.qytechs.cn/scripts/404478-jsonexportexcel-min/code/JsonExportExcelmin.js?version=811266
  14. // @require https://gf.qytechs.cn/scripts/455576-qmsg/code/Qmsg.js?version=1122361
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. "use strict";
  19. var new_element = document.createElement("link");
  20. new_element.setAttribute("rel", "stylesheet");
  21. new_element.setAttribute("href", "https://qmsg.refrain.xyz/message.min.css");
  22. document.body.appendChild(new_element);
  23.  
  24. const button = document.createElement("div");
  25. button.textContent = "导出所有类目";
  26. Object.assign(button.style, {
  27. height: "34px",
  28. lineHeight: "var(--line-height, 34px)",
  29. alignItems: "center",
  30. color: "white",
  31. background: "linear-gradient(90deg, rgba(0, 239, 253), rgba(64, 166, 254))",
  32. borderRadius: "5px",
  33. marginLeft: "10px",
  34. fontSize: "13px",
  35. padding: "0 10px",
  36. cursor: "pointer",
  37. fontWeight: "500",
  38. });
  39. button.addEventListener("click", urlClick);
  40.  
  41. //message.js
  42. let loadingMsg = null;
  43.  
  44. //目标数据
  45. let target_data = null;
  46.  
  47. (function listen() {
  48. var origin = {
  49. open: XMLHttpRequest.prototype.open,
  50. send: XMLHttpRequest.prototype.send,
  51. };
  52. XMLHttpRequest.prototype.open = function (a, b) {
  53. this.addEventListener("load", replaceFn);
  54. origin.open.apply(this, arguments);
  55. };
  56. XMLHttpRequest.prototype.send = function (a, b) {
  57. origin.send.apply(this, arguments);
  58. };
  59. function replaceFn(obj) {
  60. if (
  61. this?._url?.slice(0, 42) == "/product_node/v2/api/industry/categoryList"
  62. ) {
  63. target_data = JSON.parse(obj?.target?.response);
  64. }
  65. }
  66. })();
  67.  
  68. function appendDoc() {
  69. const likeComment = document.querySelectorAll(".Header__Container-doYohE.dhvCdO")[0];
  70. if (likeComment) {
  71. likeComment.append(button);
  72. return;
  73. }
  74. setTimeout(appendDoc, 1000);
  75. }
  76. appendDoc();
  77.  
  78. function getData(e){
  79.  
  80. //数据处理
  81. function flattenObject(obj, prefix = '') {
  82. var result = [];
  83. if (prefix !== '') {
  84. prefix += '_';
  85. }
  86. var item = {
  87. name: prefix + obj.name,
  88. parent_id: obj.parent_id,
  89. id: obj.id
  90. };
  91. result.push(item);
  92. if (obj.children) {
  93. obj.children.forEach(function(child) {
  94. if (child.children && child.children.length > 0) {
  95. result.push(...flattenObject(child, item.name));
  96. } else {
  97. var childItem = {
  98. name: item.name + '_' + child.name,
  99. parent_id: child.parent_id,
  100. id: child.id
  101. };
  102. result.push(childItem);
  103. }
  104. });
  105. }
  106. return result;
  107. }
  108.  
  109. let b = e.data.map(item => {
  110. return flattenObject(item);
  111. }).flat().filter(e=>{
  112. return e.id != '-999'
  113. })
  114.  
  115. expExcel(b);
  116. }
  117.  
  118.  
  119. function expExcel(e) {
  120.  
  121. let contrast = {
  122. name: "name",
  123. parent_id: "parent_id",
  124. id: "id"
  125. };
  126.  
  127. let option = {};
  128. option.fileName = "类目"; //文件名
  129. option.datas = [
  130. {
  131. sheetName: "",
  132. sheetData: e,
  133. sheetHeader: Object.keys(contrast),
  134. sheetFilter: Object.values(contrast),
  135. columnWidths: [], // 列宽
  136. }
  137. ];
  138. var toExcel = new ExportJsonExcel(option);
  139. toExcel.saveExcel();
  140. loadingMsg.close();
  141. }
  142.  
  143. function urlClick() {
  144. if (target_data) {
  145. loadingMsg = Qmsg.loading("正在导出,请勿重复点击!");
  146. getData(target_data);
  147. } else {
  148. loadingMsg = Qmsg.error("数据加载失败,请等待页面加载完成!");
  149. }
  150. }
  151. })();

QingJ © 2025

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