Change Background Color for Google

Adds a button to change the background color of Google search page on load and removes the carbon neutral since 2007 and everything related to it. Will apply to all google links may be broken on other pages other than google.com or other language versions of google.com

当前为 2023-07-18 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Change Background Color for Google
// @namespace https://greasyfork.org/users/1129625
// @license MIT
// @version 1.3
// @description Adds a button to change the background color of Google search page on load and removes the carbon neutral since 2007 and everything related to it.      Will apply to all google links may be broken on other pages other than google.com or other language versions of google.com
// @match   https://www.google.com/*
// ==/UserScript==

(function() {
  'use strict';

  // Find the element to remove
  var elementToRemove = document.querySelector('div[data-sfsw="1200"]');

  // Check if the element exists
  if (elementToRemove) {
    // Remove the element from the DOM
    elementToRemove.parentNode.removeChild(elementToRemove);
  }

  // Create the button element
  var button = document.createElement('button');
  button.textContent = 'Change Color';
  button.style.position = 'relative';
  button.style.marginLeft = '10px';

  // Find the Store button
  var storeButton = document.querySelector('[aria-label="Google apps"]');

  // Insert the button next to the Store button
  storeButton.parentNode.insertBefore(button, storeButton.nextSibling);

  // Add click event listener to change the background color
  button.addEventListener('click', function() {
    var color = prompt(
      "Select a color:\n1. Blue\n2. Red\n3. Green\n4. Yellow\n5. Purple\n6. Orange\n7. Pink\n8. Teal\n9. Gray\n10. Brown\n11. Custom RGB"
    );

    if (color !== null) {
      switch (color) {
        case "1":
          document.body.style.backgroundColor = "blue";
          break;
        case "2":
          document.body.style.backgroundColor = "red";
          break;
        case "3":
          document.body.style.backgroundColor = "green";
          break;
        case "4":
          document.body.style.backgroundColor = "yellow";
          break;
        case "5":
          document.body.style.backgroundColor = "purple";
          break;
        case "6":
          document.body.style.backgroundColor = "orange";
          break;
        case "7":
          document.body.style.backgroundColor = "pink";
          break;
        case "8":
          document.body.style.backgroundColor = "teal";
          break;
        case "9":
          document.body.style.backgroundColor = "gray";
          break;
        case "10":
          document.body.style.backgroundColor = "brown";
          break;
        case "11":
          var rgbColor = prompt(
            "Enter a custom RGB value (e.g., 'rgb(255, 0, 0)'):"
          );
          if (rgbColor !== null) {
            document.body.style.backgroundColor = rgbColor;
          }
          break;
        default:
          alert("Invalid selection. Please choose a valid option.");
      }
    }
  });
})();