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

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

  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 20231108.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. // @inject-into content
  15. // @run-at document-start
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. "use strict";
  20.  
  21. window.addEventListener(
  22. "click",
  23. (event) => {
  24. const anchor = event.target.closest("a");
  25. if (!anchor) return;
  26. anchor.removeAttribute("ping");
  27. anchor.setAttribute("rel", "noopener noreferrer");
  28. const href = anchor.getAttribute("href");
  29. if (!href || href == "#") return;
  30. if (["button"].includes(anchor.getAttribute("role"))) return;
  31. const url = new URL(href, location);
  32. if (href.slice(0, 5) == "/url?") {
  33. anchor.href = url.searchParams.get("url") || href;
  34. }
  35. event.stopImmediatePropagation();
  36. },
  37. true,
  38. );
  39.  
  40. if (location.pathname == "/search") {
  41. window.addEventListener(
  42. "contextmenu",
  43. (event) => {
  44. event.stopImmediatePropagation();
  45. },
  46. true,
  47. );
  48.  
  49. window.addEventListener(
  50. "mousedown",
  51. (event) => {
  52. event.stopImmediatePropagation();
  53. },
  54. true,
  55. );
  56.  
  57. window.addEventListener(
  58. "mouseup",
  59. (event) => {
  60. event.stopImmediatePropagation();
  61. },
  62. true,
  63. );
  64. }
  65.  
  66. const inline_script = () => {
  67. window.navigator.sendBeacon = () => console.log("BAN: Beacon");
  68. };
  69.  
  70. const div = document.createElement("div");
  71. div.style.display = "none";
  72. const shadowRoot = div.attachShadow({ mode: "closed" });
  73. const script = document.createElement("script");
  74. script.textContent = "(" + inline_script + ")();";
  75. shadowRoot.append(script);
  76.  
  77. if (document.body) {
  78. document.body.append(div);
  79. } else {
  80. new MutationObserver((mutationList, observer) => {
  81. document.body && (observer.disconnect(), document.body.append(div));
  82. }).observe(document, { subtree: true, childList: true });
  83. }
  84. })();