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 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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