// ==UserScript== // @name HM元素自动删除器 // @namespace http://tampermonkey.net/ // @version 1.3 // @description 页面加载完成后自动删除所有ID以"HM"开头的元素 // @author ChatGPT // @include *gying* // @grant GM_addStyle // @grant GM_notification // @run-at document-idle // @icon https://img.icons8.com/ios/50/000000/delete-forever.png // ==/UserScript== (function() { 'use strict'; // 添加自定义样式 GM_addStyle(` .hm-element-deleter-notification { position: fixed; top: 20px; right: 20px; background-color: #4CAF50; color: white; padding: 15px 25px; border-radius: 5px; box-shadow: 0 4px 8px rgba(0,0,0,0.2); z-index: 9999; font-family: Arial, sans-serif; font-size: 14px; animation: fadeIn 0.3s, fadeOut 0.3s 2.7s forwards; } .hm-element-removing { animation: fadeOut 0.5s ease forwards; position: relative; overflow: hidden; } .hm-element-removing::after { content: "正在删除..."; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(244, 67, 54, 0.7); color: white; display: flex; align-items: center; justify-content: center; font-weight: bold; z-index: 100; } @keyframes fadeIn { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } } @keyframes fadeOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-20px); } } @keyframes elementFadeOut { from { opacity: 1; height: auto; } to { opacity: 0; height: 0; } } `); // 显示通知 function showNotification(message) { // 移除现有通知 const existingNotification = document.querySelector('.hm-element-deleter-notification'); if (existingNotification) existingNotification.remove(); // 创建新通知 const notification = document.createElement('div'); notification.className = 'hm-element-deleter-notification'; notification.textContent = message; document.body.appendChild(notification); // 自动消失 setTimeout(() => { if (notification.parentNode) { notification.parentNode.removeChild(notification); } }, 3000); } // 查找所有ID以"HM"开头的元素 function findHMElements() { // 使用CSS选择器查找所有ID以"HM"开头的元素 const hmElements = document.querySelectorAll('[id^="HM"]'); return Array.from(hmElements); } // 删除HM元素 function deleteHMElements() { const hmElements = findHMElements(); if (hmElements.length === 0) { // showNotification('未找到ID以"HM"开头的元素'); return; } // 添加删除动画 hmElements.forEach(element => { element.classList.add('hm-element-removing'); }); // 延迟执行删除 setTimeout(() => { let deletedCount = 0; hmElements.forEach(element => { if (element.parentNode) { element.parentNode.removeChild(element); deletedCount++; } }); showNotification(`已删除 ${deletedCount} 个ID以"HM"开头的元素`); // 发送系统通知 if (typeof GM_notification !== 'undefined') { GM_notification({ title: 'HM元素删除完成', text: `已删除 ${deletedCount} 个元素`, timeout: 3000 }); } }, 5); } // 初始化 - 页面加载完成后执行 window.addEventListener('load', function() { // 延迟执行以确保所有元素都已加载 setTimeout(deleteHMElements, 500); setTimeout(deleteHMElements, 1000); setTimeout(deleteHMElements, 2000); setTimeout(deleteHMElements, 3000); }); })();