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.

目前为 2023-07-18 提交的版本。查看 最新版本

// ==UserScript==
// @name Change Background Color for Google
// @namespace https://gf.qytechs.cn/users/1129625
// @license MIT
// @version 1.4
// @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.
// @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.");
      }
    }
  });
})();

QingJ © 2025

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