Removes YesWare email trackers from links in GMail

This script removes the YesWare email trackers from links received in GMail. This means the sender will not know that you have clicked on their links if they use this tracking system.

Από την 09/05/2021. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Removes YesWare email trackers from links in GMail
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  This script removes the YesWare email trackers from links received in GMail. This means the sender will not know that you have clicked on their links if they use this tracking system.
// @match        https://mail.google.com/*
// @icon         https://www.google.com/s2/favicons?domain=google.com
// @grant        none
// ==/UserScript==

/**
 * YesWare tracking links look like this:
 * http://t.yesware.com/tt/d9fbcc52aa217aeec95457ead96daaee0c23b5ca/df6ccb12940ec0d69ac63a5be14e018a/a22c14da6fbc87418a7a2303a74e0ca3/realdomain.tld/some/page
 *
 * This script replaces the above ^ with https://realdomain.tld/some/page, which is found at the end.
 */

(function() {
    'use strict';

    const debug = true; // change to true to log the links found and updated

    const hrefRegex = /http(?:s)?:\/\/[a-z]+\.yesware\.com\/tt\/(?:[0-9a-f]+\/){3}(.+)$/;
    function isYesWareLink(anchor) {
        return hrefRegex.exec(anchor.href.toString()) !== null;
    }

    setInterval(function() {
        // search for YesWare-tracked links using XPath
        var xpathResult = document.evaluate("//a[contains(@href,'.yesware.com')]", document, null, XPathResult.ANY_TYPE, null);
        if (xpathResult) {
            var anchor = null;
            while ((anchor = xpathResult.iterateNext()) !== null) { // go over all the matching links
                if (isYesWareLink(anchor)) {
                    if (anchor.getAttribute('data-saferedirecturl')) { // remove GMail's own redirect
                        anchor.removeAttribute('data-saferedirecturl');
                    }
                    var match = hrefRegex.exec(anchor.href.toString()); // match the exact tracking link format, and extract the real target
                    anchor.href = 'https://' + match[1]; // rewrite the link target
                    anchor.onclick = function(){}; // disable any JavaScript interceptors that GMail may add
                    anchor.click = function(){};

                    debug && console.log('Removed YesWare tracker, now pointing to', anchor.href); // if enabled, log to the console to list all changes made
                }
            }
        }
    }, 200); // repeat as more content is loaded
})();