URL 收集器 (搜索引擎专用)

自动收集页面链接并复制规范化域名到剪贴板(仅限搜索引擎)

  1. // ==UserScript==
  2. // @name URL 收集器 (搜索引擎专用)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 自动收集页面链接并复制规范化域名到剪贴板(仅限搜索引擎)
  6. // @author Aethersailor
  7. // @match *://www.baidu.com/*
  8. // @match *://www.bing.com/*
  9. // @match *://*.google.com/*
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_addStyle
  13. // @grant GM_setClipboard
  14. // @run-at document-end
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. // 保持原有样式不变
  21. GM_addStyle(`
  22. .tm-url-collector {
  23. position: fixed;
  24. top: 20px;
  25. right: 20px;
  26. z-index: 2147483647;
  27. background: #fff;
  28. padding: 12px;
  29. border-radius: 8px;
  30. box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  31. font-family: Arial, sans-serif;
  32. }
  33. .switch-container {
  34. display: flex;
  35. align-items: center;
  36. gap: 8px;
  37. }
  38. .switch-label {
  39. font-size: 14px;
  40. color: #333;
  41. }
  42. .switch {
  43. position: relative;
  44. display: inline-block;
  45. width: 48px;
  46. height: 24px;
  47. }
  48. .switch input {
  49. opacity: 0;
  50. width: 0;
  51. height: 0;
  52. }
  53. .slider {
  54. position: absolute;
  55. cursor: pointer;
  56. top: 0;
  57. left: 0;
  58. right: 0;
  59. bottom: 0;
  60. background-color: #ccc;
  61. transition: .4s;
  62. border-radius: 34px;
  63. }
  64. .slider:before {
  65. position: absolute;
  66. content: "";
  67. height: 20px;
  68. width: 20px;
  69. left: 2px;
  70. bottom: 2px;
  71. background-color: white;
  72. transition: .4s;
  73. border-radius: 50%;
  74. }
  75. input:checked + .slider {
  76. background-color: #2196F3;
  77. }
  78. input:checked + .slider:before {
  79. transform: translateX(24px);
  80. }
  81. `);
  82.  
  83. // 保持原有面板代码
  84. const panel = document.createElement('div');
  85. panel.className = 'tm-url-collector';
  86. panel.innerHTML = `
  87. <div class="switch-container">
  88. <label class="switch">
  89. <input type="checkbox" id="tm-toggle">
  90. <span class="slider"></span>
  91. </label>
  92. <span class="switch-label">链接收集器</span>
  93. </div>
  94. `;
  95. document.body.appendChild(panel);
  96.  
  97. // 保持原有状态管理
  98. const toggle = panel.querySelector('#tm-toggle');
  99. let isEnabled = GM_getValue('enabled', false);
  100. toggle.checked = isEnabled;
  101.  
  102. toggle.addEventListener('change', () => {
  103. isEnabled = !isEnabled;
  104. GM_setValue('enabled', isEnabled);
  105. if (isEnabled) processLinks();
  106. });
  107.  
  108. // 保持原有核心逻辑
  109. function processLinks() {
  110. if (!isEnabled) return;
  111.  
  112. const currentUrl = new URL(window.location.href);
  113. const linkSet = new Set();
  114.  
  115. document.querySelectorAll('a[href]').forEach(a => {
  116. try {
  117. const url = new URL(a.href, currentUrl);
  118. if (!['http:', 'https:'].includes(url.protocol)) return;
  119.  
  120. const cleanURL = `${url.protocol}//${url.hostname}/`;
  121. linkSet.add(cleanURL.toLowerCase());
  122. } catch(e) {}
  123. });
  124.  
  125. if (linkSet.size > 0) {
  126. const result = Array.from(linkSet)
  127. .sort()
  128. .join('\n');
  129.  
  130. GM_setClipboard(result, 'text');
  131. }
  132. }
  133.  
  134. // 保持原有事件监听
  135. if (isEnabled) {
  136. window.addEventListener('load', processLinks);
  137. processLinks();
  138. }
  139.  
  140. new MutationObserver(() => {
  141. if (isEnabled) processLinks();
  142. }).observe(document.body, {
  143. childList: true,
  144. subtree: true
  145. });
  146. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址