// ==UserScript== // @name Extract All URLs From HTML // @namespace Violentmonkey Scripts // @version 1.0 // @description 點一下按鈕,從整個網頁 HTML 中抓出所有 http/https 網址並列表顯示 // @match *://*/* // @grant GM_setClipboard // @downloadURL none // ==/UserScript== (function () { 'use strict'; function extractUrlsFromHtml() { const html = document.documentElement.outerHTML; // 抓 http / https URL const regex = /https?:\/\/[^\s"'<>`]+/g; const matches = html.match(regex) || []; // 去重 const uniqueUrls = [...new Set(matches)]; return uniqueUrls; } function createPanel(urls) { const oldPanel = document.getElementById('vm-url-extract-panel'); if (oldPanel) oldPanel.remove(); const panel = document.createElement('div'); panel.id = 'vm-url-extract-panel'; panel.style.position = 'fixed'; panel.style.top = '20px'; panel.style.right = '20px'; panel.style.zIndex = '999999'; panel.style.width = '600px'; panel.style.maxHeight = '80vh'; panel.style.background = '#fff'; panel.style.color = '#000'; panel.style.border = '1px solid #999'; panel.style.boxShadow = '0 4px 12px rgba(0,0,0,0.3)'; panel.style.padding = '12px'; panel.style.overflow = 'hidden'; panel.style.fontSize = '14px'; const title = document.createElement('div'); title.style.fontWeight = 'bold'; title.style.marginBottom = '8px'; title.textContent = `找到 ${urls.length} 個網址`; panel.appendChild(title); const buttonRow = document.createElement('div'); buttonRow.style.marginBottom = '8px'; const copyBtn = document.createElement('button'); copyBtn.textContent = '複製全部'; copyBtn.style.marginRight = '8px'; copyBtn.onclick = () => { const text = urls.join('\n'); if (typeof GM_setClipboard === 'function') { GM_setClipboard(text); } else { navigator.clipboard.writeText(text).catch(() => {}); } }; buttonRow.appendChild(copyBtn); const closeBtn = document.createElement('button'); closeBtn.textContent = '關閉'; closeBtn.onclick = () => panel.remove(); buttonRow.appendChild(closeBtn); panel.appendChild(buttonRow); const textarea = document.createElement('textarea'); textarea.style.width = '100%'; textarea.style.height = '65vh'; textarea.style.boxSizing = 'border-box'; textarea.value = urls.join('\n'); panel.appendChild(textarea); document.body.appendChild(panel); } function createTriggerButton() { const btn = document.createElement('button'); btn.textContent = '抓網址'; btn.style.position = 'fixed'; btn.style.right = '20px'; btn.style.bottom = '20px'; btn.style.zIndex = '999999'; btn.style.padding = '10px 14px'; btn.style.background = '#1976d2'; btn.style.color = '#fff'; btn.style.border = 'none'; btn.style.borderRadius = '6px'; btn.style.cursor = 'pointer'; btn.style.boxShadow = '0 2px 8px rgba(0,0,0,0.3)'; btn.addEventListener('click', () => { const urls = extractUrlsFromHtml(); createPanel(urls); }); document.body.appendChild(btn); } window.addEventListener('load', () => { createTriggerButton(); }); })();