// ==UserScript== // @name TEMU欧盟自动选择站点 // @namespace http://tampermonkey.net/ // @version 0.2 // @description 点击按钮或按F8自动执行,步骤间带等待时间 // @author Gemini // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // ================= 配置部分 ================= // 1. 需要勾选的站点列表 const TARGET_SITES = ["德国站", "法国站", "意大利站", "荷兰站", "西班牙站", "葡萄牙站", "瑞典站", "希腊站", "捷克站", "匈牙利站", "比利时站"]; // 2. 统一设置每一步操作后的等待时间 (单位: 毫秒, 1000ms = 1秒) const DELAY_TIME = 300; // =========================================== // 辅助工具:等待元素出现 const waitFor = (selector, timeout = 1000) => { return new Promise((resolve, reject) => { const el = document.querySelector(selector); if (el) return resolve(el); const observer = new MutationObserver(() => { const el = document.querySelector(selector); if (el) { resolve(el); observer.disconnect(); } }); observer.observe(document.body, { childList: true, subtree: true }); setTimeout(() => { observer.disconnect(); reject(`超时未找到: ${selector}`); }, timeout); }); }; // 辅助工具:手动等待函数 const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); // 核心自动化流程 async function startAutomation() { console.log("🚀 自动化流程启动..."); try { // 1. 找到容器并点击第一个指定元素 const step1 = await waitFor("body > div.MDL_outerWrapper_5-120-1.MDL_alert_5-120-1.MDL_showCloseIcon_5-120-1.undefined > div > div > div.MDL_inner_5-120-1 > div.MDL_body_5-120-1 > div.copy-site-modal_siteBlock__WcI\\+O > div > div > div > div > div > div > div"); step1.click(); await sleep(DELAY_TIME); // 🚩 等待 // 2. 点击下拉列表中的第5项 const step2 = await waitFor("body > div.PT_outerWrapper_5-120-1.PP_outerWrapper_5-120-1.ST_dropdown_5-120-1.ST_mediumDropdown_5-120-1.PT_dropdown_5-120-1.PT_portalBottomLeft_5-120-1.PT_inCustom_5-120-1.PP_dropdown_5-120-1 > div > div > div > div > ul > li:nth-child(5)"); step2.click(); await sleep(DELAY_TIME); // 🚩 等待 // 3. 点击指定的 标签链接 const step3 = await waitFor("body > div.MDL_outerWrapper_5-120-1.MDL_alert_5-120-1.MDL_showCloseIcon_5-120-1.undefined > div > div > div.MDL_inner_5-120-1 > div.MDL_body_5-120-1 > div.copy-site-modal_siteBlock__WcI\\+O > div > div.index-module_container__kLF-J > div.index-module_tips__1WQUg > a"); step3.click(); await sleep(DELAY_TIME); // 🚩 等待 // 4. 等待新区域出现并点击“取消全选” // 注意:此处保持你脚本中的 :nth-child(19),如果失效请检查是否变回了 23 const step4 = await waitFor("body > div:nth-child(19) > div > div > div.MDL_inner_5-120-1 > div.MDL_body_5-120-1 > form > div > label"); step4.click(); await sleep(DELAY_TIME); // 🚩 等待 // 5. 循环勾选目标站点 const container = await waitFor("#openedSiteIds > div > div > div > div > div"); const labels = container.querySelectorAll('label[data-testid="beast-core-checkbox"]'); console.log("正在勾选站点..."); for (const label of labels) { const siteName = label.innerText.trim(); const isChecked = label.getAttribute('data-checked') === 'true'; if (TARGET_SITES.includes(siteName) && !isChecked) { label.click(); // 勾选每个站点之间也可以加一个极短的延迟,防止UI卡顿 //await sleep(100); } } await sleep(DELAY_TIME); // 🚩 勾选完所有站后等待 // 6. 点击第一个提交按钮 const submitBtn = await waitFor(".index-module_actions__3gRAa button.BTN_primary_5-120-1"); submitBtn.click(); await sleep(DELAY_TIME); // 🚩 等待确认弹窗弹出 // 7. 点击弹窗确认按钮 const okBtn = await waitFor('button[data-testid="beast-core-modal-ok-button"]'); okBtn.click(); console.log("✅ 全部操作成功完成"); } catch (error) { console.error("❌ 自动化中止:", error); alert("流程中断,可能因为元素未加载或选择器变更。"); } } // --- UI 界面 --- const btn = document.createElement('button'); btn.innerHTML = '⚡ 启动操作'; btn.style.cssText = ` position: fixed; bottom: 20px; left: 20px; z-index: 99999; padding: 10px 20px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.2); font-family: sans-serif; `; btn.onclick = startAutomation; document.body.appendChild(btn); // --- 快捷键 --- window.addEventListener('keydown', (e) => { if (e.key === 'F8') startAutomation(); }); })();