SPU5A_指定SPU的人群资产重叠分布

云图扩展工具

  1. // ==UserScript==
  2. // @name SPU5A_指定SPU的人群资产重叠分布
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 云图扩展工具
  6. // @author siji-Xian
  7. // @match *://yuntu.oceanengine.com/yuntu_ng/assets/commodity/related?*
  8. // @icon https://www.google.com/s2/favicons?domain=oceanengine.com
  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, 46) ==
  62. "/yuntu_ng/api/v1/GetSpuAudienceAssetOverlapSpu"
  63. ) {
  64. target_data = JSON.parse(obj?.target?.response);
  65. }
  66. }
  67. })();
  68.  
  69. function appendDoc() {
  70. const likeComment = document.querySelector(".index__legend--RaIVx");
  71. if (likeComment) {
  72. likeComment.append(button);
  73. return;
  74. }
  75. setTimeout(appendDoc, 1000);
  76. }
  77. appendDoc();
  78.  
  79. function transformData(inputData) {
  80. const outputData = [[], [], []];
  81. const xValues = Array.from(new Set(inputData.map(entry => entry.x)));
  82. const yValues = Array.from(new Set(inputData.map(entry => entry.y)));
  83. xValues.forEach(x => {
  84. const numObj = {};
  85. const rateObj = {};
  86. const compareRateObj = {};
  87. yValues.forEach(y => {
  88. const numEntry = inputData.find(entry => entry.x === x && entry.y === y);
  89. if (numEntry) {
  90. numObj[y] = numEntry.xy_overlap_cover_num;
  91. rateObj[y] = numEntry.xy_overlap_rate;
  92. compareRateObj[y] = numEntry.xy_compare_overlap_rate;
  93. } else {
  94. numObj[y] = "";
  95. rateObj[y] = "";
  96. compareRateObj[y] = "";
  97. }
  98. });
  99. outputData[0].push(numObj);
  100. outputData[1].push(rateObj);
  101. outputData[2].push(compareRateObj);
  102. });
  103. return outputData;
  104. }
  105.  
  106. function expExcel(e) {
  107. let data = transformData(e.data.heat_map_list)
  108. let contrast = {
  109. "SUP2-A1_SPU1-A1": "SPU2-A1",
  110. "SUP2-A2_SPU1-A1": "SPU2-A2",
  111. "SUP2-A3_SPU1-A1": "SPU2-A3",
  112. "SUP2-A4_SPU1-A1": "SPU2-A4",
  113. "SUP2-A5_SPU1-A1": "SPU2-A5",
  114. };
  115.  
  116. let option = {};
  117. option.fileName = "SPU5A_指定SPU的人群资产重叠分布"; //文件名
  118. option.datas = data.map((v,i)=>{
  119. return {
  120. sheetName: i == 0 ? '重叠人数':i == 1 ? '占SPU2比重':'占SPU1比重' ,
  121. sheetData: v,
  122. sheetHeader: Object.keys(contrast),
  123. sheetFilter: Object.values(contrast),
  124. columnWidths: [], // 列宽
  125. }
  126. })
  127. var toExcel = new ExportJsonExcel(option);
  128. toExcel.saveExcel();
  129. loadingMsg.close();
  130. }
  131.  
  132. function urlClick() {
  133. if (target_data) {
  134. loadingMsg = Qmsg.loading("正在导出,请勿重复点击!");
  135. expExcel(target_data);
  136. } else {
  137. loadingMsg = Qmsg.error("数据加载失败,请重试");
  138. }
  139. }
  140. })();

QingJ © 2025

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