// ==UserScript== // @name Magnet Hash Autolinker // @namespace Violentmonkey Scripts // @match *://*/* // @grant none // @version 1.0 // @author chimez // @description Converts 40-char hex hashes into clickable magnet links // @run-at document-end // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/561693/Magnet%20Hash%20Autolinker.user.js // @updateURL https://update.greasyfork.icu/scripts/561693/Magnet%20Hash%20Autolinker.meta.js // ==/UserScript== (function() { 'use strict'; // 1. The Regex: Matches exactly 40 hexadecimal characters (case insensitive) // \b ensures we don't cut off longer strings or match inside css/js code const hashRegex = /\b[a-fA-F0-9]{40}\b/g; // 2. Tags to ignore (to avoid breaking scripts, styles, or existing links) const ignoredTags = new Set(['A', 'SCRIPT', 'STYLE', 'TEXTAREA', 'INPUT', 'SELECT', 'BUTTON', 'CODE', 'PRE']); /** * scans a specific DOM node (and its children) for hashes */ function processNode(rootNode) { // We only care about Elements (1) to traverse, but we actually modify Text Nodes (3) if (!rootNode || !rootNode.nodeType) return; // Create a TreeWalker to find all text nodes under the rootNode const walker = document.createTreeWalker( rootNode, NodeFilter.SHOW_TEXT, { acceptNode: function(node) { // Skip if parent is a forbidden tag (e.g. don't link inside a