Pure Black Background with Visible Text and Links

Apply a pure black background to any website, ensure text visibility, and differentiate links

当前为 2024-09-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pure Black Background with Visible Text and Links
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description Apply a pure black background to any website, ensure text visibility, and differentiate links
  6. // @author Patrick Gomes
  7. // @match *://*/*
  8. // @grant none
  9. // @require https://code.jquery.com/jquery-3.6.0.min.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Apply pure black background and ensure text visibility
  16. const applyStyles = () => {
  17. $('*').each(function() {
  18. const color = $(this).css('color');
  19. if (color) {
  20. const rgb = color.match(/\d+/g);
  21. if (rgb) {
  22. const brightness = (parseInt(rgb[0]) * 299 + parseInt(rgb[1]) * 587 + parseInt(rgb[2]) * 114) / 1000;
  23. if (brightness < 128) {
  24. $(this).css('color', '#FFFFFF');
  25. }
  26. }
  27. }
  28. $(this).css('background-color', '#000000');
  29. });
  30.  
  31. // Style links and visited links
  32. $('a:link').css('color', '#1E90FF'); // DodgerBlue for unvisited links
  33. $('a:visited').css('color', '#551A8B'); // Purple for visited links
  34. };
  35.  
  36. // Initial style application
  37. applyStyles();
  38.  
  39. // Observe for dynamically loaded content
  40. const observer = new MutationObserver(applyStyles);
  41. observer.observe(document.body, { childList: true, subtree: true });
  42. })();