V2EX Domain Switcher

尽可能避免增加账号的活跃度 (已弃用)

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         V2EX Domain Switcher
// @version      1.1
// @description  尽可能避免增加账号的活跃度 (已弃用)
// @match        *://*.v2ex.com/*
// @match        *://*.v2ex.co/*
// @author       Wanten
// @copyright    2024 Wanten
// @license      MIT
// @supportURL   https://github.com/WantenMN/v2ex-userscripts/issues
// @icon         https://v2ex.com/favicon.ico
// @homepageURL  https://github.com/WantenMN/v2ex-userscripts
// @namespace    https://greasyfork.org/en/scripts/509836
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function () {
  "use strict";

  // Create floating button
  const button = document.createElement("button");
  button.style.position = "fixed";
  button.style.bottom = "20px";
  button.style.right = "20px";
  button.style.padding = "7px";
  button.style.border = "black 2px solid";
  button.style.borderRadius = "25px";
  button.style.cursor = "pointer";

  // Function to get clean domain (without www)
  function getCleanDomain(domain) {
    return domain.replace(/^www\./, "");
  }

  // Set button color and border based on current clean domain
  const currentCleanDomain = getCleanDomain(window.location.hostname);
  if (currentCleanDomain === "v2ex.com") {
    button.style.backgroundColor = "green";
    button.style.border = "2px solid darkgreen"; // Border color for green
  } else if (currentCleanDomain === "global.v2ex.co") {
    button.style.backgroundColor = "yellow";
    button.style.border = "2px solid darkorange"; // Border color for yellow
  }

  // Add click event listener
  button.addEventListener("click", () => {
    const newDomain =
      currentCleanDomain === "v2ex.com" ? "global.v2ex.co" : "v2ex.com";
    const newUrl = new URL(window.location.href);
    newUrl.hostname = newDomain;
    window.location.href = newUrl.toString();
  });

  // Add button to page
  document.body.appendChild(button);
})();