// ==UserScript== // @name GMV TO 5A // @namespace http://tampermonkey.net/ // @license MIT // @version 1.1 // @description 云图扩展工具 // @author siji-Xian // @match *://yuntu.oceanengine.com/yuntu_brand/assets/gta/track?* // @icon https://lf3-static.bytednsdoc.com/obj/eden-cn/prhaeh7pxvhn/yuntu/yuntu-logo_default.svg // @grant none // @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 // @downloadURL https://update.greasyfork.icu/scripts/464723/GMV%20TO%205A.user.js // @updateURL https://update.greasyfork.icu/scripts/464723/GMV%20TO%205A.meta.js // ==/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); var buttom = document.createElement("button"); //创建一个按钮 buttom.textContent = "导出数据"; //按钮内容 buttom.style.height = "32px"; //高 buttom.style.lineHeight = "32px"; //行高 buttom.style.align = "center"; //文本居中 buttom.style.color = "white"; //按钮文字颜色 buttom.style.background = "#2a5df0"; //按钮底色 buttom.style.border = "0px"; //边框属性 buttom.style.borderRadius = "3px"; //按钮四个角弧度 buttom.style.marginLeft = "10px"; buttom.style.fontSize = "12px"; buttom.style.padding = "0 5px"; buttom.addEventListener("click", userClick); //监听按钮点击事件 //message.js let loadingMsg = null; //获取industry_id let industry_id = null; //获取report_id let report_id = null; (function listen() { var origin = { open: XMLHttpRequest.prototype.open, send: XMLHttpRequest.prototype.send, }; XMLHttpRequest.prototype.open = function (a, b) { this.addEventListener("load", replaceFn); origin.open.apply(this, arguments); }; XMLHttpRequest.prototype.send = function (a, b) { origin.send.apply(this, arguments); }; function replaceFn(obj) { if ( this?._url?.slice(0, 42) == "/yuntu_ng/api/v1/get_brand_competitor_list" ) { industry_id = JSON.parse(obj?.target?.response).data[0].industry_id; } if ( this?._url?.slice(0, 45) == "/yuntu_ng/api/v1/AudienceGtaReportQueryListV2" ) { report_id = JSON.parse(obj?.target?.response).data.reports[0].base_info.report_id; } } })(); //默认GET请求 const getRequestOptions = { method: "GET", redirect: "follow", }; //获取brand信息 let brand = localStorage.getItem("__Garfish__platform__yuntu_user") || ""; let brands = JSON.parse(brand); // 弹窗组件 class inlyModelComponent { constructor() { let _this = this; this.loadingMsg = null; //展示弹窗 this.showModel = () => { $("#inly_model").css({ display: "block" }); $(".inly_box").css({ animation:'inly_box .2s forwards' }) setTimeout(() => { $("#inly_model").css({ opacity: 1 }); }, 0); }; //关闭弹窗 this.closeModel = function () { $("#inly_model").css({ opacity: 0 }); $(".inly_box").css({animation:'inly_box_close .2s forwards'}) setTimeout(() => { document.getElementById("inly_model").style.display = "none"; }, 200); }; //原生阻止冒泡 this.stopPropagation = function (e) { e = e || window.event; if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } }; const htmlModel = ` `; //添加弹窗到body节点 $("body").append(htmlModel); function appendDoc() { let like_comment; setTimeout(() => { like_comment = $("body"); if (like_comment) { like_comment.append(htmlModel); //把按钮加入到 x 的子节点中 return; } appendDoc(); }, 1000); } appendDoc(); //点击空白处关闭弹窗 $("#inly_model").click(function (event) { _this.closeModel(); _this.stopPropagation(); return false; }); //阻止冒泡 $("#inly_box").click(function (event) { _this.stopPropagation(); return false; }); //按钮事件 $("#inly_xkxs").click(function (e) { exp_xkxs(); _this.stopPropagation(); return false; }); $("#inly_xkxz").click(function (e) { exp_xkxz(); _this.stopPropagation(); return false; }); $("#inly_lkxs").click(function (e) { exp_lkxs(); _this.stopPropagation(); return false; }); $("#inly_xkxscl").click(function (e) { exp_xkxscl(); _this.stopPropagation(); return false; }); $("#inly_xkxzcl").click(function (e) { exp_xkxzcl(); _this.stopPropagation(); return false; }); $("#inly_lkxscl").click(function (e) { exp_lkxscl(); _this.stopPropagation(); return false; }); $("#inly_xs").click(function (e) { exp_xs(); _this.stopPropagation(); return false; }); $("#inly_xscl").click(function (e) { exp_xscl(); _this.stopPropagation(); return false; }); } } //初始化弹窗组件 const inly_Model = new inlyModelComponent(); let aadvid = getQueryVariable("aadvid"), brand_id = brands.brand_id; function appendDoc() { let like_comment; setTimeout(() => { like_comment = document.getElementsByClassName( "backHeader-hgTQPa" )[0]; if (like_comment) { like_comment.append(buttom); //把按钮加入到 x 的子节点中 return; } appendDoc(); }, 1000); } appendDoc(); //query参数获取 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; } //fetch请求封装 async function fetchFun(url, data = {}, requestOptions = getRequestOptions) { const urlData = Object.keys(data) .map((v) => `${v}=${data[v]}`) .join("&"); try { const response = await fetch(`${url}?${urlData}`, requestOptions); const result_1 = await response.text(); return JSON.parse(result_1); } catch (error) { return console.log("error", error); } } //活动期转化分析 async function fetchData_hd(i, data) { let requestData = await fetchFun( "https://yuntu.oceanengine.com/yuntu_ng/api/v1/AudienceGtaHarvestAnalysis", { ...data, card: i } ); let res = requestData.data.ax_analysis.tps; return res.map((v) => { return { ...v, trigger_point_name: `A${i}${v.trigger_point_name}`, }; }); } //活动期转化分析人群策略 async function fetchData_cl(i, data) { let requestData = await fetchFun( "https://yuntu.oceanengine.com/yuntu_ng/api/v1/AudienceGtaHarvestAnalysis", { ...data, card: i } ); let res = requestData.data.ax_analysis.packs; return res; } //蓄水期触点贡献情况 async function fetchData_xs(i, data) { let requestData = await fetchFun( "https://yuntu.oceanengine.com/yuntu_ng/api/v1/AudienceGtaImpoundAnalysis", { ...data, card: i } ); let res = requestData.data.ax_analysis.tps; return res.map((v) => { return { ...v, trigger_point_name: `A${i}${v.trigger_point_name}`, }; }); } //蓄水期人群策略 async function fetchData_xscl(i, data) { let requestData = await fetchFun( "https://yuntu.oceanengine.com/yuntu_ng/api/v1/AudienceGtaImpoundAnalysis", { ...data, card: i } ); let res = requestData.data.ax_analysis.packs; return res; } async function getData(fun, card, param, fileName, contrast) { let data = { aadvid, industry_id, brand_id, report_id, ...param, }; let requestData = await Promise.all( card.map((v) => { let res = fun(v, data); return res; }) ); let option = requestData.map((v) => { return { sheetName: "", sheetData: v, sheetHeader: Object.keys(contrast), sheetFilter: Object.values(contrast), columnWidths: [], // 列宽 }; }); toExcel(fileName, option); } function toExcel(e, data) { let option = {}; option.fileName = e; //文件名 option.datas = data; var toExcel = new ExportJsonExcel(option); toExcel.saveExcel(); loadingMsg.close(); } function userClick() { inly_Model.showModel(); } function exp_xkxs() { loadingMsg = Qmsg.loading("正在导出,请勿重复点击!"); let fileName = "活动期新客蓄水"; let param = { gta_type: 1, analysis_type: 1, }; let card = [1, 2, 3]; let contrast = { 触点: "trigger_point_name", ID: "trigger_point_id", 曝光次数: "show_cnt", 曝光人数: "show_uv", 人均曝光次数: "show_avg", 存量转化人数: "to_a4_cnt", 存量转化率: "to_a4_rate", }; getData(fetchData_hd, card, param, fileName, contrast); } function exp_xkxscl() { loadingMsg = Qmsg.loading("正在导出,请勿重复点击!"); let fileName = "活动期新客蓄水人群策略"; let param = { gta_type: 1, analysis_type: 3, }; let card = [1, 2, 3]; let contrast = { 人群包: "pack_name", 人群包id: "pack_id", 人群包量级: "cover_num", 曝光次数: "show_cnt", 曝光人数: "show_uv", 人均曝光次数: "show_avg", 存量转化人数: "to_a4_cnt", 存量转化率: "to_a4_rate", }; getData(fetchData_cl, card, param, fileName, contrast); } function exp_xkxz() { loadingMsg = Qmsg.loading("正在导出,请勿重复点击!"); let fileName = "活动期新客新增"; let param = { gta_type: 2, analysis_type: 1, }; let card = [1, 2, 3]; let contrast = { 触点: "trigger_point_name", ID: "trigger_point_id", 曝光次数: "show_cnt", 曝光人数: "show_uv", 人均曝光次数: "show_avg", 新增转化人数: "to_a4_cnt", 新增转化率: "to_a4_rate", }; getData(fetchData_hd, card, param, fileName, contrast); } function exp_xkxzcl() { loadingMsg = Qmsg.loading("正在导出,请勿重复点击!"); let fileName = "活动期新客新增人群策略"; let param = { gta_type: 2, analysis_type: 3, }; let card = [1, 2, 3]; let contrast = { 人群包: "pack_name", 人群包id: "pack_id", 人群包量级: "cover_num", 曝光次数: "show_cnt", 曝光人数: "show_uv", 人均曝光次数: "show_avg", 新增转化人数: "to_a4_cnt", 新增转化率: "to_a4_rate", }; getData(fetchData_cl, card, param, fileName, contrast); } function exp_lkxs() { loadingMsg = Qmsg.loading("正在导出,请勿重复点击!"); let fileName = "活动期老客蓄水"; let param = { gta_type: 4, analysis_type: 1, }; let card = [4]; let contrast = { 触点: "trigger_point_name", ID: "trigger_point_id", 曝光次数: "show_cnt", 曝光人数: "show_uv", 人均曝光次数: "show_avg", 购买转化人数: "to_a4_cnt", 购买转化率: "to_a4_rate", }; getData(fetchData_hd, card, param, fileName, contrast); } function exp_lkxscl() { loadingMsg = Qmsg.loading("正在导出,请勿重复点击!"); let fileName = "活动期老客蓄水人群策略"; let param = { gta_type: 4, analysis_type: 3, }; let card = [4]; let contrast = { 人群包: "pack_name", 人群包id: "pack_id", 人群包量级: "cover_num", 曝光次数: "show_cnt", 曝光人数: "show_uv", 人均曝光次数: "show_avg", 购买转化人数: "to_a4_cnt", 购买转化率: "to_a4_rate", }; getData(fetchData_cl, card, param, fileName, contrast); } function exp_xs() { loadingMsg = Qmsg.loading("正在导出,请勿重复点击!"); let fileName = "蓄水期触点贡献情况"; let param = { analysis_type: 1, }; let card = [1, 2, 3]; let contrast = { 触点: "trigger_point_name", ID: "trigger_point_id", 曝光次数: "show_cnt", 曝光人数: "show_uv", 人均曝光次数: "show_avg", 流转规模: "to_a3_cnt", 流转率: "to_a3_rate", }; getData(fetchData_xs, card, param, fileName, contrast); } function exp_xscl() { loadingMsg = Qmsg.loading("正在导出,请勿重复点击!"); let fileName = "蓄水期人群策略"; let param = { analysis_type: 3, }; let card = [1, 2, 3]; let contrast = { 人群包: "pack_name", 人群包id: "pack_id", 人群包量级: "cover_num", 曝光次数: "show_cnt", 曝光人数: "show_uv", 人均曝光次数: "show_avg", 流转规模: "to_a3_cnt", 流转率: "to_a3_rate", }; getData(fetchData_xscl, card, param, fileName, contrast); } })();