diff --git a/tampermonkey/hn_url_highlighter_with_preview.js b/tampermonkey/hn_url_highlighter_with_preview.js new file mode 100644 index 0000000..f630ee7 --- /dev/null +++ b/tampermonkey/hn_url_highlighter_with_preview.js @@ -0,0 +1,108 @@ +// ==UserScript== +// @name Hacker News URL Highlighter with Preview +// @namespace https://news.ycombinator.com/ +// @version 1.3 +// @description Highlights URLs in comments on Hacker News, lists them in a panel, and provides export functionality. Hover previews only in comments. +// @author MorganGeek +// @match https://news.ycombinator.com/item?id=* +// @grant GM_xmlhttpRequest +// @grant GM_setClipboard +// @connect * +// @run-at document-end +// ==/UserScript== + +(function () { + 'use strict'; + + // Create a floating panel for displaying URLs + const panel = document.createElement('div'); + panel.id = 'url-panel'; + panel.style.position = 'fixed'; + panel.style.top = '10px'; + panel.style.right = '10px'; + panel.style.backgroundColor = '#fff'; + panel.style.border = '1px solid #ccc'; + panel.style.borderRadius = '5px'; + panel.style.padding = '10px'; + panel.style.boxShadow = '0px 0px 10px rgba(0,0,0,0.2)'; + panel.style.maxHeight = '80vh'; + panel.style.overflowY = 'auto'; + panel.style.zIndex = 1000; + panel.innerHTML = '
${description}
`; + tooltip.style.display = 'block'; + }, + onerror: () => { + tooltip.innerHTML = 'Preview unavailable'; + tooltip.style.display = 'block'; + } + }); + + const rect = link.getBoundingClientRect(); + tooltip.style.top = `${rect.bottom + window.scrollY + 5}px`; + tooltip.style.left = `${rect.left + window.scrollX}px`; + }); + + link.addEventListener('mouseout', () => { + tooltip.style.display = 'none'; + }); + }); + }); + + // Handle the Copy URLs button + document.getElementById('copy-urls').addEventListener('click', () => { + const urlArray = Array.from(urlSet); + GM_setClipboard(urlArray.join('\n'), 'text'); + alert('URLs copied to clipboard!'); + }); +})();