Google Maps Authuser Modifier

Ensure authuser=n is always present in Google Maps URLs

目前为 2024-02-09 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Google Maps Authuser Modifier
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Ensure authuser=n is always present in Google Maps URLs
  6. // @author JKamsker
  7. // @match *://www.google.at/maps*
  8. // @grant none
  9. // @run-at document-start
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. function getAuthUserId() {
  17. // Check if the authuserId is stored in localStorage
  18. let authuserId = localStorage.getItem("authuserId");
  19. // If not present or user wants to change it (by adding ?changeAuthUser=true in the URL)
  20. let urlParams = new URLSearchParams(window.location.search);
  21. if (!authuserId || urlParams.get("changeAuthUser") === "true") {
  22. // Prompt the user to enter their authuserId
  23. authuserId = prompt(
  24. "Please enter your authuserId for Google Maps:",
  25. authuserId || ""
  26. );
  27. if (authuserId) {
  28. // If provided, save it
  29. localStorage.setItem("authuserId", authuserId);
  30. } else {
  31. // If not provided, use a default or exit
  32. alert("authuserId not set. Using default or existing value.");
  33. return null;
  34. }
  35. }
  36. return authuserId;
  37. }
  38.  
  39. function ensureAuthUser() {
  40. let url = new URL(window.location.href);
  41. // if (url.searchParams.get('authuser') !== authuserId) {
  42. // url.searchParams.set('authuser', authuserId);
  43. // window.location.href = url.toString();
  44. // }
  45. let authUserIdIsSet = url.search.indexOf("authuser=") !== -1;
  46.  
  47. // Only set if not already set
  48. if (!authUserIdIsSet) {
  49. let authuserId = getAuthUserId();
  50.  
  51. if (!authuserId) {
  52. return;
  53. }
  54.  
  55. url.search += (url.search ? "&" : "?") + "authuser=" + authuserId;
  56. window.location.href = url.toString();
  57. }
  58.  
  59. // If the URL has a different authuser than the one stored in localStorage, update the localStorage value
  60. if (authUserIdIsSet) {
  61. let authuserId = url.searchParams.get("authuser");
  62. let storedAuthuserId = localStorage.getItem("authuserId");
  63. if (authuserId !== storedAuthuserId) {
  64. localStorage.setItem("authuserId", authuserId);
  65. }
  66. }
  67. }
  68.  
  69. // Run the function on script load
  70. ensureAuthUser();
  71.  
  72. window.addEventListener("popstate", function (event) {
  73. ensureAuthUser();
  74. });
  75.  
  76. const originalPushState = history.pushState;
  77. const originalReplaceState = history.replaceState;
  78.  
  79. history.pushState = function () {
  80. originalPushState.apply(this, arguments);
  81. ensureAuthUser();
  82. };
  83.  
  84. history.replaceState = function () {
  85. originalReplaceState.apply(this, arguments);
  86. ensureAuthUser();
  87. };
  88. })();

QingJ © 2025

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