Removes YesWare & ConvertKit email trackers from links in GMail

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

目前為 2021-06-10 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Removes YesWare & ConvertKit email trackers from links in GMail
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  This script removes the YesWare & ConvertKit email trackers from links received in GMail. This means the sender will not know that you have clicked on their links if they use these tracking systems.
// @match        https://mail.google.com/*
// @icon         https://www.google.com/s2/favicons?domain=gmail.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.
 *
 * ConvertKit tracking links look like this:
 * https://click.convertkit-mail.com/13vyokfqpr2wzxz7vqn1/ml70lp19elw6tdl3/aHR0cHM6Ly9leGFtcGxlLmNvbS9zb21lLXVybA==
 * This script replaces the above ^ with https://example.com/some-url, which is found encoded at the end.
 */

/* jshint esversion: 6 */

(function() {
    'use strict';

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

    const trackers = [ // these are the configurations used by the script, each contains:
      /*{
            name:  the name of the tracker (used for logging if debug is set to true)
            xpathSearch: how to find the links on the page
            hrefRegex: the exact format we're looking for
            rewrite: a function taking the match object and returning the new link without a tracker
        }*/
        {
            name: 'YesWare',
            xpathSearch: '.yesware.com',
            hrefRegex: /http(?:s)?:\/\/[a-z]+\.yesware\.com\/tt\/(?:[0-9a-f]+\/){3}(.+)$/,
            rewrite: match => 'https://' + match[1]
        },
        {
            name: 'ConvertKit',
            xpathSearch: '.convertkit-mail.com',
            hrefRegex: /http(?:s)?:\/\/[a-z]+.convertkit-mail.com\/[a-z0-9]+\/[a-z0-9]+\/([a-zA-Z0-9_\-=]+)$/,
            rewrite: match => atob(match[1])
        },
    ];

    function matches(anchor, regex) {
        return regex.exec(anchor.href.toString()) !== null;
    }

    // join all the domains together to create the XPath query, which looks like: a[contains(@href,'x.com') or contains(@href,'y.com')]
    const domainPredicate = trackers.map(t => "contains(@href,'" + t.xpathSearch + "')").join(' or ');

    setInterval(function() {
        const xpathResult = document.evaluate(`//a[${ domainPredicate }]`, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); // search for tracker links using XPath
        if (xpathResult) {
            for (var i = 0; i < xpathResult.snapshotLength; i++) { // go over all the matching links
                const anchor = xpathResult.snapshotItem(i);
                for (const tracker of trackers) {
                    if (matches(anchor, tracker.hrefRegex)) {
                        if (anchor.getAttribute('data-saferedirecturl')) { // remove GMail's own redirect
                            anchor.removeAttribute('data-saferedirecturl');
                        }
                        const match = tracker.hrefRegex.exec(anchor.href.toString()); // match the exact tracking link format, and extract the real target
                        anchor.href = tracker.rewrite(match); // rewrite the link target
                        anchor.onclick = function(){}; // disable any JavaScript interceptors that GMail may add
                        anchor.click = function(){};

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址