// ==UserScript==
// @name 品牌形象洞察_联想度
// @namespace http://tampermonkey.net/
// @version 2.0.3
// @description 云图扩展工具
// @author siji-Xian
// @match *://yuntu.oceanengine.com/yuntu_brand/image/insight/brand?indicator=3*
// @icon https://lf3-static.bytednsdoc.com/obj/eden-cn/prhaeh7pxvhn/yuntu/yuntu-logo_default.svg
// @grant GM.xmlHttpRequest
// @license MIT
// @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: "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",
position: "absolute",
top: "200px",
right: "70px",
});
button.addEventListener("click", urlClick);
//message.js
let loadingMsg = null;
//目标数据
let target_data = null;
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;
}
(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, 47) ==
"/measurement/api/v2/image/get_communication_tag"
) {
target_data = JSON.parse(obj?.target?.response);
}
}
})();
function appendDoc() {
const likeComment = document.querySelector("body");
if (likeComment) {
likeComment.append(button);
return;
}
setTimeout(appendDoc, 1000);
}
appendDoc();
//提交数据到服务器
function submitData(option) {
//从localStorage获取statBaseUrl
let statBaseUrl = localStorage.getItem("statBaseUrl");
if (!statBaseUrl) {
Qmsg.error("statBaseUrl获取失败,请联系管理员!");
loadingMsg.close();
return;
}
//获取当前脚本名称
const scriptName = GM_info.script.name;
//使用GM.xmlHttpRequest将数据提交到后端服务器
GM.xmlHttpRequest({
method: "POST",
url: statBaseUrl,
data: JSON.stringify({
...option,
plugins_name: scriptName,
advertiser_id: getQueryVariable("aadvid"),
}),
headers: {
"Content-Type": "application/json",
},
onload: function (response) {
let res = JSON.parse(response.responseText);
if (res.code == "990") {
Qmsg.success("数据已上传");
var toExcel = new ExportJsonExcel(option);
toExcel.saveExcel();
setTimeout(() => {
loadingMsg.close();
}, 1000);
} else {
loadingMsg.close();
Qmsg.error("数据上传失败,请联系管理员!");
}
},
onerror: function (response) {
Qmsg.error("数据上传失败,请联系管理员!");
loadingMsg.close();
},
});
}
function expExcel(e) {
let contrast = {
"tag_name": "标签名称",
"communication_rate": "联想度",
"user_mention_cnt": "用户提及量",
"user_mention_rate": "用户提及占比",
"brand_broadcast_cnt": "品牌传播曝光量",
"brand_broadcast_rate": "品牌传播占比"
}
let option = {};
option.fileName = "品牌形象洞察_联想度"; //文件名
option.datas = [{
sheetName: 'sheet1',
sheetData: e.data.tags,
sheetHeader: Object.values(contrast),
sheetFilter: Object.keys(contrast),
columnWidths: [], // 列宽
}]
submitData(option);
}
function urlClick() {
if (target_data) {
loadingMsg = Qmsg.loading("正在导出,请勿重复点击!");
expExcel(target_data);
} else {
loadingMsg = Qmsg.error("数据加载失败,请重试");
}
}
})();