Grayscale Toggle with Persistence

Toggles grayscale on the webpage with Alt+G and remembers the state

  1. // ==UserScript==
  2. // @name Grayscale Toggle with Persistence
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Toggles grayscale on the webpage with Alt+G and remembers the state
  6. // @author Drewby123
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const STORAGE_KEY = 'grayscaleToggleState';
  16.  
  17. // Retrieve and apply the saved grayscale state on page load
  18. let isGrayscale = localStorage.getItem(STORAGE_KEY) === 'true';
  19. document.body.style.filter = isGrayscale ? 'grayscale(100%)' : 'none';
  20.  
  21. // Listen for the Alt+G key combination to toggle grayscale
  22. document.addEventListener('keydown', (e) => {
  23. if (e.altKey && e.key.toLowerCase() === 'g') {
  24. isGrayscale = !isGrayscale;
  25. document.body.style.filter = isGrayscale ? 'grayscale(100%)' : 'none';
  26.  
  27. // Save the current state to localStorage
  28. localStorage.setItem(STORAGE_KEY, isGrayscale);
  29. }
  30. });
  31. })();

QingJ © 2025

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