Greasy Fork is available in English.
1. 添加【零效果产品页】复制及数据查看产品按钮 2. 添加【产品运营工作台页】产品编辑及数据查看按钮 3. 添加【产品分析页】编辑及数据查看按钮 4. 添加【产品详情页】编辑及数据查看按钮,添加显示产品关键词
当前为
// ==UserScript==
// @namespace http://www.alibaba.com
// @author Lepturus
// @version 0.0.1
// @name 阿里巴巴国际站产品辅助脚本
// @icon http://is.alicdn.com/favicon.ico
// @description 1. 添加【零效果产品页】复制及数据查看产品按钮 2. 添加【产品运营工作台页】产品编辑及数据查看按钮 3. 添加【产品分析页】编辑及数据查看按钮 4. 添加【产品详情页】编辑及数据查看按钮,添加显示产品关键词
// @match *://data.alibaba.com/product/ineffective*
// @match *://hz-productposting.alibaba.com/product/product_grow_up_manage.htm*
// @match *://data.alibaba.com/product/overview*
// @match *://www.alibaba.com/product-detail/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// 添加零效果产品页复制产品按钮
function productNEW(){
let products = document.querySelectorAll('tbody>tr')
let ln = products.length;
// 非对不起,未能查询到符合您要求的产品,建议重新设置查询条件或者已经存在复制按钮
if (!document.querySelector('tbody>tr').textContent.match("未能查询到")&&!document.querySelector('tbody>tr').textContent.match("复制")){
for (var i = 0; i < ln; i++) {
var product_info= products[i].querySelectorAll('.next-table-cell-wrapper'); // 表格每一行产品
// console.log(product_info);
var product_url= product_info[1].querySelector("a").href;
var container = product_info[6].querySelector(".edit-delete-off"); // <span class="edit-delete-off">...
var product_id = product_url.match(/_(\d+)\.htm(l)?/)[1]; // http://www.alibaba.com/product-detail//XXX_123456789.html?spm=a2... // 产品ID
var product_newURL = "https://post.alibaba.com/product/publish.htm?spm=a2747.manage.0.0.8e9071d2H60Rr7&pubType=similarPost&itemId=" + product_id + "&behavior=copyNew";
var content = `<a href="${product_newURL}" target="_blank" behavior="copyToNewProduct"><br/>复制</a>
<a href="//hz-productposting.alibaba.com/product/manage_products.htm?#/product/all/1-10/productId=${product_id}" target="_blank">数据</a>`;
container.innerHTML+=content;
}
console.log("零效果产品页复制按钮添加成功!!!");
}
}
// 添加产品运营工作台产品编辑按钮
function productEdit(){
let products = document.querySelectorAll('.upgrade-products-article-item')
let ln = products.length;
// 非已经存在编辑按钮
if (ln&&!document.querySelector('.upgrade-products-article-item').textContent.match("编辑")){
for (var i = 0; i < ln; i++) {
var product_title= products[i].querySelector(".product-subject").title;
var product_container = products[i].querySelector(".product-id");
var product_id = product_container.textContent.match(/\d+/)[0]; // 产品ID
// console.log(product_title, product_id);
var product_href = `<a href="//post.alibaba.com/product/publish.htm?spm=a2747.manage.0.0.77fb71d2zK7Jvr&itemId=${product_id}" target="_blank"><br/>编辑</a>
<a href="//hz-productposting.alibaba.com/product/manage_products.htm?#/product/all/1-10/productId=${product_id}" target="_blank"> 数据</a>`
product_container.innerHTML+=product_href;
}
console.log("添加产品运营工作台产品编辑按钮成功!!!");
}
}
// 添加产品分析页面按钮
function productAnalyse(){
let products = document.querySelectorAll('tbody>tr')
let ln = products.length;
// 非已经存在产品分层按钮
if (ln&&!document.querySelector('tbody>tr:last-child').textContent.match("分层")){
for (var i = 0; i < ln; i++) {
var product_title= products[i].querySelector(".media-content").textContent;
var product_url = products[i].querySelector(".custom-td-content>a").href;
var product_id = product_url.match(/_(\d+)\.htm(l)?/)[1]; // 产品ID
// console.log(product_title, product_id);
var product_newURL = "https://post.alibaba.com/product/publish.htm?spm=a2747.manage.0.0.8e9071d2H60Rr7&pubType=similarPost&itemId=" + product_id + "&behavior=copyNew";
var product_href = `<br><a class="action-enabled TEST" href="${product_newURL}" target="_blank" behavior="copyToNewProduct">复制</a><br>
<a class="action-enabled TEST" href="//hz-productposting.alibaba.com/product/manage_products.htm?#/product/all/1-10/productId=${product_id}" target="_blank">分层</a>`;
var product_container = products[i].querySelector(".action-enabled").parentElement; // 插入span 编辑 ...
product_container.innerHTML+=product_href;
// In most cases, it is the same as parentNode. The only difference comes when a node's parentNode is not an element. If so, parentElement is null.
product_container.parentNode.insertBefore(document.createElement("br"), product_container.nextSibling);
// document.querySelector('col:last-child').style.setProperty("width", "180px", "important"); // 设置表格最后一栏宽度
}
console.log("添加产品分析页面按钮成功!!!");
}
}
// 添加产品页按钮
function productDetail(){
if (!document.querySelector('.detail-title-section').textContent.match("编辑")){
var product_title= document.querySelector(".module-pdp-title").textContent;
var product_id = document.URL.match(/_(\d+)\.htm(l)?/)[1]; // 产品ID
var product_keywords = document.title.match(/- Buy(.*) Product/)[1]; // 产品关键词
var product_keywords_html = product_keywords.split(",").map(item => (`<br/><span style="color:orange;">${item}</span>`)).join("")
var product_href = `<a href="//post.alibaba.com/product/publish.htm?spm=a2747.manage.0.0.77fb71d2zK7Jvr&itemId=${product_id}" target="_blank"><br/>编辑</a>
<a href="//hz-productposting.alibaba.com/product/manage_products.htm?#/product/all/1-10/productId=${product_id}" target="_blank"> 数据</a>
${product_keywords_html}`
document.querySelector(".module-pdp-title").parentElement.innerHTML+=product_href
console.log("添加产品分析页面按钮成功!!!");
}
}
// 添加产品运营工作台产品编辑按钮
if (/product_grow_up_manage/.test(document.URL)) {
setInterval(productEdit, 2500);
// 添加零效果产品页复制产品按钮
} else if(/ineffective/.test(document.URL)) {
setInterval(productNEW, 2500);
// 添加产品分析页面按钮
} else if (/overview/.test(document.URL)) {
setInterval(productAnalyse, 2500);
} else if (/product-detail/.test(document.URL)) {
setInterval(productDetail, 2500);
}
})();