Auto Switch Google Account

Auto redirects Google sites to a separate user that is logged in. Useful if you want to set a "default" account without signing out of all accounts.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Auto Switch Google Account
// @namespace   HowBoutNo
// @description Auto redirects Google sites to a separate user that is logged in. Useful if you want to set a "default" account without signing out of all accounts.
// @match       *://*.google.com/*
// @version     1.2
// @author      HowBoutNo
// @run-at document-start
// @license MIT
// ==/UserScript==

var url = window.location.href;
var uid = 0; // uid is the number corresponding to the account. In URLs it would be the number after /u/

if (url.match("/u/") != null) { // check if site is a Google product (Drive, Mail, etc.)
  if (url.match("/u/" + uid) == null) {
    url = url.replace(/\/u\/[0-9]/, "/u/" + uid)
    window.location.replace(url);
  }
} else if (url.match("authuser=" + uid) == null) { // if not product, site must be Google search which needs to be handled differently
  if (url.match(/\?/) == null) {
    url += "?authuser=" + uid
  } else if (url.match("&authuser=") == null) {
    url += "&authuser=" + uid
  } else {
    url = url.replace(/(authuser=)[0-9]/, "authuser="+uid)
  }
  window.location.replace(url);
}