单品分析_爆品指数_人群分析对比

云图扩展工具

目前为 2023-04-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         单品分析_爆品指数_人群分析对比
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  云图扩展工具
// @author       siji-Xian
// @match        *://yuntu.oceanengine.com/yuntu_ng/product/productOverview/productAnalysis/crowd*
// @icon         https://www.google.com/s2/favicons?domain=oceanengine.com
// @grant        none
// @license      BSD
// @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://gf.qytechs.cn/scripts/404478-jsonexportexcel-min/code/JsonExportExcelmin.js?version=811266
// @require      https://gf.qytechs.cn/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: "white",
    background: "linear-gradient(90deg, rgba(0, 239, 253), rgba(64, 166, 254))",
    borderRadius: "5px",
    marginLeft: "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, 82) ==
      "https://yuntu.oceanengine.com/product_node/api/graphql/?op=getProductIndexPortrait"
    ) {
      fetchList.push({ response, body: args[1].body });
    }
    return response;
  };

  function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
      var pair = vars[i].split("=");
      if (pair[0] == variable) {
        return pair[1];
      }
    }
    return false;
  }
    
  const objData = {
    BRAND: '本品',
    COMPETITOR_BRAND: '对比商品',
    INDUSTRY_BRAND: '行业Top20',
    ALL: '全部',
    LIVE_ROOM: '直播',
    PRODUCT_CARD: '商品卡',
    SHORT_VIDEO: '短视频',
    PURCHASE: '商品购买',
    CLICK: '商品点击',
    CLICK_NOT_PURCHASE: '商品后未购',
    SHOW: '商品曝光',
    SHOW_NOT_PURCHASE: '曝光后未购',
    ADD_CART: '商品加购'
  }
  

  //获取aadvid
  const aadvid = getQueryVariable("aadvid");

  //message.js
  let loadingMsg = null;

  function appendDoc() {
    const likeComment = document.querySelectorAll(".byted-radio-group-size-md")[3];
    if (likeComment) {
      likeComment.append(button);
      return;
    }
    setTimeout(appendDoc, 1000);
  }
  appendDoc();

  function formatData(data) {
    const result = [];
    data.items.forEach((item) => {
      const newItem = {
        labelName: data.name,
        name: item.name,
        value: item.value,
      };
      result.push(newItem);
    });
    return result;
  }

  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)
        const formatRes = (res) => {
          return res?.map((v) => {
              return formatData(v);
            })
            .flat();
        };
        const targetRes_formatted = formatRes(_this?.data?.getProductIndexPortrait?.competitorData);
        const contrastRes_formatted = formatRes(_this?.data?.getProductIndexPortrait?.selfData);

        const { variables } = JSON.parse(body);
         expExcel([
          {
            label: `目标组A-${objData[variables.competitorDimension.benchmarkType]}-${objData[variables.competitorDimension.contentType]}-${objData[variables.competitorDimension.actionType]}`,
            value: targetRes_formatted,
          },
          {
            label: `目标组B-${objData[variables.selfDimension.benchmarkType]}-${objData[variables.selfDimension.contentType]}-${objData[variables.selfDimension.actionType]}`,
            value: contrastRes_formatted,
          },
        ]);
      }
    });
    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 = {
      标签类型: "labelName",
      标签: "name",
      占比: "value"
    };
    let fileName =
      document.querySelector(".byted-input-size-md").value || "data";
    let option = {};
    option.fileName = fileName; //文件名
    option.datas = e.map((v) => {
      return {
        sheetName: v.label,
        sheetData: v.value,
        sheetHeader: Object.keys(contrast),
        sheetFilter: Object.values(contrast),
        columnWidths: [], // 列宽
      };
    });
    var toExcel = new ExportJsonExcel(option);
    toExcel.saveExcel();
    setTimeout(() => {
      loadingMsg.close();
    }, 1000);
  }

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

QingJ © 2025

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