ACT.谷歌.DM.直链无跟踪

直接的链接,更少的跟踪。

当前为 2022-04-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name               ACT.Google.DM.Trackless
// @name:zh-CN         ACT.谷歌.DM.直链无跟踪
// @description        Make links direct and track less.
// @description:zh-CN  直接的链接,更少的跟踪。
// @author             ACTCD
// @version            20220420.1
// @license            GPL-3.0-or-later
// @namespace          ACTCD/Userscripts
// @supportURL         https://github.com/ACTCD/Userscripts#contact
// @homepageURL        https://github.com/ACTCD/Userscripts
// @match              *://www.google.com/*
// @grant              none
// @run-at             document-start
// ==/UserScript==

(function () {
    'use strict';

    window.addEventListener('click', event => {
        const anchor = event.target.closest('a');
        if (!anchor) return;
        anchor.removeAttribute('ping');
        anchor.setAttribute('rel', 'noopener noreferrer');
        const href = anchor.getAttribute('href');
        if (!href || href == '#') return;
        if (['button'].includes(anchor.getAttribute('role'))) return;
        const url = new URL(href, location);
        if (href.slice(0, 5) == '/url?') {
            anchor.href = url.searchParams.get('url') || href;
        }
        event.stopImmediatePropagation();
    }, true);

    window.addEventListener('contextmenu', event => {
        event.stopImmediatePropagation();
    }, true);

    window.addEventListener('mousedown', event => {
        event.stopImmediatePropagation();
    }, true);

    window.addEventListener('mouseup', event => {
        event.stopImmediatePropagation();
    }, true);

    const inline_script = () => {
        window.navigator.sendBeacon = () => console.log('BAN: Beacon');
    };

    const script = document.createElement("script");
    script.textContent = '(' + inline_script + ')();';

    if (document.head) {
        document.head.append(script);
    } else {
        new MutationObserver((mutationList, observer) => {
            document.head && (observer.disconnect(), document.head.append(script));
        }).observe(document, { subtree: true, childList: true });
    }

})();