// ==UserScript== // @name link工具 // @namespace http://tampermonkey.net/ // @version 0.6.2 // @description 点击复制,提取链接,快捷截图 // @author lwj // @match https://* // @license MIT // @grant GM_setValue // @grant GM_getValue // @grant GM_setClipboard // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== (function () { // 检查当前页面 URL 是否匹配指定的网址 var isHomeURL = function () { var currentURL = window.location.href; return currentURL.indexOf("https://m.linkmcn.com/#/live/plan?select=") !== -1; }; var isTableCardURL = function () { return window.location.href.indexOf("https://m.linkmcn.com/#/live/plan/tableCard/") !== -1; }; var versionTitleTxt = 'Version 0.6.2'; // 存储当前网址的变量 let lastCurrentURL = window.location.href; // 初始化开关状态 var copySwitchState = localStorage.getItem('copySwitchState') === 'true'; var toggleSwitchState = localStorage.getItem('toggleSwitchState') === 'true'; var mainOnlyItemIdSwitchState = localStorage.getItem('mainOnlyItemIdSwitchState') === 'true'; var tableCardPngSwitchState = localStorage.getItem('tableCardPngSwitchState') === 'true'; var mainItemSortSwitchState = localStorage.getItem('mainItemSortSwitchState') === 'true'; var notificationTimer; // 通知计时器 var isHiding = false; // 标志,表示是否正在隐藏通知 var countNum_Sort = 0;// 计数排序功能默认值 let temp_itemId = ''; // 创建开关容器元素 var switchesContainer = document.createElement('div'); switchesContainer.classList.add('flex', 'items-center', 'justify-between', 'pb-12'); switchesContainer.style.cssText = 'position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 9999;'; if (isHomeURL()) { document.body.appendChild(switchesContainer); } // 创建点击复制开关元素 var copySwitchContainer = document.createElement('div'); copySwitchContainer.classList.add('flex', 'items-center'); var copySwitchText = document.createElement('span'); copySwitchText.textContent = '点击店名复制'; copySwitchText.classList.add('mr-8', 'ml-4', 'lh-22'); copySwitchContainer.appendChild(copySwitchText); var copySwitch = document.createElement('button'); copySwitch.innerHTML = '
'; copySwitch.setAttribute('type', 'button'); copySwitch.setAttribute('role', 'switch'); copySwitch.setAttribute('aria-checked', copySwitchState); // 设置开关状态 copySwitch.classList.add('ant-switch', 'css-9fw9up'); if (copySwitchState) { copySwitch.classList.add('ant-switch-checked'); // 开启 } copySwitchContainer.appendChild(copySwitch); switchesContainer.appendChild(copySwitchContainer); // 封装函数返回SVG图标 function createSVGIcon() { var svgIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg"); svgIcon.setAttribute('class', 'icon custom-svg'); // 添加自定义类名 svgIcon.setAttribute('viewBox', '0 0 1024 1024'); svgIcon.setAttribute('width', '20'); svgIcon.setAttribute('height', '20'); svgIcon.setAttribute('fill', '#bbbbbb'); svgIcon.innerHTML = ''; svgIcon.style.cssText = 'vertical-align: middle;'; // 垂直居中样式 return svgIcon; } // 添加事件监听用于下拉箭头 document.addEventListener('mouseenter', function (event) { if (event.target instanceof Element && event.target.matches('svg.icon.custom-svg')) { // 仅匹配具有自定义类名的SVG event.target.setAttribute('fill', '#ff6200'); } }, true); document.addEventListener('mouseleave', function (event) { if (event.target instanceof Element && event.target.matches('svg.icon.custom-svg')) { // 仅匹配具有自定义类名的SVG event.target.setAttribute('fill', '#bbbbbb'); } }, true); // 创建下拉菜单容器 var dropdownContainer = document.createElement('div'); dropdownContainer.style.cssText = 'position: relative; display: inline-block;'; var dropdownButton = document.createElement('button'); dropdownButton.textContent = '更多功能'; dropdownButton.style.cssText = 'margin-left: 20px; padding: 5px 10px; cursor: pointer; border-radius: 999px;'; dropdownButton.classList.add('ant-btn', 'css-9fw9up', 'ant-btn-default', 'primaryButton___N3z1x'); dropdownContainer.appendChild(dropdownButton); // 创建下拉菜单内容 var dropdownContent = document.createElement('div'); dropdownContent.style.cssText = ` display: none; position: absolute; background-color: #f9f9f9; min-width: 200px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; border-radius: 10px; max-height: 355px; overflow-y: auto; /* 使用 auto 可以根据内容是否溢出显示滚动条 */ scrollbar-width: none; /* 隐藏滚动条,适用于 Firefox */ -ms-overflow-style: none; /* 隐藏滚动条,适用于 IE 和 Edge */ `; // 创建快捷粘贴搜索开关元素 var toggleSwitchContainer = document.createElement('div'); toggleSwitchContainer.classList.add('flex', 'items-center', 'dropdown-item'); toggleSwitchContainer.style.cssText = 'padding: 12px 16px; cursor: pointer; display: flex; justify-content: space-between;'; var toggleSwitchText = document.createElement('span'); toggleSwitchText.textContent = '快捷粘贴搜索'; toggleSwitchText.classList.add('lh-22'); toggleSwitchContainer.appendChild(toggleSwitchText); var toggleSwitch = document.createElement('button'); toggleSwitch.innerHTML = '
'; toggleSwitch.setAttribute('type', 'button'); toggleSwitch.setAttribute('role', 'switch'); toggleSwitch.setAttribute('aria-checked', toggleSwitchState); // 设置开关状态 toggleSwitch.classList.add('ant-switch', 'css-9fw9up'); if (toggleSwitchState) { toggleSwitch.classList.add('ant-switch-checked'); } toggleSwitchContainer.appendChild(toggleSwitch); // 创建手卡快捷截图开关元素 var tableCardPngSwitchContainer = document.createElement('div'); tableCardPngSwitchContainer.classList.add('flex', 'items-center', 'dropdown-item'); tableCardPngSwitchContainer.style.cssText = 'padding: 12px 16px; cursor: pointer; display: flex; justify-content: space-between;'; var tableCardPngSwitchText = document.createElement('span'); tableCardPngSwitchText.textContent = '手卡快捷截图'; tableCardPngSwitchText.classList.add('lh-22'); tableCardPngSwitchContainer.appendChild(tableCardPngSwitchText); var tableCardPngSwitch = document.createElement('button'); tableCardPngSwitch.innerHTML = '
'; tableCardPngSwitch.setAttribute('type', 'button'); tableCardPngSwitch.setAttribute('role', 'switch'); tableCardPngSwitch.setAttribute('aria-checked', tableCardPngSwitchState); // 设置开关状态 tableCardPngSwitch.classList.add('ant-switch', 'css-9fw9up'); if (tableCardPngSwitchState) { tableCardPngSwitch.classList.add('ant-switch-checked'); } tableCardPngSwitchContainer.appendChild(tableCardPngSwitch); // 创建提取商品链接按钮容器 var onlyItemIdButtonContainer = document.createElement('div'); var mainOnlyItemIdSwitch;// 声明开关元素 // 声明自动点击开关元素与开关状态生成 var sonSwitch_onlyItemId_autoClick; var sonSwitch_onlyItemId_autoClick_State = localStorage.getItem('sonSwitch_onlyItemId_autoClick_State') === 'true'; // 声明检查开关元素与开关状态生成 var sonSwitch_onlyItemId_checkId; var sonSwitch_onlyItemId_checkId_State = localStorage.getItem('sonSwitch_onlyItemId_checkId_State') === 'true'; onlyItemIdButtonContainer.classList.add('flex', 'items-center', 'dropdown-item'); onlyItemIdButtonContainer.style.cssText = 'padding: 12px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center;'; // 创建提取商品链接按钮文本 var onlyItemIdButtonText = document.createElement('span'); onlyItemIdButtonText.textContent = '链接自动提取'; onlyItemIdButtonText.classList.add('lh-22'); onlyItemIdButtonContainer.appendChild(onlyItemIdButtonText); // 创建提取商品链接按钮 var onlyItemIdButton = document.createElement('button'); onlyItemIdButton.style.cssText = 'background: none; border: none; font-size: 16px; cursor: pointer; transition: transform 0.3s;margin: 0px 6px'; onlyItemIdButtonContainer.appendChild(onlyItemIdButton); // 添加svg图片 onlyItemIdButton.appendChild(createSVGIcon()); // 创建商品排序按钮容器 var itemSortButtonContainer = document.createElement('div'); var mainItemSortSwitch;// 声明开关元素 // 声明测试功能开关元素与开关状态生成 var sonSwitch_itemSort_testFun; var sonSwitch_itemSort_testFun_State = localStorage.getItem('sonSwitch_itemSort_testFun_State') === 'true'; itemSortButtonContainer.classList.add('flex', 'items-center', 'dropdown-item'); itemSortButtonContainer.style.cssText = 'padding: 12px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center;'; // 创建商品排序按钮文本 var itemSortButtonText = document.createElement('span'); itemSortButtonText.textContent = '商品排序'; itemSortButtonText.classList.add('lh-22'); itemSortButtonContainer.appendChild(itemSortButtonText); // 创建商品排序按钮 var itemSortButton = document.createElement('button'); itemSortButton.style.cssText = 'background: none; border: none; font-size: 16px; cursor: pointer; transition: transform 0.3s;margin: 0px 6px'; itemSortButtonContainer.appendChild(itemSortButton); // 添加svg图片 itemSortButton.appendChild(createSVGIcon()); var versionTitle = document.createElement('p'); versionTitle.textContent = versionTitleTxt; versionTitle.style.cssText = ` font-size: 12px; line-height: 1.8; /* 调整行高 */ margin: 0 20px; justify-content: center; /* 使用 flex 居中对齐 */ align-items: center; border-top: 1px solid #D2D2D2; text-align: center; /* 居中文本 */ color: #9B9B9B; display: flex; /* 添加 display: flex 以使用 flexbox 布局 */ `; // 将开关和按钮加入页面 dropdownContent.appendChild(toggleSwitchContainer); dropdownContent.appendChild(onlyItemIdButtonContainer); dropdownContent.appendChild(tableCardPngSwitchContainer); dropdownContent.appendChild(itemSortButtonContainer); dropdownContent.appendChild(versionTitle); dropdownContainer.appendChild(dropdownContent); switchesContainer.appendChild(dropdownContainer); // 下拉按钮点击事件 dropdownButton.addEventListener('click', function () { dropdownContent.style.display = dropdownContent.style.display === 'none' ? 'block' : 'none'; }); // 点击外部区域隐藏下拉菜单 window.addEventListener('click', function (event) { if (!dropdownContainer.contains(event.target)) { dropdownContent.style.display = 'none'; } }); var notification_style = document.createElement('style'); notification_style.type = 'text/css'; notification_style.innerHTML = ` @keyframes showNotification { 0% { transform: translateX(-50%) scale(0); } 40% { transform: translateX(-50%) scale(.96); } 55% { transform: translateX(-50%) scale(1.04); } 100% { transform: translateX(-50%) scale(1); } } @keyframes hideNotification { 5% { transform: translateX(-50%) scale(1); } 100% { opacity: 0; transform: translateX(-50%) scale(0.2); } } .notification { position: fixed; bottom: 60px; left: 50%; background-color: rgba(0, 0, 0, 0.5); color: #fff; padding: 10px; border-radius: 12px; display: none; z-index: 9999; backdrop-filter: blur(10px) brightness(90%); /* 添加模糊效果 */ -webkit-backdrop-filter: blur(10px); /* 兼容Safari浏览器 */ transform-origin: center; width: auto; /* 默认宽度 */ max-width: 68%; white-space: nowrap; /* 单行显示 */ overflow: hidden; /* 超出内容隐藏 */ text-overflow: ellipsis; /* 溢出省略号 */ text-align: center; /* 文本居中显示 */ transform: translateX(-50%); /* 初始水平居中 */ } `; document.head.appendChild(notification_style); // 创建通知弹窗 var NotificationContainer = document.createElement('div'); NotificationContainer.classList.add('notification'); document.body.appendChild(NotificationContainer); // 获取开关元素 var copySwitchHandle = copySwitch.querySelector('.ant-switch-handle'); var toggleSwitchHandle = toggleSwitch.querySelector('.ant-switch-handle'); var tableCardPngSwitchHandle = tableCardPngSwitch.querySelector('.ant-switch-handle'); // 更新本地存储的开关状态 var updateSwitchState = function (switchName, newState) { localStorage.setItem(switchName, newState.toString()); }; // 监听开关点击事件 copySwitch.addEventListener('click', function () { var newState = copySwitch.getAttribute('aria-checked') === 'true' ? false : true; copySwitch.setAttribute('aria-checked', newState); if (newState) { copySwitch.classList.add('ant-switch-checked'); showNotification("点击店名复制:开启"); } else { copySwitch.classList.remove('ant-switch-checked'); showNotification("点击店名复制:关闭"); } updateSwitchState('copySwitchState', newState); }); toggleSwitch.addEventListener('click', function () { var newState = toggleSwitch.getAttribute('aria-checked') === 'true' ? false : true; toggleSwitch.setAttribute('aria-checked', newState); if (newState) { toggleSwitch.classList.add('ant-switch-checked'); showNotification("快捷粘贴搜索:开启"); } else { toggleSwitch.classList.remove('ant-switch-checked'); showNotification("快捷粘贴搜索:关闭"); } updateSwitchState('toggleSwitchState', newState); }); // 手卡快捷截图开关点击事件 tableCardPngSwitch.addEventListener('click', function () { var newState = tableCardPngSwitch.getAttribute('aria-checked') === 'true' ? false : true; tableCardPngSwitch.setAttribute('aria-checked', newState); if (newState) { tableCardPngSwitch.classList.add('ant-switch-checked'); showNotification("手卡快捷截图:开启"); } else { tableCardPngSwitch.classList.remove('ant-switch-checked'); showNotification("手卡快捷截图:关闭"); } updateSwitchState('tableCardPngSwitchState', newState); }); // 通用子菜单容器样式的函数 function initializeContainerStyle(container, state) { if (!state) { container.style.opacity = '0.4';// 设置透明度使内容变浅 container.style.pointerEvents = 'none';// 禁止点击操作 } else { container.style.opacity = '';// 恢复透明度 container.style.pointerEvents = '';// 恢复点击操作 } } // 提取商品链接按钮点击事件 // 提取商品链接设置页面逻辑区 // 创建提取商品链接二级页面内容 var secondaryContent = document.createElement('div'); secondaryContent.id = 'secondary-content'; secondaryContent.style.cssText = 'margin: 0px 10px; display:none; padding: 10px 12px; background: #E9E9E9; border: 1px solid #D2D2D2; border-radius: 10px;'; // 创建设置页面 var contentContainer = document.createElement('div'); contentContainer.style.cssText = 'display: flex; justify-content: space-between; align-items: center;'; // 创建标题 var title = document.createElement('p'); title.textContent = '提取商品链接'; title.style.cssText = 'font-size: 14px; margin: 0;'; contentContainer.appendChild(title); // 子选项设置页面 var sonContentContainer = document.createElement('div'); sonContentContainer.style.cssText = 'display: block; justify-content: space-between; align-items: center;'; // 创建开关 mainOnlyItemIdSwitch = document.createElement('button'); mainOnlyItemIdSwitch.innerHTML = '
'; mainOnlyItemIdSwitch.setAttribute('type', 'button'); mainOnlyItemIdSwitch.setAttribute('role', 'switch'); mainOnlyItemIdSwitch.setAttribute('aria-checked', mainOnlyItemIdSwitchState); // 设置开关状态 mainOnlyItemIdSwitch.classList.add('ant-switch', 'css-9fw9up', 'ant-switch-small'); if (mainOnlyItemIdSwitchState) { mainOnlyItemIdSwitch.classList.add('ant-switch-checked'); } else { initializeContainerStyle(sonContentContainer, false);// 使用函数初始化 } // 主功能说明容器 var mainIllustrate = document.createElement('div'); mainIllustrate.style.cssText = 'font-size: 12px; color: #9B9B9B; margin: 5px 0px; padding-bottom: 5px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #D2D2D2;'; mainIllustrate.textContent = '当点击商品链接窗口时,会主动提取当前剪切板中的商品链接,并更新你的剪切板'; contentContainer.appendChild(mainOnlyItemIdSwitch); secondaryContent.appendChild(contentContainer); secondaryContent.appendChild(mainIllustrate); // 子选项设置页面 上放!! secondaryContent.appendChild(sonContentContainer); // 自动保存开关页面 var autoClickSwitch = document.createElement('div'); autoClickSwitch.style.cssText = 'display: flex; justify-content: space-between; align-items: center;'; // 自动保存开关标题 var autoClickTitle = document.createElement('p'); autoClickTitle.textContent = '自动保存'; autoClickTitle.style.cssText = 'font-size: 14px; margin: 0;'; autoClickSwitch.appendChild(autoClickTitle); // 创建自动保存开关元素 sonSwitch_onlyItemId_autoClick = document.createElement('button'); sonSwitch_onlyItemId_autoClick.innerHTML = '
'; sonSwitch_onlyItemId_autoClick.setAttribute('type', 'button'); sonSwitch_onlyItemId_autoClick.setAttribute('role', 'switch'); sonSwitch_onlyItemId_autoClick.setAttribute('aria-checked', sonSwitch_onlyItemId_autoClick_State); // 设置开关状态 sonSwitch_onlyItemId_autoClick.classList.add('ant-switch', 'css-9fw9up', 'ant-switch-small'); if (sonSwitch_onlyItemId_autoClick_State) { sonSwitch_onlyItemId_autoClick.classList.add('ant-switch-checked'); } // 自动保存功能说明容器 var autoClickIllustrate = document.createElement('div'); autoClickIllustrate.style.cssText = 'font-size: 12px; color: #9B9B9B; margin: 5px 0px; padding-bottom: 5px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #D2D2D2;'; autoClickIllustrate.textContent = '替换链接后自动点击“保存”按钮'; // 链接检查开关页面 var checkIdSwitch = document.createElement('div'); checkIdSwitch.style.cssText = 'display: flex; justify-content: space-between; align-items: center;'; // 链接检查开关标题 var checkIdTitle = document.createElement('p'); checkIdTitle.textContent = '链接检查'; checkIdTitle.style.cssText = 'font-size: 14px; margin: 0;'; checkIdSwitch.appendChild(checkIdTitle); // 创建链接检查开关元素 sonSwitch_onlyItemId_checkId = document.createElement('button'); sonSwitch_onlyItemId_checkId.innerHTML = '
'; sonSwitch_onlyItemId_checkId.setAttribute('type', 'button'); sonSwitch_onlyItemId_checkId.setAttribute('role', 'switch'); sonSwitch_onlyItemId_checkId.setAttribute('aria-checked', sonSwitch_onlyItemId_checkId_State); // 设置开关状态 sonSwitch_onlyItemId_checkId.classList.add('ant-switch', 'css-9fw9up', 'ant-switch-small'); if (sonSwitch_onlyItemId_checkId_State) { sonSwitch_onlyItemId_checkId.classList.add('ant-switch-checked'); } // 链接检查功能说明容器 var checkIdIllustrate = document.createElement('div'); checkIdIllustrate.style.cssText = 'font-size: 12px; color: #9B9B9B; margin: 5px 0px; padding-bottom: 5px; display: flex; justify-content: space-between; align-items: center; border-bottom: 0px solid #D2D2D2; white-space: pre-line;'; checkIdIllustrate.textContent = '链接中不存在12位ID时,使用“警告”替换当前剪切板\n开启此功能会引起剪切板冲突'; // 自动保存加入autoClickSwitch页面 autoClickSwitch.appendChild(sonSwitch_onlyItemId_autoClick); // 链接检查加入checkIdSwitch页面 checkIdSwitch.appendChild(sonSwitch_onlyItemId_checkId); sonContentContainer.appendChild(autoClickSwitch); sonContentContainer.appendChild(autoClickIllustrate); sonContentContainer.appendChild(checkIdSwitch); sonContentContainer.appendChild(checkIdIllustrate); // 将二级页面内容插入到 onlyItemIdButtonContainer 的下方 onlyItemIdButtonContainer.parentNode.insertBefore(secondaryContent, onlyItemIdButtonContainer.nextSibling); // 监听onlyItemId主功能开关状态 mainOnlyItemIdSwitch.addEventListener('click', function () { var newState = mainOnlyItemIdSwitch.getAttribute('aria-checked') === 'true' ? false : true; mainOnlyItemIdSwitch.setAttribute('aria-checked', newState); if (newState) { mainOnlyItemIdSwitch.classList.add('ant-switch-checked'); showNotification("提取商品链接:开启"); } else { mainOnlyItemIdSwitch.classList.remove('ant-switch-checked'); showNotification("提取商品链接:关闭"); } updateSwitchState('mainOnlyItemIdSwitchState', newState); // 获取sonContentContainer容器内的所有输入元素 var inputs = sonContentContainer.querySelectorAll('input, select, textarea, button'); inputs.forEach(function (input) { input.disabled = !newState; }); initializeContainerStyle(sonContentContainer, newState); }); // 监听onlyItemId自动保存开关状态 sonSwitch_onlyItemId_autoClick.addEventListener('click', function () { var newState = sonSwitch_onlyItemId_autoClick.getAttribute('aria-checked') === 'true' ? false : true; sonSwitch_onlyItemId_autoClick.setAttribute('aria-checked', newState); if (newState) { sonSwitch_onlyItemId_autoClick.classList.add('ant-switch-checked'); } else { sonSwitch_onlyItemId_autoClick.classList.remove('ant-switch-checked'); } updateSwitchState('sonSwitch_onlyItemId_autoClick_State', newState); }); // 监听onlyItemId链接检查开关状态 sonSwitch_onlyItemId_checkId.addEventListener('click', function () { var newState = sonSwitch_onlyItemId_checkId.getAttribute('aria-checked') === 'true' ? false : true; sonSwitch_onlyItemId_checkId.setAttribute('aria-checked', newState); if (newState) { sonSwitch_onlyItemId_checkId.classList.add('ant-switch-checked'); } else { sonSwitch_onlyItemId_checkId.classList.remove('ant-switch-checked'); } updateSwitchState('sonSwitch_onlyItemId_checkId_State', newState); }); onlyItemIdButton.addEventListener('click', function () { // 切换二级页面显示状态 secondaryContent = document.getElementById('secondary-content'); if (secondaryContent) { secondaryContent.style.display = secondaryContent.style.display === 'block' ? 'none' : 'block'; } else { console.log("onlyItemId二级页面异常") } // 旋转按钮图标 var icon = onlyItemIdButton.querySelector('svg'); var rotation = icon.style.transform === 'rotate(90deg)' ? 'rotate(0deg)' : 'rotate(90deg)'; icon.style.transform = rotation; }); // 商品排序按钮点击事件 // 商品排序设置页面逻辑区 // 创建商品排序二级页面内容 var itemSort_secondaryContent = document.createElement('div'); itemSort_secondaryContent.id = 'itemSort_secondary-content'; itemSort_secondaryContent.style.cssText = 'margin: 0px 10px; display:none; padding: 10px 12px; background: #E9E9E9; border: 1px solid #D2D2D2; border-radius: 10px;'; // 创建设置页面 var itemSort_contentContainer = document.createElement('div'); itemSort_contentContainer.style.cssText = 'display: flex; justify-content: space-between; align-items: center;'; // 创建标题 var itemSort_title = document.createElement('p'); itemSort_title.textContent = '自动填充'; itemSort_title.style.cssText = 'font-size: 14px; margin: 0;'; itemSort_contentContainer.appendChild(itemSort_title); // 子选项设置页面 var sonitemSort_contentContainer = document.createElement('div'); sonitemSort_contentContainer.style.cssText = 'display: block; justify-content: space-between; align-items: center;'; // 创建开关 mainItemSortSwitch = document.createElement('button'); mainItemSortSwitch.innerHTML = '
'; mainItemSortSwitch.setAttribute('type', 'button'); mainItemSortSwitch.setAttribute('role', 'switch'); mainItemSortSwitch.setAttribute('aria-checked', mainItemSortSwitchState); // 设置开关状态 mainItemSortSwitch.classList.add('ant-switch', 'css-9fw9up', 'ant-switch-small'); if (mainItemSortSwitchState) { mainItemSortSwitch.classList.add('ant-switch-checked'); } else { sonitemSort_contentContainer.style.opacity = '0.4';// 设置透明度使内容变浅 sonitemSort_contentContainer.style.pointerEvents = 'none';// 禁止点击操作 } // 主功能说明容器 var mainItemSort_mainIllustrate = document.createElement('div'); mainItemSort_mainIllustrate.style.cssText = 'font-size: 12px; color: #9B9B9B; margin: 5px 0px; padding-bottom: 5px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #D2D2D2;'; mainItemSort_mainIllustrate.textContent = '点击排序时自动自动清空或输入'; itemSort_contentContainer.appendChild(mainItemSortSwitch); itemSort_secondaryContent.appendChild(itemSort_contentContainer); itemSort_secondaryContent.appendChild(mainItemSort_mainIllustrate); // 子选项设置页面 上放!! itemSort_secondaryContent.appendChild(sonitemSort_contentContainer); // 自动输入功能开关页面 var itemSort_testFunSwitch = document.createElement('div'); itemSort_testFunSwitch.style.cssText = 'display: flex; justify-content: space-between; align-items: center;'; // 自动输入功能开关标题 var itemSort_testFunTitle = document.createElement('p'); itemSort_testFunTitle.textContent = '输入内容'; itemSort_testFunTitle.style.cssText = 'font-size: 14px; margin: 0;'; itemSort_testFunSwitch.appendChild(itemSort_testFunTitle); // 创建自动输入功能选择框元素 var select_itemSort_testFun = document.createElement('select'); select_itemSort_testFun.setAttribute('id', 'select_itemSort_testFun'); select_itemSort_testFun.style.cssText = ` font-size: 14px; margin: 0; width: auto; border: 1px solid rgb(155, 155, 155); background-color: rgb(249,249,249); color: rgb(155, 155, 155); border-radius: 20px; padding: 0 2.5%; -webkit-appearance: none; -moz-appearance: none; appearance: none; position: relative; `; // 悬浮时和激活时边框颜色变化 select_itemSort_testFun.addEventListener('mouseover', function () { select_itemSort_testFun.style.borderColor = '#ff6200'; }); select_itemSort_testFun.addEventListener('mouseout', function () { if (!select_itemSort_testFun.matches(':focus')) { select_itemSort_testFun.style.borderColor = 'rgb(155, 155, 155)'; } }); select_itemSort_testFun.addEventListener('focus', function () { select_itemSort_testFun.style.borderColor = '#ff6200'; }); select_itemSort_testFun.addEventListener('blur', function () { select_itemSort_testFun.style.borderColor = 'rgb(155, 155, 155)'; }); // 获取localStorage中保存的值,如果没有则使用默认值 var select_itemSort_savedValue = localStorage.getItem('select_itemSort_savedValue') || ''; // 创建选择框选项 var options = ['', '0', '1', '2', '3', '999']; options.forEach(function (value) { var option = document.createElement('option'); option.value = value; option.style.cssText = ` text-align: center; padding: 0 5px; `; option.textContent = value === '' ? '空' : value; select_itemSort_testFun.appendChild(option); }); // 设置选择框默认选项 select_itemSort_testFun.value = sonSwitch_itemSort_testFun_State ? sonSwitch_itemSort_testFun_State : ''; // 存在上次的值 if (select_itemSort_savedValue) { select_itemSort_testFun.value = select_itemSort_savedValue; } // 添加事件监听器处理选中值变化,并将值保存到localStorage select_itemSort_testFun.addEventListener('change', function () { var select_itemSort_savedValue = select_itemSort_testFun.value; localStorage.setItem('select_itemSort_savedValue', select_itemSort_savedValue); // 悬浮时和激活时边框颜色变化 select_itemSort_testFun.style.borderColor = '#ff6200'; }); // 监听选择框变化事件 select_itemSort_testFun.addEventListener('change', function () { var newState = select_itemSort_testFun.value; updateSwitchState('sonSwitch_itemSort_testFun_State', newState); }); // 自动输入功能加入itemSort_testFunSwitch页面 itemSort_testFunSwitch.appendChild(select_itemSort_testFun); // 自动输入功能功能说明容器 var itemSort_testFunIllustrate = document.createElement('div'); itemSort_testFunIllustrate.style.cssText = 'font-size: 12px; color: #9B9B9B; margin: 5px 0px; padding-bottom: 5px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #D2D2D2;'; itemSort_testFunIllustrate.textContent = '设置自动输入的默认内容'; sonitemSort_contentContainer.appendChild(itemSort_testFunSwitch); sonitemSort_contentContainer.appendChild(itemSort_testFunIllustrate); // 将二级页面内容插入到 itemSortButtonContainer 的下方 itemSortButtonContainer.parentNode.insertBefore(itemSort_secondaryContent, itemSortButtonContainer.nextSibling); // 监听itemSort测试功能选择框状态 select_itemSort_testFun.addEventListener('change', function () { var newState = select_itemSort_testFun.value; updateSwitchState('sonSwitch_itemSort_testFun_State', newState); }); // 计数输入功能开关页面 var itemSort_countInputFunSwitch = document.createElement('div'); itemSort_countInputFunSwitch.style.cssText = 'display: flex; justify-content: space-between; align-items: center;'; // 计数输入功能开关标题 var itemSort_countInputFunTitle = document.createElement('p'); itemSort_countInputFunTitle.textContent = '计数输入'; itemSort_countInputFunTitle.style.cssText = 'font-size: 14px; margin: 0;'; itemSort_countInputFunSwitch.appendChild(itemSort_countInputFunTitle); // 数字文本及SVG控制区 var countControlDiv = document.createElement('div'); countControlDiv.style.cssText = ` font-size: 14px; display: none; align-items: center; margin: 0; width: auto; border: 1px solid rgb(155, 155, 155); background-color: rgb(249,249,249); color: rgb(155, 155, 155); border-radius: 20px; padding: 0 2.5%; -webkit-appearance: none; -moz-appearance: none; appearance: none; position: relative; `; // 数字文本 var countText = document.createElement('span'); countText.textContent = '999'; // 初始数字为0 countText.style.cssText = 'font-size: 14px; margin-right: 5px; margin-left: 5px;'; countControlDiv.appendChild(countText); // 创建函数来设置悬停颜色 function addHoverEffect(svgElement) { svgElement.addEventListener('mouseover', function () { var path = svgElement.querySelector('path'); if (path) { path.setAttribute('data-original-fill', path.getAttribute('fill')); path.setAttribute('fill', '#ff6200'); } }); svgElement.addEventListener('mouseout', function () { var path = svgElement.querySelector('path'); if (path) { path.setAttribute('fill', path.getAttribute('data-original-fill')); } }); } // SVG控制区 var svgControlDiv = document.createElement('div'); svgControlDiv.style.cssText = 'display: flex; flex-direction: column; justify-content: space-between; cursor: pointer;'; // 上方SVG var svgUp = document.createElementNS("http://www.w3.org/2000/svg", "svg"); svgUp.setAttribute("width", "6"); svgUp.setAttribute("height", "6"); svgUp.setAttribute("viewBox", "0 0 1024 1024"); svgUp.innerHTML = ` `; addHoverEffect(svgUp); svgControlDiv.appendChild(svgUp); // 下方SVG var svgDown = document.createElementNS("http://www.w3.org/2000/svg", "svg"); svgDown.setAttribute("width", "6"); svgDown.setAttribute("height", "6"); svgDown.setAttribute("viewBox", "0 0 1024 1024"); svgDown.innerHTML = ` `; addHoverEffect(svgDown); svgControlDiv.appendChild(svgDown); countControlDiv.appendChild(svgControlDiv); // 将数字文本及SVG控制区加入页面 itemSort_countInputFunSwitch.insertBefore(countControlDiv, itemSort_countInputButton); // 计数输入功能开启按钮 var itemSort_countInputButton = document.createElement('button'); itemSort_countInputButton.setAttribute('id', 'itemSort_countInputButton'); itemSort_countInputButton.textContent = '开始'; itemSort_countInputButton.style.cssText = ` font-size: 14px; margin: 0; width: auto; border: 1px solid rgb(155, 155, 155); background-color: rgb(249,249,249); color: rgb(155, 155, 155); border-radius: 20px; padding: 0 2%; -webkit-appearance: none; -moz-appearance: none; appearance: none; position: relative; cursor: pointer; user-select: none; `; // 悬浮时和激活时边框颜色变化 itemSort_countInputButton.addEventListener('mouseover', function () { if (itemSort_countInputButton.textContent === '开始') { itemSort_countInputButton.style.borderColor = '#ff6200'; } else { itemSort_countInputButton.style.borderColor = 'rgb(155, 155, 155)'; } }); itemSort_countInputButton.addEventListener('mouseout', function () { if (itemSort_countInputButton.textContent === '开始') { itemSort_countInputButton.style.borderColor = 'rgb(155, 155, 155)'; } else { itemSort_countInputButton.style.borderColor = 'rgb(249, 249, 249)'; } }); // 按钮点击事件 itemSort_countInputButton.addEventListener('click', function () { if (itemSort_countInputButton.textContent === '开始') { itemSort_countInputButton.textContent = '结束'; itemSort_countInputButton.style.color = '#fff'; itemSort_countInputButton.style.backgroundColor = '#ff0000'; itemSort_countInputButton.style.borderColor = '#fff'; countControlDiv.style.display = 'flex'; countNum_Sort = 0; countText.textContent = countNum_Sort + 1; temp_itemId = ''; showNotification("计数排序:开启"); countSort_reShowNotification(); initializeContainerStyle(itemSort_testFunSwitch, false); initializeContainerStyle(itemSort_testFunIllustrate, false); } else { itemSort_countInputButton.textContent = '开始'; itemSort_countInputButton.style.color = 'rgb(155, 155, 155)'; itemSort_countInputButton.style.backgroundColor = 'rgb(249,249,249)'; itemSort_countInputButton.style.borderColor = 'rgb(155, 155, 155)'; countControlDiv.style.display = 'none'; showNotification("计数排序:关闭"); initializeContainerStyle(itemSort_testFunSwitch, true); initializeContainerStyle(itemSort_testFunIllustrate, true); } }); svgUp.addEventListener('click', function () { countNum_Sort++; countText.textContent = countNum_Sort + 1; showNotification("下一个输入序号:" + countText.textContent, 0); }); svgDown.addEventListener('click', function () { if (countNum_Sort > 0) countNum_Sort--; else { showNotification("当前已是最小序号"); countSort_reShowNotification(); } countText.textContent = countNum_Sort + 1; showNotification("下一个输入序号:" + countText.textContent, 0); }); // 将计数输入功能开启按钮加入页面 itemSort_countInputFunSwitch.appendChild(itemSort_countInputButton); // 计数输入功能功能说明容器 var itemSort_countInputFunIllustrate = document.createElement('div'); itemSort_countInputFunIllustrate.style.cssText = 'font-size: 12px; color: #9B9B9B; margin: 5px 0px; padding-bottom: 5px; display: flex; justify-content: space-between; align-items: center; border-bottom: 0px solid #D2D2D2;'; itemSort_countInputFunIllustrate.textContent = '将“输入内容”更新为当前计数,以方便排序'; sonitemSort_contentContainer.appendChild(itemSort_countInputFunSwitch); sonitemSort_contentContainer.appendChild(itemSort_countInputFunIllustrate); // 监听ItemSort主功能开关状态 mainItemSortSwitch.addEventListener('click', function () { var newState = mainItemSortSwitch.getAttribute('aria-checked') === 'true' ? false : true; mainItemSortSwitch.setAttribute('aria-checked', newState); if (newState) { mainItemSortSwitch.classList.add('ant-switch-checked'); showNotification("自动填充:开启"); } else { mainItemSortSwitch.classList.remove('ant-switch-checked'); itemSort_countInputButton.textContent = '开始'; itemSort_countInputButton.style.color = 'rgb(155, 155, 155)'; itemSort_countInputButton.style.backgroundColor = 'rgb(249,249,249)'; itemSort_countInputButton.style.borderColor = 'rgb(155, 155, 155)'; countControlDiv.style.display = 'none'; initializeContainerStyle(itemSort_testFunSwitch, true); initializeContainerStyle(itemSort_testFunIllustrate, true); showNotification("自动填充:关闭"); } updateSwitchState('mainItemSortSwitchState', newState); // 获取sonitemSort_contentContainer容器内的所有输入元素 var inputs = sonitemSort_contentContainer.querySelectorAll('input, select, textarea, button'); inputs.forEach(function (input) { input.disabled = !newState; }); //sonitemSort_contentContainer容器变灰色 initializeContainerStyle(sonitemSort_contentContainer, newState); }); itemSortButton.addEventListener('click', function () { // 切换二级页面显示状态 itemSort_secondaryContent = document.getElementById('itemSort_secondary-content'); if (itemSort_secondaryContent) { itemSort_secondaryContent.style.display = itemSort_secondaryContent.style.display === 'block' ? 'none' : 'block'; } else { console.log("itemSort二级页面异常") } // 旋转按钮图标 var icon = itemSortButton.querySelector('svg'); var rotation = icon.style.transform === 'rotate(90deg)' ? 'rotate(0deg)' : 'rotate(90deg)'; icon.style.transform = rotation; }); // 单击和双击事件的延迟和计数器 var delay = 200; // 延迟时间,单位毫秒 var clicks = 0; var timer = null; // 监听鼠标左键点击事件 document.addEventListener('click', function (event) { // 检查是否开启了点击复制功能且在匹配的网址上 if (copySwitch.getAttribute('aria-checked') === 'true' && isHomeURL()) { clicks++; if (clicks % 2 === 1) { timer = setTimeout(function () { // 单击操作 clicks = 0; handleSingleClick(event); }, delay); } else { // 取消之前的单击操作 clearTimeout(timer); clicks = 0; handleDoubleClick(event); } } }); // 单击处理函数 function handleSingleClick(event) { if (event.target && event.target.classList.contains('link-overflow-tip')) { var text = event.target.textContent; var copiedText = text.substring(); GM_setClipboard(copiedText); showNotification("复制成功:" + copiedText); countSort_reShowNotification(); } } // 双击处理函数 function handleDoubleClick(event) { if (event.target && event.target.classList.contains('link-overflow-tip')) { var text = event.target.textContent; var copiedText = text.substring(0, 3); GM_setClipboard(copiedText); showNotification("复制成功:" + copiedText); countSort_reShowNotification(); } } // 添加鼠标悬浮和移出事件监听器 NotificationContainer.addEventListener('mouseenter', function () { clearTimeout(notificationTimer); // 悬浮时清除计时器 // console.log('Mouse entered notification'); // 调试日志 }); NotificationContainer.addEventListener('mouseleave', function () { // console.log('Mouse left notification'); // 调试日志 var time = 3000; if (itemSort_countInputButton.textContent != '开始') time = 0; resetTimer(time); // 移出时重置计时器 }); function showNotification(message, duringTime = 3000, showImage = false) { // 清除之前的计时器 if (notificationTimer) { clearTimeout(notificationTimer); } // 重置隐藏标志 isHiding = false; // 重置通知样式 NotificationContainer.innerHTML = ''; NotificationContainer.style.width = 'auto'; NotificationContainer.style.transform = 'translateX(-50%)'; NotificationContainer.style.animation = 'none'; NotificationContainer.style.padding = '10px'; // 短暂移除并重新添加通知元素,强制触发动画 document.body.removeChild(NotificationContainer); setTimeout(() => { document.body.appendChild(NotificationContainer); // 设置通知文本内容 NotificationContainer.textContent = message; // 如果指定了显示图片,则读取剪贴板中的图片并显示 if (showImage) { NotificationContainer.style.padding = '5px'; navigator.clipboard.read().then(async function (data) { for (const item of data) { for (const type of item.types) { if (type.startsWith('image/')) { const blob = await item.getType(type); const imageURL = URL.createObjectURL(blob); const imageElement = document.createElement('img'); imageElement.src = imageURL; imageElement.style.width = '300px'; imageElement.style.borderRadius = '8px'; const imageContainer = document.createElement('div'); imageContainer.style.paddingTop = '10px'; imageElement.style.maxWidth = 'auto'; imageContainer.style.borderRadius = '8px'; imageContainer.style.margin = 'auto'; imageContainer.style.display = 'block'; imageContainer.appendChild(imageElement); NotificationContainer.appendChild(imageContainer); // 图片加载完成后调整位置并设置消失定时器 imageElement.onload = function () { NotificationContainer.style.left = '50%'; NotificationContainer.style.display = 'block'; NotificationContainer.style.animation = 'showNotification 0.5s forwards'; // 设置消失动画计时器 resetTimer(duringTime); }; break; } } } }).catch(function (error) { console.error('Error reading clipboard:', error); }); } else { // 显示通知 NotificationContainer.style.display = 'block'; NotificationContainer.style.animation = 'showNotification 0.5s forwards'; // 设置消失动画计时器 resetTimer(duringTime); } }, 50); // 确保通知元素短暂移除再添加 } function hideNotification() { if (isHiding) return; isHiding = true; NotificationContainer.style.animation = 'hideNotification 0.5s forwards'; // 在动画结束后隐藏元素 notificationTimer = setTimeout(function () { NotificationContainer.style.display = 'none'; isHiding = false; }, 500); } function resetTimer(duringTime = 3000) { if (notificationTimer) { clearTimeout(notificationTimer); console.log("清除计时器"); } if (duringTime > 0) { notificationTimer = setTimeout(function () { hideNotification(); console.log("设置计时器"); }, duringTime); // 3秒后自动隐藏通知 } } async function clickButton(pastedData = true, delayTime, containerSelector = document, buttonSelector) { // 判断粘贴内容是否为空或为 true if (pastedData === true || (typeof pastedData === 'string' && pastedData.trim().length > 0)) { // 查找指定容器内的按钮 var container = containerSelector === document ? document : document.querySelector(containerSelector); if (container) { var button = container.querySelector(buttonSelector); if (button) { setTimeout(function () { button.click(); }, delayTime); } } } } // 监听粘贴事件 document.addEventListener('paste', function (event) { // 判断是否开启了自动点击功能且在匹配的网址上 if (toggleSwitch.getAttribute('aria-checked') === 'true' && isHomeURL()) { // 获取粘贴板中的内容 var pastedData = (event.clipboardData || window.clipboardData).getData('text'); var className = '.ant-btn.css-9fw9up.ant-btn-primary'; clickButton(pastedData, 100, undefined, className); } }); // 检查文本中是否是天猫链接函数 function checkForTmallInClipboard(text) { const regex = /https:\/\/[^ ]*tmall[^ ]*id=\d{12}/; return regex.test(text); } function checkForChaoshiInClipboard(text) { const regex = /https:\/\/[^ ]*chaoshi[^ ]*id=\d{12}/; return regex.test(text); } function checkForFeizhuInClipboard(text) { const regex = /https:\/\/[^ ]*fliggy[^ ]*id=\d{12}/; return regex.test(text); } // 提取链接id函数 function extractIdFromClipboard(text) { const idMatch = text.match(/id=(\d{12})/); return idMatch ? idMatch[1] : null; } // 粘贴功能 async function simulatePaste(targetElement, clearBeforePaste = true) { try { // 从剪贴板读取文本 let clipboardText = await navigator.clipboard.readText(); // 检查目标元素是否为可编辑元素 if (targetElement.isContentEditable || targetElement.tagName === 'INPUT' || targetElement.tagName === 'TEXTAREA') { // 如果clearBeforePaste为true,清空目标元素的内容 if (clearBeforePaste) { if (targetElement.isContentEditable) { targetElement.innerHTML = ''; } else { targetElement.value = ''; } } // 插入剪贴板内容到目标元素 if (document.execCommand('insertText', false, clipboardText)) { // console.log('粘贴成功:' + clipboardText); } else { targetElement.value += clipboardText; } } else { alert('目标元素不可编辑'); } } catch (err) { console.error('读取剪贴板内容失败:', err); showNotification("读取剪贴板内容失败"); } } function updateClipboardContent() { var tmail = "https://detail.tmall.com/item.htm?id="; var chaoshi = "https://chaoshi.detail.tmall.com/item.htm?id="; var taobao = "https://item.taobao.com/item.htm?id="; var feizhu = "https://traveldetail.fliggy.com/item.htm?id="; navigator.clipboard.readText().then((clipText) => { const isTmall = checkForTmallInClipboard(clipText); const isChaoshi = checkForChaoshiInClipboard(clipText); const isFeizhu = checkForFeizhuInClipboard(clipText); const itemId = extractIdFromClipboard(clipText); if (itemId) { var newUrl; if (isTmall && !isChaoshi) { // 转换为天猫链接 newUrl = tmail + itemId; } else if (isChaoshi) { // 转换为猫超链接 newUrl = chaoshi + itemId; } else if (isFeizhu) { // 转换为飞猪链接 newUrl = tmail + itemId; } else { // 转换为淘宝链接 newUrl = taobao + itemId; } GM_setClipboard(newUrl); showNotification("剪贴板内容已更新为:" + newUrl); //console.log('剪贴板内容已更新为:' + newUrl); } else { if (sonSwitch_onlyItemId_checkId.getAttribute('aria-checked') === 'true') { // 防止错误粘贴功能 GM_setClipboard("12位数字ID不全"); } showNotification("剪贴板中没有找到12位数字ID"); //console.log('剪贴板中没有找到12位数字ID'); } }).catch((err) => { console.error('读取剪贴板失败:', err); }); } // 监听鼠标左键点击事件 document.addEventListener('click', function (event) { // 提取商品链接粘贴功能区域 if (mainOnlyItemIdSwitch.getAttribute('aria-checked') === 'true' && isHomeURL()) { if (event.target.closest('.ant-form-item.liveLinkFormItem___RPAQZ.css-9fw9up.ant-form-item-has-success')) { if (event.target.classList.contains('ant-input-affix-wrapper') || event.target.classList.contains('ant-input-affix-wrapper-status-error') || event.target.classList.contains('css-9fw9up')) { // console.log('目标元素被点击'); updateClipboardContent(); simulatePaste(document.activeElement); // 点击保存按钮 if (sonSwitch_onlyItemId_autoClick.getAttribute('aria-checked') === 'true') { var fbutton = '.ant-drawer-footer'; var buttonName = '.ant-btn.css-9fw9up.ant-btn-primary'; showNotification("粘贴成功&保存成功"); clickButton(undefined, 300, fbutton, buttonName); } } } } // 自动序号标1功能 if (mainItemSortSwitch.getAttribute('aria-checked') === 'true') { if (event.target.closest('.ant-input-number.ant-input-number-sm.css-1ayq15k')) { if (event.target.classList.contains('ant-input-number-input')) { // console.log('目标元素被点击'); if (itemSort_countInputButton.textContent === '开始') { GM_setClipboard(select_itemSort_testFun.value); } else { GM_setClipboard(countNum_Sort); showNotification("下一个输入序号:" + countText.textContent, 0); } simulatePaste(document.activeElement); } } } // 自动激活排序输入框 if (mainItemSortSwitch.getAttribute('aria-checked') === 'true') { if (event.target.classList.contains('sortWeights___Kn8mn') || event.target.closest('.sortWeights___Kn8mn')) { // console.log('找到sortWeights___Kn8mn'); activateInputFieldAndSave(event); } } //标题优化功能 if (false) { if (window.location.href.includes('/live/plan?select=')) { titlePrint_extractData(); } else if (window.location.href.includes('/live/plan/batchPrint')) { titlePrint_useData(); } } }); /* 快捷截图功能区 */ if (tableCardPngSwitch.getAttribute('aria-checked') === 'true' && isTableCardURL()) { // Load html2canvas library function loadHtml2Canvas(callback) { var script = document.createElement('script'); script.src = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js'; script.onload = callback; document.head.appendChild(script); } function createCaptureScreenshotButton() { const targetClass = '[class*="ant-space"][class*="css-9fw9up"][class*="ant-space-horizontal"][class*="ant-space-align-center"]'; const observer = new MutationObserver((mutationsList, observer) => { for (let mutation of mutationsList) { if (mutation.type === 'childList') { const targetElement = document.querySelector(targetClass); if (targetElement) { if (document.querySelector('.captureScreenshot')) { observer.disconnect(); return; } var captureScreenshot = document.createElement('div'); captureScreenshot.classList.add('ant-space-item'); var captureScreenshotButton = document.createElement('button'); captureScreenshotButton.textContent = '快捷截图'; captureScreenshotButton.classList.add('ant-btn', 'css-9fw9up', 'ant-btn-default', 'captureScreenshot'); captureScreenshot.appendChild(captureScreenshotButton); targetElement.insertBefore(captureScreenshot, targetElement.firstChild); captureScreenshotButton.addEventListener('click', captureScreenshotFunction); observer.disconnect(); break; } } } }); observer.observe(document.body, { childList: true, subtree: true }); } function loadImageAsDataURL(url) { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method: 'GET', url: url, responseType: 'blob', onload: function (response) { const blob = response.response; const reader = new FileReader(); reader.onloadend = function () { resolve(reader.result); }; reader.onerror = function () { reject(new Error('Failed to load image')); }; reader.readAsDataURL(blob); }, onerror: function () { reject(new Error('Network error')); } }); }); } async function captureScreenshotFunction() { const tableElement = document.querySelector('table'); var displayScale = 2.5; showNotification("截图中···", 0); if (tableElement) { const rows = tableElement.querySelectorAll('tr'); if (rows.length >= 3) { rows[2].cells[0].textContent = ''; // 隐藏除第二行和第三行外的所有行 rows.forEach((row, index) => { if (index !== 1 && index !== 2) { row.style.display = 'none'; } }); const imgElement = rows[2].cells[2].querySelector('img'); if (imgElement) { try { const dataUrl = await loadImageAsDataURL(imgElement.src); imgElement.src = dataUrl; setTimeout(() => { // 使用 html2canvas 捕获截图 html2canvas(tableElement, { scale: displayScale }).then(canvas => { // 恢复所有行的显示状态 rows.forEach(row => { row.style.display = ''; }); canvas.toBlob(async function (blob) { try { await navigator.clipboard.write([new ClipboardItem({ "image/png": blob })]); console.log("%cTable Screenshot:", "color: #9147ff", "Screenshot copied to clipboard."); showNotification("截图已成功复制到剪贴板", undefined, true); } catch (error) { console.log("%cTable Screenshot: Screenshot failed to copy to clipboard!", "color: #ff8080"); showNotification("截图失败!"); } }); }); }, 200); // 延迟 200 毫秒等待图片加载完毕 } catch (error) { console.log('Image load error:', error); } } else { console.log('Image element not found'); } } else { console.log("Table does not have enough rows"); } } else { console.log("Table element not found"); } } loadHtml2Canvas(createCaptureScreenshotButton); } /* ************************** 自动激活排序窗口、点击保存 ************************** */ function activateInputFieldAndSave(event) { if (true) { const click_itemId = handleCellClick(event); if (temp_itemId != click_itemId) { countNum_Sort++; temp_itemId = click_itemId; } countText.textContent = countNum_Sort + 1; // console.log('计数:'+countNum_Sort); const popover = document.querySelector('.ant-popover:not(.ant-popover-hidden)'); const inputField = popover.querySelector('.ant-input-number-input'); if (inputField) { inputField.focus(); inputField.click(); } else { console.log('未找到输入字段'); } } } // 查找点击的id function handleCellClick(event) { // 查找最接近的包含行元素的类 let rowElement = event.target.closest('.ag-row'); if (rowElement) { // 获取row-index属性 let rowIndex = rowElement.getAttribute('row-index'); // console.log('找到的行索引:', rowIndex); // 使用row-index属性查找行内的span标签 let targetSpan = document.querySelector(`.ag-row[row-index="${rowIndex}"] span#MarkHighlight-upLiveId-upLiveId`); if (targetSpan) { return targetSpan.textContent; // 打印span的文本内容 // console.log('目标span的文本内容:', targetSpan.textContent); } else { // console.log(`在行索引为${rowIndex}的行中未找到id为"MarkHighlight-upLiveId-upLiveId"的span标签。`); } } else { // console.log('未找到点击单元格对应的行。'); } } let countSort_notificationTimeout = null; // 常显通知 function countSort_reShowNotification() { var show_time = 1500; if (countSort_notificationTimeout) { clearTimeout(countSort_notificationTimeout); } countSort_notificationTimeout = setTimeout(() => { if (mainItemSortSwitch.getAttribute('aria-checked') === 'true' && itemSort_countInputButton.textContent != '开始') { showNotification("下一个输入序号:" + countText.textContent, 0); } countSort_notificationTimeout = null; }, show_time); // 延迟后触发 } /* ================= 打印标题优化 ================= */ function titlePrint_extractData() { const dateElement = document.querySelector('.isSelect___qbUI1 .ant-space.css-9fw9up.ant-space-horizontal.ant-space-align-center.title___mA8xY .ant-space-item:nth-child(2) div'); const sessionElement = document.querySelector('.truncate.sessionName___HUMKC.font-ma-semibold'); if (dateElement && sessionElement) { const dateText = dateElement.textContent.trim(); const sessionText = sessionElement.textContent.trim(); GM_setValue('titlePrint_extractedDate', dateText); GM_setValue('titlePrint_extractedSession', sessionText); console.log('Date extracted and stored:', dateText); console.log('Session name extracted and stored:', sessionText); } } function titlePrint_useData() { const storedDate = GM_getValue('titlePrint_extractedDate', ''); const storedSession = GM_getValue('titlePrint_extractedSession', ''); if (storedDate && storedSession) { console.log('Using stored date:', storedDate); console.log('Using stored session name:', storedSession); // 拼接标题 document.title = `${storedDate} ${storedSession}手卡`; } } /* ================= 手卡标题优化 ================= */ // 网址id提取 function url_getSessionGoodsId() { const url = window.location.href; const match = url.match(/sessionGoodsId=(\d+)/); return match ? match[1] : null; } // 检查当前页面标题是否为“表格手卡查看 - 羚客Link” function isTableCardTitle() { return document.title === '表格手卡查看 - 羚客Link'; } // 检测并修改标题 function checkAndModifyTitle() { if (!true) return; const sessionGoodsId = url_getSessionGoodsId(); if (sessionGoodsId && isTableCardTitle() && isTableCardURL()) { document.title = '【手卡】商品ID:' + sessionGoodsId; console.log("标题更新"); } } // 监听标题变化 const checkAndModifyTitle_observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.type === 'childList' || mutation.type === 'subtree') { if (false) checkAndModifyTitle(); } }); }); // 开始观察整个文档的变化 checkAndModifyTitle_observer.observe(document, { childList: true, subtree: true }); // 初始检查 window.addEventListener('load', function () { if (false) checkAndModifyTitle(); }); /* 系统功能优化 */ // 创建一个MutationObserver实例 const sys_auxiliaryFunctions = new MutationObserver((mutationsList) => { let urlChanged = false; for (let mutation of mutationsList) { if (mutation.type === 'childList') { mutation.addedNodes.forEach((node) => { // 系统通知位置优化 if (node.nodeType === 1 && node.classList.contains('ant-message') && node.classList.contains('ant-message-top') && node.classList.contains('css-190m0jy')) { // 修改top值为64px node.style.top = '64px'; } // 关闭浏览器更新弹窗 if (node.nodeType === 1 && node.id === 'link-browser-update-global') { const closeButton = node.querySelector('.link-browser-update-global-close'); if (closeButton) { closeButton.click(); console.log('关闭了浏览器更新弹窗'); } else { console.log('未找到关闭按钮'); } } }); // 检查URL是否变化 if (isHomeURL() && window.location.href !== lastCurrentURL) { lastCurrentURL = window.location.href; urlChanged = true; } } } // 处理URL变化 if (urlChanged) { // 检查是否存在switchesContainer if (!document.getElementById('switchesContainer')) { if (isHomeURL()) { document.body.appendChild(switchesContainer); } } } }); // 观察目标节点的子节点添加和移除 sys_auxiliaryFunctions.observe(document.body, { childList: true, subtree: true }); })();