Colorful Glasses

改变网页背景颜色(Changing the background color of web)

  1. // ==UserScript==
  2. // @name Colorful Glasses
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description 改变网页背景颜色(Changing the background color of web)
  6. // @author Zz
  7. // @include *
  8. // @grant GM_registerMenuCommand
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // ==/UserScript==
  12.  
  13. var canvas = document.createElement('canvas');
  14. var r = GM_getValue('r', 0);
  15. var g = GM_getValue('g', 0);
  16. var b = GM_getValue('b', 0);
  17. var a = GM_getValue('a', 0.1);
  18.  
  19. GM_registerMenuCommand("改变背景颜色", function(){
  20. var color = prompt("请输入RGB颜色值和透明度,中间用逗号隔开,例如绿豆沙色 199,238,206,0.5","");
  21. var colors = color.split(',');
  22. if (colors.length == 4) {
  23. r = colors[0];
  24. GM_setValue('r',r);
  25. g = colors[1];
  26. GM_setValue('g',g);
  27. b = colors[2];
  28. GM_setValue('b',b);
  29. a = colors[3];
  30. GM_setValue('a',a);
  31. canvas.getContext('2d').fillStyle = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
  32. canvas.getContext('2d').clearRect(0, 0, document.body.offsetWidth, document.body.offsetHeight);
  33. canvas.getContext('2d').fillRect(0, 0, document.body.offsetWidth, document.body.offsetHeight);
  34. } else {
  35. alert("您输入的格式不对哦");
  36. }
  37. });
  38.  
  39. GM_registerMenuCommand("默认背景颜色", function(){
  40. GM_setValue('r',0);
  41. GM_setValue('g',0);
  42. GM_setValue('b',0);
  43. GM_setValue('a',0.1);
  44. canvas.getContext('2d').fillStyle = 'rgba(0,0,0,0.1)';
  45. canvas.getContext('2d').clearRect(0, 0, document.body.offsetWidth, document.body.offsetHeight);
  46. canvas.getContext('2d').fillRect(0, 0, document.body.offsetWidth, document.body.offsetHeight);
  47. });
  48.  
  49. canvas.style.position = 'fixed';
  50. canvas.style.pointerEvents = 'none';
  51. canvas.style.minWidth = '100%';
  52. canvas.style.minHeight = '100%';
  53. canvas.style.top = 0;
  54. canvas.style.left = 0;
  55. canvas.style.width = 'auto';
  56. canvas.style.height = 'auto';
  57. canvas.style.zIndex = 10000;
  58. var context = canvas.getContext('2d');
  59. context.fillStyle = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
  60. context.fillRect(0, 0, document.body.offsetWidth, document.body.offsetHeight);
  61. document.body.insertBefore(canvas, document.body.firstChild);