Greasy Fork

Greasy Fork is available in English.

Change Background Color for Google

Adds a button to change the background color of Google search page on click

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

// ==UserScript==
// @name Change Background Color for Google
// @version 1.0
// @description Adds a button to change the background color of Google search page on click
// @match *://www.google.com/*
// @license MIT
// @namespace http://greasyfork.icu/users/1129625
// ==/UserScript==

(function() {
  // 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");

    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)'):");
        document.body.style.backgroundColor = rgbColor;
        break;
      default:
        alert("Invalid selection. Please choose a valid option.");
    }
  });
})();