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

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

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

  1. // ==UserScript==
  2. // @name ACT.Google.DM.Trackless
  3. // @name:zh-CN ACT.谷歌.DM.直链无跟踪
  4. // @description Make links direct and track less.
  5. // @description:zh-CN 直接的链接,更少的跟踪。
  6. // @author ACTCD
  7. // @version 20220419.1
  8. // @license GPL-3.0-or-later
  9. // @namespace ACTCD/Userscripts
  10. // @supportURL https://github.com/ACTCD/Userscripts#contact
  11. // @homepageURL https://github.com/ACTCD/Userscripts
  12. // @match *://www.google.com/*
  13. // @grant none
  14. // @run-at document-start
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. 'use strict';
  19.  
  20. window.addEventListener('click', event => {
  21. const anchor = event.target.closest('a');
  22. if (!anchor) return;
  23. anchor.removeAttribute('ping');
  24. const href = anchor.getAttribute('href');
  25. if (!href || href == '#') return;
  26. if (['button'].includes(anchor.getAttribute('role'))) return;
  27. const url = new URL(href, location);
  28. if (href.slice(0, 5) == '/url?') {
  29. const r_url = url.searchParams.get('url');
  30. r_url && (url.href = anchor.href = r_url);
  31. }
  32. if (anchor.hasAttribute('target')) {
  33. window.open(url, anchor.getAttribute('target'), 'noopener,noreferrer');
  34. } else {
  35. location.assign(url);
  36. }
  37. event.preventDefault();
  38. event.stopImmediatePropagation();
  39. }, true);
  40.  
  41. window.addEventListener('contextmenu', event => {
  42. event.stopImmediatePropagation();
  43. }, true);
  44.  
  45. window.addEventListener('mousedown', event => {
  46. event.stopImmediatePropagation();
  47. }, true);
  48.  
  49. window.addEventListener('mouseup', event => {
  50. event.stopImmediatePropagation();
  51. }, true);
  52.  
  53. const inline_script = () => {
  54. window.navigator.sendBeacon = () => console.log('BAN: Beacon');
  55. };
  56.  
  57. const script = document.createElement("script");
  58. script.textContent = '(' + inline_script + ')();';
  59.  
  60. if (document.head) {
  61. document.head.append(script);
  62. } else {
  63. new MutationObserver((mutationList, observer) => {
  64. document.head && (observer.disconnect(), document.head.append(script));
  65. }).observe(document, { subtree: true, childList: true });
  66. }
  67.  
  68. })();