卡世界辅助脚本,产品管理列表数据导出
当前为
// ==UserScript==
// @name ksjhaoka_get_js
// @namespace http://tampermonkey.net/
// @version 0.2
// @license MIT
// @description 卡世界辅助脚本,产品管理列表数据导出
// @author byhgz
// @match https://www.ksjhaoka.com/
// @icon https://www.google.com/s2/favicons?sz=64&domain=ksjhaoka.com
// @require https://greasyfork.org/scripts/462234-message/code/Message.js?version=1170653
// @grant GM_registerMenuCommand
// ==/UserScript==
const Util = {
/**
*注册一个菜单并返回菜单id,可在插件中点击油猴时看到对应脚本的菜单
* @param {string}text 显示文本
* @param {function}func 事件
* @param {string}shortcutKey 快捷键
* @return menu 菜单id
*/
addGMMenu(text, func, shortcutKey = null) {
return GM_registerMenuCommand(text, func, shortcutKey);
},
/**
* 内容导出为文件
* @param {String}content 内容
* @param {String}fileName 文件名
*/
fileDownload(content, fileName) {
// 获取导出文件内容
// 创建隐藏的下载文件链接
const element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content));
element.setAttribute('download', fileName);
element.style.display = 'none';
document.body.appendChild(element);
// 手动触发下载
element.click();
// 清理dom
document.body.removeChild(element);
},
/**
* 复制文本
* @param text
*/
copyText(text) {
// 创建一个新的textarea元素
const textarea = document.createElement("textarea");
// 设置textarea的内容为需要复制的文本
textarea.value = text;
// 将textarea添加到文档中
document.body.appendChild(textarea);
// 选择textarea的文本
textarea.select();
// 复制选中的文本
document.execCommand("copy");
// 从文档中移除textarea
document.body.removeChild(textarea);
}
}
function getData() {
const dataList = [];
document.querySelectorAll(".app-main .el-row>div").forEach(value => {
const data = {};
data["运营商"] = value.querySelector(".goods-header-title").textContent.match(/运营商:(.+)/)[1];
data["上架时间"] = value.querySelector(".goods-header-time").textContent.match(/上架时间:(.+)/)[1];
const tempTitle = value.querySelector(".overflow-ellipsis").textContent;
data["title"] = tempTitle.substring(2, tempTitle.indexOf("卡") + 1);
const tempTitleInfo = tempTitle.substring(tempTitle.indexOf("卡") + 1);
data["titleInfo"] = tempTitleInfo;
const monthlyRentIndexOf = tempTitleInfo.indexOf("元");
let temp_monthlyRent;
if (monthlyRentIndexOf !== -1) {
temp_monthlyRent = tempTitleInfo.substring(0, monthlyRentIndexOf);
} else {
temp_monthlyRent = "未描述";
}
data["月租"] = temp_monthlyRent;
const tagsEl = value.querySelectorAll(".goods-tab>span");
const placeOfBelonging = tagsEl[0].textContent;
data["归属地"] = placeOfBelonging.includes("归属地") ? placeOfBelonging.match(/(.+)归属地/)[1] : placeOfBelonging;
data["快递"] = tagsEl[1].textContent;
data["合约"] = tagsEl[2].textContent;
data["年龄要求"] = tagsEl[3].textContent;
let tempActivationPlan;
if (tagsEl.length === 5) {
tempActivationPlan = tagsEl[4].textContent;
} else {
tempActivationPlan = "未描述"
}
data["激活方案"] = tempActivationPlan;
data["佣金"] = value.querySelector(".goods-brokerage div").textContent;
value.querySelectorAll(".goods-info-ul>.goods-info-li").forEach(li => {
const strings = li.querySelector(".goods-info-value").textContent.split(":");
data[strings[0]] = strings[1];
});
data["img"] = value.querySelector(".goods-img").src;
for (const key in data) {
data[key] = data[key].trim();
}
dataList.push(data);
})
return dataList;
}
(function () {
'use strict';
Util.addGMMenu("获取当前产品页面列表", () => {
const url = document.documentURI;
if (!url.endsWith("/#/goods/sale")) {
//提示
alert("当前页面不是产品管理");
return;
}
const data = getData();
console.log("===========当前页面产品列表===========")
console.log(data)
Util.copyText(JSON.stringify(data))
console.log("===========当前页面产品列表===========")
alert("已复制到剪切板,并打印在控制台上")
})
})();