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 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 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
})();