Greasy Fork is available in English.

商品_细分市场_市场构成

云图扩展工具

// ==UserScript==
// @name         商品_细分市场_市场构成
// @namespace    http://tampermonkey.net/
// @version      0.2.1
// @description  云图扩展工具
// @author       siji-Xian
// @match        *://yuntu.oceanengine.com/yuntu_ng/product/segmentedMarketDetail/marketAweme?*
// @icon         https://www.google.com/s2/favicons?domain=oceanengine.com
// @grant        none
// @license      MIT
// @require      https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.2.1/jquery.min.js
// @require      https://cdn.bootcss.com/moment.js/2.20.1/moment.min.js
// @require      https://greasyfork.org/scripts/404478-jsonexportexcel-min/code/JsonExportExcelmin.js?version=811266
// @require      https://greasyfork.org/scripts/455576-qmsg/code/Qmsg.js?version=1122361
// ==/UserScript==

(function () {
  "use strict";
  var new_element = document.createElement("link");
  new_element.setAttribute("rel", "stylesheet");
  new_element.setAttribute("href", "https://qmsg.refrain.xyz/message.min.css");
  document.body.appendChild(new_element);

  const button = document.createElement("div");
  button.textContent = "导出数据";
  Object.assign(button.style, {
    height: "34px",
    lineHeight: "var(--line-height, 34px)",
    alignItems: "center",
    color: "#FFF",
    background: "linear-gradient(60deg, rgb(95, 240, 225), rgb(47, 132, 254))",
    borderRadius: "5px",
    margin: "0 10px",
    fontSize: "13px",
    padding: "0 10px",
    cursor: "pointer",
    fontWeight: "500",
  });
  button.addEventListener("click", urlClick);

  let fetchList = [];

  window.au_fetch = window.fetch;
  window.fetch = async (...args) => {
    let [resource, config] = args;
    // request interceptor here
    const response = await window.au_fetch(resource, config);
    if (
      response.url.slice(0, 87) ==
      "https://yuntu.oceanengine.com/product_node/api/graphql/?op=getIndustryInsightAwemeStats"
    ) {
      fetchList.push({ response, body: args[1].body });
    }
    return response;
  };

  //message.js
  let loadingMsg = null;

  function appendDoc() {
    const likeComment = document.querySelector(
      ".ModuleWrapper__Header-guwZQm"
    );
    if (likeComment) {
      likeComment.append(button);
      return;
    }
    setTimeout(appendDoc, 1000);
  }
  appendDoc();

  async function getData() {
    loadingMsg = Qmsg.loading("正在导出,请勿重复点击!");

    let body = fetchList[fetchList.length - 1].body;
    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;

    xhr.addEventListener("readystatechange", function () {
      if (this.readyState === 4) {
        let _this = JSON.parse(this.responseText);
        let expData = _this?.data?.industryInsightAwemeStats?.list?.map((v) => {
          return {
            ...v.aweme,
            perUidOrderCnt: v.data.perUidOrderCnt.value,
            perUidPurchaseProductCnt: v.data.perUidPurchaseProductCnt.value,
            productAvgPrice: v.data.productAvgPrice.value,
            productCnt: v.data.productCnt.value,
            purchaseUidCnt: v.data.purchaseUidCnt.value,
            salesAmount: v.data.salesAmount.value,
            salesAmountRank: v.data.salesAmount.rank,
            salesVolune: v.data.salesVolune.value,
          };
        });
        expExcel(expData);
      }
    });
    xhr.open("POST", fetchList[fetchList.length - 1].response.url);
    xhr.setRequestHeader("authority", "yuntu.oceanengine.com");
    xhr.setRequestHeader("accept", "*/*");
    xhr.setRequestHeader("accept-language", "zh-CN,zh;q=0.9");
    xhr.setRequestHeader("content-type", "application/json");

    xhr.send(body);
    return;
  }

  function expExcel(e) {
    let contrast = {
      '排名': "salesAmountRank",
      '头像': "imageUrl",
      '名称': "name",
      '抖音号': "awemeId",
      '抖音号类型': "authorType",
      '主推类目': "liveMainCategory",
      "销售金额(指数)": "salesAmount",
      "销售量(指数)": "salesVolune",
      "购买人数(指数)": "purchaseUidCnt",
      "商品数(指数)": "productCnt",
      "人均购买频次(指数)": "perUidOrderCnt",
      "人均购买量(指数)": "perUidPurchaseProductCnt",
    };
    let fileName = "抖音号分析";
    let option = {};
    option.fileName = fileName; //文件名
    option.datas = [
      {
        sheetName: "",
        sheetData: e,
        sheetHeader: Object.keys(contrast),
        sheetFilter: Object.values(contrast),
        columnWidths: [], // 列宽
      },
    ];
    var toExcel = new ExportJsonExcel(option);
    toExcel.saveExcel();
    setTimeout(() => {
      loadingMsg.close();
    }, 1000);
  }

  function urlClick() {
    getData();
  }
})();