// ==UserScript== // @name 选品添加主品 // @namespace http://tampermonkey.net/ // @version 2024-06-02 // @description 专用的 // @author You // @match https://shopee.co.th/* // @match https://detail.1688.com/offer/* // @require https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.7.1.min.js // @icon https://www.google.com/s2/favicons?sz=64&domain=mabangerp.com // @grant GM_xmlhttpRequest // @downloadURL https://update.greasyfork.icu/scripts/501044/%E9%80%89%E5%93%81%E6%B7%BB%E5%8A%A0%E4%B8%BB%E5%93%81.user.js // @updateURL https://update.greasyfork.icu/scripts/501044/%E9%80%89%E5%93%81%E6%B7%BB%E5%8A%A0%E4%B8%BB%E5%93%81.meta.js // ==/UserScript== (function () { 'use strict'; function jisuan_roi(that_click){ $(that_click).closest('.thisMsg').find('.jisuan_roi').each(function(index, value) { if(index>0){ var saleprice = parseFloat($(value).find('.mx1').val().replace(/[^0-9.]/g, '')); var yongjin = parseFloat($(value).find('.cg0').val()/100); var chengben = parseFloat($(value).find('.cg1').val()); var wuliu = parseFloat($(value).find('.cg2').val()); var baocai = parseFloat($(value).find('.cg3').val()); var zongchengben=yongjin*saleprice+chengben+wuliu+baocai; var maolilv=1-zongchengben/saleprice; $(this).find('.cg4').val((maolilv.toFixed(3)*100).toFixed(3)+"%"); $(this).find('.cg5').val((1/maolilv).toFixed(3)); } }); } function update_input(father_id,that_click){//更新输入数据 var this_class=""; var typea=""; if ($(that_click).hasClass('caigoua') || $(that_click).hasClass('xiaoshou') || $(that_click).hasClass('fuzhia') || $(that_click).hasClass('fuzhib')) { // 如果当前对象包含class 'caigoua',执行这里的代码 this_class=".caigoua"; typea="xp_xuanpin"; } else if ($(that_click).hasClass('caigoua1') || $(that_click).hasClass('xiaoshou1') || $(that_click).hasClass('fuzhia1') || $(that_click).hasClass('fuzhib1')){ // 如果当前对象不包含class 'caigoua',执行这里的代码 this_class=".caigoua1"; typea="xp_jp"; } var values = ''; $(that_click).closest('.thisMsg').find(this_class).each(function(index, element) { if (index > 0 && index % 6 == 0) { values += '分行'; } if (index > 0 && index % 6 != 0) { values += '分隔'; } values += $(element).val(); }); console.log("触发采购成本计算") console.log("father_id="+ father_id.slice(2)+"&update_cg=" + values+"&type=" + typea) GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "father_id="+ father_id.slice(2)+"&update_cg=" + values+"&type=" + typea, headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { // code console.log(r) } }); } function update_xiaoshou(father_id,that_click){//更新输入数据 var this_class=""; var typea=""; if ($(that_click).hasClass('xiaoshou') || $(that_click).hasClass('fuzhib') || $(that_click).hasClass('fuzhia')) { // 如果当前对象包含class 'caigoua',执行这里的代码 this_class=".xiaoshou"; typea="xp_xuanpin"; } else if ($(that_click).hasClass('xiaoshou1') || $(that_click).hasClass('fuzhib1') || $(that_click).hasClass('fuzhia1')){ // 如果当前对象不包含class 'caigoua',执行这里的代码 this_class=".xiaoshou1"; typea="xp_jp"; } var values = ''; $(that_click).closest('.thisMsg').find(this_class).each(function(index, element) { if (index > 0 && index % 4 == 0) { values += '分行'; } if (index > 0 && index % 4 != 0) { values += '分隔'; } if ($(this).is('span')) { values += $(element).text(); } else if ($(this).is('input')) { values += $(element).val(); } }); console.log("father_id="+ father_id.slice(2)+"&update_xs=" + values+"&type=" + typea) GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "father_id="+ father_id.slice(2)+"&update_xs=" + values+"&type=" + typea, headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { // code console.log(r) } }); } function postdata_jp(dataa,father_id) { // console.log(dataa) GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "father_id="+ father_id+"&dataa_jp=" + dataa+"&jpurl=" + encodeURIComponent(window.location.href), headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { // code // console.log(r) getxpdata() } }); } function postdata(dataa) { GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "caozuo=" + $("#caozuo").val()+"&dataa=" + dataa+"&xpurl="+encodeURIComponent(window.location.href), headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { // code getxpdata() console.log(r) } }); } function getxpdata_sj(weiyi_id,typea) { var leixingxs="xiaoshou1"; var leixingcg="caigoua1"; if(typea=="xp_xuanpin"){leixingxs="xiaoshou";leixingcg="caigoua";} console.log("调用获取竞品数据详细中间") var xphtml = ""; GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "weiyi_id="+ weiyi_id+"&xuanpinGET_sj=" + "yes"+"&type=" + typea, headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { console.log(r) var value = $.parseJSON(r.response)[0]; console.log(value) var arr = value.neirong.split('哦个'); $.each(arr, function(index1, value1) { if (value1.indexOf("分行") !== -1) { var arr1 = value1.split('分行'); var arrcg1 = value.caigou.split('分行'); $.each(arr1, function(index2, value2) { xphtml=xphtml+"
"; var arr2 = value2.split('分隔'); var arrcg2 = arrcg1[index2].split('分隔'); var kuandu=10; $.each(arr2, function(index3, value3) { if(index2>0 && index3==1){ xphtml=xphtml+""; } else{ xphtml=xphtml+""+value3+""; } }); $.each(arrcg2, function(index4, value4) { if(index2==0){ xphtml=xphtml+""+value4+""; }else{ xphtml=xphtml+""; } }); xphtml=xphtml+"
"; }); } else { if(index1==0){ xphtml=xphtml+"
"; } xphtml=xphtml+"
"+value1+"
"; if(index1==3){ xphtml=xphtml+"
"; xphtml=xphtml+"
添加当前
连接到采品
"; } } }); $('#content_sj'+value.father_weiyi_id).html(xphtml); } }); } function getxpdata_cg(father_id) { console.log("调用采购品"+father_id) $('#content_cg'+father_id).html(""); var xphtml = ""; GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "father_id="+ father_id+"&xuanpinGET_cg=" + "yes", headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { //console.log(r.response) var jsonObj = $.parseJSON(r.response); $.each(jsonObj, function (key, value) { //下面是采购图片 xphtml=xphtml+"
采品"+key+"×
🔗
"; }); $('#content_cg'+father_id).append(xphtml); } }); } function getxpdata_jp(father_id) { var xphtml = ""; GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "father_id="+ father_id+"&xuanpinGET_jp=" + "yes", headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { // console.log(r.response) var jsonObj = $.parseJSON(r.response); $.each(jsonObj, function (key, value) { //下面是左侧图片 xphtml=xphtml+"
竞品"+key+"×
🔗
"; }); $('#content_jp'+father_id).append(xphtml); } }); } function getxpdata() { var xphtml = ""; $('#xuanpin').html(xphtml) GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "xuanpinGET=" + "yes", headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { // code //console.log(r.response) // 使用jQuery进行JSON格式化 var jsonObj = $.parseJSON(r.response); $.each(jsonObj, function (key, value) { var beijingse=""; if((key+1)%2==1){beijingse="background-color: rgba(128, 128, 128, 0.8);";} xphtml=xphtml+"
"; //下面是左侧图片 xphtml=xphtml+"
选品"+key+"×
🔗
添加当前
连接到竞品"+value.caozuo+"
"; xphtml=xphtml+"
"; var arr = value.neirong.split('哦个'); $.each(arr, function(index1, value1) { if (value1.indexOf("分行") !== -1) { var arr1 = value1.split('分行'); var arrcg1 = value.caigou.split('分行'); $.each(arr1, function(index2, value2) { xphtml=xphtml+"
"; var arr2 = value2.split('分隔'); var arrcg2 = arrcg1[index2].split('分隔'); var kuandu=10; $.each(arr2, function(index3, value3) { if(index2>0 && index3==1){ xphtml=xphtml+""; } else{ xphtml=xphtml+""+value3+""; } }); $.each(arrcg2, function(index4, value4) { if(index2==0){ xphtml=xphtml+""+value4+""; }else{ xphtml=xphtml+""; } }); xphtml=xphtml+"
"; }); } else { if(index1==0){ xphtml=xphtml+"
"; } xphtml=xphtml+"
"+value1+"
"; if(index1==3){ xphtml=xphtml+"
"; xphtml=xphtml+"
添加当前
连接到采品
"; } } }); xphtml=xphtml+"
"; xphtml=xphtml+"
"; xphtml=xphtml+"
"; xphtml=xphtml+""; $('#xuanpin').append(xphtml) xphtml = ""; getxpdata_jp(value.weiyi_ID) getxpdata_cg(value.weiyi_ID) }); } }); } $(document).ready(function () { if (window.location.href.includes('https://detail.1688.com/')) { $('body').append('') } if ($("#modal").length > 0) { $("#modal").append('
打开选品
'); } $(document).on("click", "#toggle", function () { if ($('#sidebar').html() === '') { var divhtml = ''; divhtml = divhtml + '
X
'; divhtml = divhtml + ''; divhtml = divhtml + '
'; // divhtml = divhtml + ''; divhtml = divhtml + '
'; divhtml = divhtml + '
'; divhtml = divhtml + '
'; divhtml = divhtml + ''; $('#toggle').text('点击隐藏'); $('#sidebar').html(divhtml); getxpdata(); $("#sidebar").animate({ width: "1080px" // 设置侧边栏的宽度 }); if (localStorage.getItem('caozuo') != null && localStorage.getItem('caozuo') != "undefined") { // 如果没有 'caozuo',则创建 $("#caozuo").val(localStorage.getItem('caozuo')); } } else { $(this).text('打开选品'); } }); }); //触发通过js动态添加的主品a $(document).on("click", "#add_product", function () { if (!window.location.href.includes('shopee.co.th')) { alert("只能在虾皮详情页加入选品"); return; } if ($("#caozuo").val()=="") { alert("输入代表你的编号或名字"); $("#caozuo").focus(); return; }else{ localStorage.setItem('caozuo',$("#caozuo").val()); } var heji = []; heji.push($('.UBG7wZ:eq(1) picture img').first().attr('src')); $('div').filter('.detail-info-list').each(function () { // 在这里处理每个匹配的div元素 heji.push($(this).text()); }); var bodytr = ""; $('.t-table__header tr').each(function () { $(this).find('th').each(function () { // 在这里处理每个元素 bodytr = bodytr + $(this).text() + "分隔"; }); bodytr = bodytr.replace(/分隔$/, ''); bodytr = bodytr + "分行"; }); //bodytr = bodytr.replace(/分行$/, ''); $('.t-table__body tr').each(function () { $(this).find('td').each(function () { // 在这里处理每个元素 bodytr = bodytr + $(this).text() + "分隔"; }); bodytr = bodytr.replace(/分隔$/, ''); bodytr = bodytr + "分行"; }); bodytr = bodytr.replace(/分行$/, ''); heji.push(bodytr); postdata(encodeURIComponent(JSON.stringify(heji))) }); //触发通过js动态添加的竞品 $(document).on("click", "#add_cgp", function () { // 检查当前窗口的URL是否包含特定字符串 if (!window.location.href.includes('detail.1688.com')) { alert("只能在阿里巴巴加入采购品"); return; } var src = $('.img-list-wrapper [ind="2"]').attr('src'); var fatherid=$(this).data('father-id'); GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "father_id="+ $(this).data('father-id')+"&urlcg=" + encodeURIComponent(window.location.href)+"&picurl=" +src, headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { // code console.log("父亲ID"+fatherid); getxpdata_cg(fatherid) console.log(r) } }); }); //触发删除竞品 $(document).on("click", "#delete_jp", function () { if(!confirm("你确定要删除"+$(this).prev().text()+"吗?")){ return; } var father_id = $(this).data('weiyi-id'); var father_id1 = $(this).data('father-id'); GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "delete_jp="+ father_id, headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { // code console.log(r) if (r.response != "竞品删除成功") { alert("出错了"+r.response); } else { getxpdata_jp(father_id1); } } }); }); //触发删除选品 $(document).on("click", "#delete_xp", function () { if(!confirm("你确定要删除"+$(this).prev().text()+"吗?")){ return; } var father_id = $(this).data('father-id'); GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "delete_xp="+ father_id, headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { // code console.log(r) if (r.response === "删除成功") { $(".xpall"+father_id).remove(); } else { alert("出错了"+r.response); } } }); }); //触发通过js动态添加的竞品 $(document).on("click", "#delete_cp", function () { if(!confirm("你确定要删除"+$(this).prev().text()+"吗?")){ return; } var father_id = $(this).data('father-id'); var weiyi_ID = $(this).data('weiyi-id'); GM_xmlhttpRequest({ method: "post", url: 'https://www.taobaimei.com/thailand/inser_xp.php', data: "delete_cp="+ weiyi_ID, headers: {"Content-Type": "application/x-www-form-urlencoded"}, onload: function (r) { // code getxpdata_cg(father_id) console.log(r) } }); }); //触发通过js动态添加的竞品 $(document).on("click", "#add_jp", function () { // 检查当前窗口的URL是否包含特定字符串 if (!window.location.href.includes('shopee.co.th')) { alert("只能在虾皮详情页加入竞品"); return; } var heji = []; heji.push($('.UBG7wZ picture img').first().attr('src')); $('div').filter('.detail-info-list').each(function () { // 在这里处理每个匹配的div元素 heji.push($(this).text()); }); var bodytr = ""; $('.t-table__header tr').each(function () { $(this).find('th').each(function () { // 在这里处理每个元素 bodytr = bodytr + $(this).text() + "分隔"; }); bodytr = bodytr.replace(/分隔$/, ''); bodytr = bodytr + "分行"; }); //bodytr = bodytr.replace(/分行$/, ''); $('.t-table__body tr').each(function () { $(this).find('td').each(function () { // 在这里处理每个元素 bodytr = bodytr + $(this).text() + "分隔"; }); bodytr = bodytr.replace(/分隔$/, ''); bodytr = bodytr + "分行"; }); bodytr = bodytr.replace(/分行$/, ''); heji.push(bodytr); //console.log(heji) postdata_jp(encodeURIComponent(JSON.stringify(heji)),$(this).data('father-id')) }); //触发通过js动态改变数据列表页 $(document).on("click", ".fuzhia", function () { $('.cg'+$(this).data('custom')).val($(this).prev('input').val()); jisuan_roi($(this)); update_input($(this).data('custom'),$(this)) }); //触发批量修改价格 $(document).on("click", ".fuzhib", function () { $('.xs'+$(this).data('custom')).val($(this).prev('input').val()); jisuan_roi($(this)); update_xiaoshou($(this).data('custom'),$(this)) update_input($(this).data('custom'),$(this)) }); //触发修改单个采购输入款值 $(document).on("change", ".caigoua", function () { jisuan_roi($(this)); update_input($(this).data('custom'),$(this)) }); //触发单个数改变保存 $(document).on("change", ".xiaoshou", function () { console.log("触发单个数改变") jisuan_roi($(this)); update_xiaoshou($(this).data('custom'),$(this)) update_input($(this).data('custom'),$(this)) }); //触发竞品点击改变数据列表页 $(document).on("click", ".fuzhia1", function () { $('.cg'+$(this).data('custom')).val($(this).prev('input').val()); jisuan_roi($(this)); update_input($(this).data('custom'),$(this)) }); //触发竞品点击批量修改价格 $(document).on("click", ".fuzhib1", function () { $('.xs'+$(this).data('custom')).val($(this).prev('input').val()); jisuan_roi($(this)); update_xiaoshou($(this).data('custom'),$(this)) update_input($(this).data('custom'),$(this)) }); //触发竞品点击修改单个采购输入款值 $(document).on("change", ".caigoua1", function () { jisuan_roi($(this)); update_input($(this).data('custom'),$(this)) }); //触发竞品点击单个数改变保存 $(document).on("change", ".xiaoshou1", function () { console.log("触发竞品单个数改变") jisuan_roi($(this)); update_xiaoshou($(this).data('custom'),$(this)) update_input($(this).data('custom'),$(this)) }); //触发通过js动态改变数据列表页 $(document).on("click", ".jingpin_xz", function () { console.log($(this).data('father-id')) var fatherid=$(this).data('father-id') getxpdata_sj($(this).data('weiyi-id'),"xp_jp") setTimeout(function() { // 这里是你想要延迟执行的代码 getxpdata_cg(fatherid) }, 3000); }); //触发选品改变数据列表页 $(document).on("click", ".jingpin_xp", function () { console.log($(this).data('father-id')) var fatherid=$(this).data('father-id') getxpdata_sj($(this).data('weiyi-id'),"xp_xuanpin") setTimeout(function() { // 这里是你想要延迟执行的代码 getxpdata_cg(fatherid) }, 3000); }); $(document).on("click", "#close_sidebar", function () { $('#sidebar').empty(); $("#sidebar").animate({ width: "0" // 设置侧边栏的宽度 }); $("#toggle").text('打开选品'); }); $(document).click(function () { if($("#sidebar").width()=="1080"){ event.stopPropagation(); // 阻止点击事件冒泡到document } //console.log("清空") //$('#sidebar').empty(); //$("#sidebar").animate({ // width: "0" // 设置侧边栏的宽度 // }); // $("#toggle").text('打开选品'); }); // Your code here... })();