// ==UserScript== // @name 拼多多跨境(Temu)弹窗屏蔽 // @version 1.0 // @description 用于屏蔽拼多多跨境卖家平台的弹窗-jquery重构. // @author linying // @match *://kuajing.pinduoduo.com/* // @match *://seller.kuajingmaihuo.com/* // @match *://kuajingboss.com/* // @match *://agentseller.temu.com/* // @exclude */login* // @exclude */settle/site-main* // @exclude */questionnaire?surveyId=* // @exclude */settle/seller-login?redirectUrl=* // @exclude */agentseller*.temu.com/main/authentication?redirectUrl=* // @exclude */agentseller*.temu.com/mmsos/online-shipping-result.html* // @icon https://gitlab.com/linying23333/green-service-center-temu-or-pinduoduokuajing-2024/raw/main/icon.svg // @supportURL https://gitlab.com/linying23333/green-service-center-temu-or-pinduoduokuajing-2024 // @homepage https://github.com/linying2333 // @require https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js // @run-at document-idle // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM.setValue // @grant GM.getValue // @grant GM.deleteValue // @grant GM_registerMenuCommand // ==/UserScript== // @icon 来自 https://www.iconfont.cn/ 如果侵犯您的权利请与我沟通 // @note 更新日志&常见问题解决:https://gitlab.com/linying23333/green-service-center-temu-or-pinduoduokuajing-2024/raw/main/Readme.md // @note 本js用户脚本版权归linying所有,仅供研究学习,禁止以任何形式倒卖 //于北京时间 2024/06/10 03:33:11 使用通义千问2.5+ChatGPT3.5以jQuery 2.2.4重构 'use strict'; this.$ = this.jQuery = jQuery.noConflict(true); // 防止网页与使用的jquery.2.2.4.min.js发生冲突 /* 防止代码因其他原因被执行多次 这段代码出自 Via轻插件,作者谷花泰 */ var key = encodeURIComponent('拼多多跨境(Temu)弹窗屏蔽'); if (window[key]) return; window[key] = true; // 初始化默认数据库 var value = [ // 参数需要根据您的电脑加载速度而定,切勿无脑调低或者调高 // 基础设置 // 设置配置文件版本(为未来预留) {name: 'setting_Config_Version', value: '1'}, // 启动后进行删除的等待时间: // 值设置为 0 不启用,默认推荐值为3800 // 单位毫秒,1秒 = 1000毫秒 {name: 'setting_Start_Wait_Time', value: '4200'}, // 是否展示调价菜单 // 默认true(开启),使用false(关闭) {name: 'setting_Show_Price_Menu', value: 'true'}, // 快速模式设置 // 快速删除模式的删除间隔时间: // 默认推荐值为100 // 单位毫秒,1秒 = 1000毫秒 {name: 'setting_Fast_Remove_Interval_Time', value: '1'}, // 快速删除持续删除时间 // 默认推荐值为8000 // 单位毫秒,1秒 = 1000毫秒 {name: 'setting_Fast_Remove_Duration', value: '1'}, // 'setting_Fast_Remove_Interval_Time'与'setting_Fast_Remove_Duration'同时设置为 1 不启用 // 是否弹出快速删除结束提示框 // 默认false(关闭),使用true(开启) {name: 'setting_Show_Fast_Remove_Stopped_Alert', value: 'false'}, // 手动清除按钮设置 // 设置是否添加手动清除按钮 // 默认true(开启),使用false(关闭) {name: 'setting_Add_Manual_Clear_Button', value: 'true'}, // 设置按钮加载位置默认值 // 位置从浏览器屏幕左上角开始计算,X轴+1则向右移动,Y轴+1则向下移动 // 参数需要带单位(受支持的单位 百分比"%",像素点"px") // 按钮的X轴(纵向)值 {name: 'setting_Add_Manual_Clear_Button_X', value: '30%'}, // 按钮的Y轴(纵向)值 {name: 'setting_Add_Manual_Clear_Button_Y', value: '92%'}, // 在多长时间内快速点击3次移动按钮打开设置 // 默认推荐值为400 // 单位毫秒,1秒 = 1000毫秒 {name: 'setting_Quickly_Click_3Times_To_Open_Settings_Check_Time', value: '500'}, // 调试模式日志输出 // 默认false(关闭),使用true(开启) {name: 'setting_Print_DebugMode_Log', value: 'false'} ]; $.each(value, function(index, Event) { var setValue = Event.value; // 先获取原始值 // 特别处理布尔类型的值 if (Event.value === 'true' || Event.value === 'false') { setValue = Event.value === 'true'; } // 如果没有对应的配置项,则为油猴存储添加配置项,确保值为期望的类型 if (!GM_getValue(Event.name)) {GM_setValue(Event.name, setValue)}; }); // 初始化变量 var Button_X = GM_getValue('setting_Add_Manual_Clear_Button_X'), Button_Y = GM_getValue('setting_Add_Manual_Clear_Button_Y'); // 创建 GreaseMonkey 菜单 (function CreateMenu() { GM_registerMenuCommand('⚙️ 设置', LoadSettingsPanel); var Status = GM_getValue('setting_Print_DebugMode_Log'); GM_registerMenuCommand('🛠️ 打印控制台调试日志状态切换 | 首次加载状态:' + Status, () => { // 先进行状态切换 Status = !Status // 将字符串'true','false'转换为布尔值'true','false' let boolValue = (Status === 'true') ? true : (Status === 'false') ? false : Status; GM_setValue('setting_Print_DebugMode_Log', boolValue); // 提示刷新网页使其生效 alert('打印调试日志状态已经更新为' + boolValue + '\n请手动刷新网页使其油猴菜单文字刷新'); }); })(); // 全局定义是否打印日志调用函数 function log(message) { if (GM_getValue('setting_Print_DebugMode_Log')) { console.log('来自 拼多多跨境(Temu)弹窗屏蔽 js用户脚本提示:\n' + message); } } // 启动时检查并提示调试模式状态 (function checkDebugModeStatus() { var debugMode = GM_getValue('setting_Print_DebugMode_Log'); console.log(`当前 Debug 模式已设置为: ${debugMode}, 调试日志${debugMode ? '已' : '未'}启用.`); })(); // 按钮处理部分 // 检查是否启用该部分 if (GM_getValue('setting_Add_Manual_Clear_Button')) { (function() { // 创建新的div并设置属性 var $div = $('
', { id: 'js_button_div', css: { cssText: 'z-index: 2147483648 !important;', // 在css对象中添加cssText position: 'fixed', top: GM_getValue('setting_Add_Manual_Clear_Button_Y'), left: GM_getValue('setting_Add_Manual_Clear_Button_X'), '-webkit-user-select': 'none', /* 对于Webkit和Mozilla浏览器,IE浏览器应使用'unselectable' */ '-moz-user-select': 'none', /* 对于早期的Firefox */ '-ms-user-select': 'none', /* 对于早期的Chrome和Safari */ 'user-select': 'none' /* IE 10+ */ } }); // 添加div到body之后 $('body').after($div); // 创建移动按钮 var $eventMoveButton = $(' `); $(document).ready(function() { $('#js_setting_reset').on('click', function() { value.forEach((event) => { GM_deleteValue(event.name); }); alert('配置项已被重置!'); }); }); $(document).ready(function() { $('#js_setting_save').on('click', function() { let elements = $('.js_setting_input'); let number = 10; if (elements.length === number) { elements.each(function(index) { let boolValue = $(this).val() === 'true' ? true : $(this).val() === 'false' ? false : $(this).val(); GM_setValue(value[index + 1].name, boolValue); // 注意索引从1开始,跳过版本信息 console.log(`目前是第 ${index + 1} 个输入框,\n数据库数据名:${value[index + 1].name} 的\n值已经设置为: ${GM_getValue(value[index + 1].name)}`); }); alert('配置项已被保存!'); } else { console.error("输入框数量不符,实际数量:" + elements.length + ", 预期数量:" + number); alert('配置项保存失败,输入框数量不匹配!'); return; // 避免在配置未正确处理时继续执行后续逻辑 } }); }); } // 显示等待开始执行的提示信息 insertModalDivs(`

来自 拼多多跨境(Temu)弹窗屏蔽 js用户脚本提示:


将会等待 ${GM_getValue('setting_Start_Wait_Time') / 1000} 秒后开始执行删除
`); // 在指定延迟后开始执行 setTimeout(function() { insertModalDivs('

来自 拼多多跨境(Temu)弹窗屏蔽 js用户脚本提示:


开始操作
'); // 确保DOM准备就绪后立即执行remove操作 setTimeout(remove, 0); }, GM_getValue('setting_Start_Wait_Time')); // remove 函数的实现保持不变 function remove() { if (document.readyState === 'loading') { $(document).ready(startInterval); } else { startInterval(); } } let intervalId; function startInterval() { intervalId = setInterval(removeElements, GM_getValue('setting_Fast_Remove_Interval_Time')); setTimeout(function() { clearInterval(intervalId); if (GM_getValue('setting_Fast_Remove_Interval_Time') !== GM_getValue('setting_Fast_Remove_Duration')) { log(`${GM_getValue('setting_Fast_Remove_Duration')} 毫秒已过,停止删除操作.`); if (GM_getValue('setting_Show_Fast_Remove_Stopped_Alert')) { alert(`设置的循环时间 ${GM_getValue('setting_Fast_Remove_Duration')} 毫秒到了,您可以继续操作了.`); } } else { log('快速模式未启用'); } }, GM_getValue('setting_Fast_Remove_Duration')); } function removeElements() { // 移除具有特定id属性的div元素(js_info) $('div#js_info').remove(); // 查找并删除具有特定data-testid属性的div元素 $('div[data-testid="beast-core-modal"]').each(function() { let shouldRemoveParent = true; // 查找 modalDiv 之前的具有 data-testid="beast-core-modal-mask" 的 div 元素 let $maskDiv = $(this).prevAll('div[data-testid="beast-core-modal-mask"]').first(); // 如果GM_getValue('setting_Show_Price_Menu')为false,则直接删除元素,不检查子结构 if (!GM_getValue('setting_Show_Price_Menu')) { $(this).remove(); return; } // 查找包含“切换店铺”文本的div const $switchShopDiv = $(this).find('.layout_title__1eHi_'); if ($switchShopDiv.length && $switchShopDiv.text().trim().includes('切换店铺')) { shouldRemoveParent = false; } // 检查是否有包含"调价原因"的元素 const $headers = $(this).find('.TB_thead_5-109-0 .TB_th_5-109-0'); const hasReasonHeader = $headers.filter(function() { return $(this).text().trim().includes('调价原因'); }).length > 0; if (hasReasonHeader) { shouldRemoveParent = false; } // 根据shouldRemoveParent的值执行操作 if (shouldRemoveParent) { log('没有找到包含 "调价原因" 或 "切换店铺" 的元素'); $(this).remove(); // 删除对应的maskDiv if ($maskDiv.length) { $maskDiv.remove(); } } else { log('找到包含 "调价原因" 或 "切换店铺" 的元素'); } }); // 延迟执行删除空div的操作 setTimeout(removeEmptyDivsAtBodyEnd, GM_getValue('setting_Start_Wait_Time') + GM_getValue('setting_Fast_Remove_Duration') + 10000); } function insertModalDivs(InputHTML) { // 创建并设置模态框div var $div = $('
', { id: 'js_info', align: 'center', css: { cssText: 'z-index: 2147483648 !important;', // 在css对象中添加cssText 'overflow-y': 'auto', 'max-height': '90%', position: 'fixed', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', 'background-color': '#000', color: '#fff', padding: '10px', border: '1px solid #ccc', 'box-shadow': '0 0 10px rgba(0, 0, 0, 0.3)' }, html: ` × ${InputHTML} ` }); // 添加div到body之后 $('body').after($div); } // 防抖函数实现 function debounce(func, wait) { let timeout; return function() { const context = this; const args = arguments; clearTimeout(timeout); timeout = setTimeout(() => func.apply(context, args), wait); }; } // 监听切换功能区 $('.index-module__menuBox___2aaTA').on('click', debounce(function(event) { if ($(event.target).closest('.index-module__menuBox___2aaTA').length) { var $mmsDescendant = $(event.target).closest('.bg-shell-theme-menu-mms'); if ($mmsDescendant.length) { var $menuDescendant = $(event.target).closest('.index-module__menu___3Wyz- .bg-shell-theme-menu'); if ($menuDescendant.length && $mmsDescendant[0] !== $menuDescendant.parent()[0]) { log('匹配到.index-module__menu___3Wyz- .bg-shell-theme-menu .bg-shell-theme-menu-mms下的.index-module__menu___3Wyz- .bg-shell-theme-menu的后代元素触发的点击'); var longtimelist = ['/goods/product/list', '/main/sale-manage/main']; setTimeout(function() { log('等待 100 毫秒,加载网址进行匹配'); var currentPath = window.location.pathname; var time = longtimelist.includes(currentPath) ? 1400 : 960; setTimeout(function() { log(`已经等待 ${time} 毫秒,执行删除函数`); removeElements(); setTimeout(CheckWebError, 1000); }, time); }, 100); } } } }, 1000)); // 删除尾部空div的函数 function removeEmptyDivsAtBodyEnd() { var $lastChild = $('body').children().last(); while ($lastChild.is('div') && !$lastChild.text().trim()) { $lastChild.remove(); $lastChild = $('body').children().last(); } } function CheckWebError() { const $rootDiv = $('#root'); if (!$rootDiv.length) { log('未找到ID为"root"的div元素'); return; } const commentsToFind = [ '', '', '' ]; let allCommentsFound = true; $rootDiv.contents().each(function(index, childNode) { if (index >= 3 || !commentsToFind.some(comment => $(childNode).text().includes(comment.trim()))) { allCommentsFound = false; return false; // Break the loop } }); if (allCommentsFound) { log('找到所有定义的错误注释,刷新网页'); insertModalDivs(`

检测到网页错误,为您刷新

`); location.reload(); // 刷新页面 } else { log('未找到所有定义的错误注释,保持原样'); } }