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.

目前为 2021-05-09 提交的版本。查看 最新版本

// ==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
})();

QingJ © 2025

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