Remove Transparency on Websites

Adds a background to websites that have transparency in your browser (e.g. Zen Browser).

目前为 2025-02-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Remove Transparency on Websites
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description Adds a background to websites that have transparency in your browser (e.g. Zen Browser).
  6. // @author Maniac
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. /*
  17. This generally should deal with most websites that have the transparency issue.
  18. */
  19. // Apply background color before the page starts rendering
  20. document.documentElement.style.backgroundColor = "#ffffff"; // White background
  21.  
  22. window.addEventListener('DOMContentLoaded', function() {
  23. const bodyStyle = window.getComputedStyle(document.body);
  24.  
  25. if (!bodyStyle.backgroundImage && bodyStyle.backgroundImage === 'none' && bodyStyle.backgroundColor === 'rgba(0, 0, 0, 0)' && !bodyStyle.background) {
  26. document.body.style.backgroundColor = "#ffffff"; // Ensure body background stays white
  27. }
  28. });
  29.  
  30. /*
  31. This was a fix for Brave Search that could help with other websites.
  32. This takes the background color of the body and makes a div with that background color in the very back.
  33. */
  34. const bgDiv = document.createElement("div");
  35. bgDiv.style.position = "fixed";
  36. bgDiv.style.top = "0";
  37. bgDiv.style.left = "0";
  38. bgDiv.style.width = "100vw";
  39. bgDiv.style.height = "100vh";
  40. bgDiv.style.zIndex = "-1"; // Send it to the back
  41. bgDiv.style.background = getComputedStyle(document.body).backgroundColor || "white";
  42.  
  43. // Insert at the very beginning of the body
  44. document.body.prepend(bgDiv);
  45. })();