WhiteBG

White background for pages that not set background color

  1. // ==UserScript==
  2. // @name WhiteBG
  3. // @namespace iFantz7E.WhiteBG
  4. // @version 1.12
  5. // @description White background for pages that not set background color
  6. // @include *
  7. // @run-at document-start
  8. // @grant none
  9. // @copyright 2016, 7-elephant
  10. // ==/UserScript==
  11.  
  12. function attachOnLoad(callback)
  13. {
  14. window.addEventListener("load", function (e)
  15. {
  16. callback();
  17. });
  18. }
  19.  
  20. function attachOnReady(callback)
  21. {
  22. document.addEventListener("DOMContentLoaded", function (e)
  23. {
  24. callback();
  25. });
  26. }
  27.  
  28. function main()
  29. {
  30. if (window.parent === window && document.documentElement && document.body)
  31. {
  32. var bgHead = window.getComputedStyle(document.documentElement).backgroundColor;
  33. if (bgHead === "transparent" || bgHead === "rgba(0, 0, 0, 0)")
  34. {
  35. var bgBody = window.getComputedStyle(document.body).backgroundColor;
  36. if (bgBody === "transparent" || bgBody === "rgba(0, 0, 0, 0)")
  37. {
  38. document.documentElement.style.setProperty("background-color", "white", "important");
  39. document.body.style.setProperty("background-color", "white", "important");
  40. }
  41. }
  42. }
  43. }
  44.  
  45. attachOnReady(main);