站长之家增强-页面域名收集器

自动收集站长之家页面中出现的域名,并复制规范化域名到剪贴板

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

QingJ © 2025

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