Disable Mailto Links

Disable all mailto links on web pages

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Disable Mailto Links
// @namespace    http://tampermonkey.net/
// @version      1.1.0
// @description  Disable all mailto links on web pages
// @include      *
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to disable a single mailto link
    function disableMailtoLink(link) {
        link.addEventListener('click', function(event) {
            event.preventDefault();
        });
        link.style.pointerEvents = 'none'; // Optional: visually indicate the link is disabled
        link.style.color = 'gray'; // Optional: change link color to show it's disabled
    }

    // Function to disable all mailto links
    function disableMailtoLinks() {
        const links = document.querySelectorAll('a[href^="mailto:"]');
        links.forEach(disableMailtoLink);
    }

    // Run the function on page load
    window.addEventListener('load', disableMailtoLinks);

    // Set up a MutationObserver to watch for new mailto links
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === Node.ELEMENT_NODE) {
                    if (node.matches('a[href^="mailto:"]')) {
                        disableMailtoLink(node);
                    }
                    // Check within the node for any new mailto links
                    node.querySelectorAll && node.querySelectorAll('a[href^="mailto:"]').forEach(disableMailtoLink);
                }
            });
        });
    });

    // Start observing the document for changes
    observer.observe(document.body, { childList: true, subtree: true });
})();