Google Analytics opt-out

Defines the Google Analytics opt-out object on every page.

  1. // ==UserScript==
  2. // @name Google Analytics opt-out
  3. // @namespace zdnq5fclhrdh8lgo
  4. // @match *://*/*
  5. // @grant none
  6. // @version 1.2
  7. // @license MIT
  8. // @description Defines the Google Analytics opt-out object on every page.
  9. // @run-at document-start
  10. // @inject-into content
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. const defineOptout = (null, function (unwrapper = (x)=>x, exporter = (f)=>f) {
  17. const _gaUserPrefs = new window.Object();
  18. const ioo = exporter(function ioo() { return true; });
  19.  
  20.  
  21. // Define property directly if this is an Xray
  22. Reflect.defineProperty(unwrapper(_gaUserPrefs), "ioo", {
  23. enumerable: true,
  24. configurable: false,
  25. get: exporter(() => ioo),
  26. set: exporter(() => {})
  27. });
  28.  
  29. Reflect.defineProperty(unwrapper(window), "_gaUserPrefs", {
  30. enumerable: false,
  31. configurable: false,
  32. get: exporter(() => _gaUserPrefs),
  33. set: exporter(() => {})
  34. });
  35. });
  36.  
  37.  
  38. if ("wrappedJSObject" in window) {
  39. // Bypass Firefox sandbox
  40. defineOptout(XPCNativeWrapper.unwrap, (f) => exportFunction(f, window));
  41. } else {
  42. // Inject script tag (Chrome)
  43. const script = document.createElement("script");
  44. script.text = `"use strict";(${defineOptout})();`;
  45. (document.head ?? document.documentElement).prepend(script);
  46. script.remove();
  47. }
  48. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址