Blur on inactivity

Blur screen upon inactivity. This is helpful to prevent display sensitive information when you are away from screen. Inactivity time is set to 90 seconds.

当前为 2023-05-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Blur on inactivity
  3. // @description Blur screen upon inactivity. This is helpful to prevent display sensitive information when you are away from screen. Inactivity time is set to 90 seconds.
  4. // @author Schimon Jehudah, Adv.
  5. // @namespace i2p.schimon.blur
  6. // @homepageURL https://greasyfork.org/en/scripts/466065-blur-on-inactivity
  7. // @supportURL https://greasyfork.org/en/scripts/466065-blur-on-inactivity/feedback
  8. // @copyright 2023, Schimon Jehudah (http://schimon.i2p)
  9. // @license MIT; https://opensource.org/licenses/MIT
  10. // @exclude devtools://*
  11. // @include *
  12. // @version 23.04.07
  13. // @run-at document-end
  14. // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7wn5al77iPPC90ZXh0Pjwvc3ZnPgo=
  15. // ==/UserScript==
  16.  
  17. // 'unset' is probably the most preferable
  18. const originalFilter = document.body.style.filter;
  19.  
  20. window.addEventListener('keydown',event => {
  21. document.body.style.filter = originalFilter;
  22. });
  23.  
  24. window.addEventListener('mousemove',event => {
  25. document.body.style.filter = originalFilter;
  26. });
  27.  
  28. // Source: /questions/24338450/how-to-detect-user-inactivity-with-javascript
  29. onInactive(90000, function () {
  30. //console.log('Inactivity detected');
  31. if (document.querySelector('video')) {
  32. if (document.querySelector('video').paused) {
  33. document.body.style.filter = 'blur(10px)';
  34. }
  35. }
  36. });
  37.  
  38. function onInactive(ms, cb) {
  39. var wait = setInterval(cb, ms);
  40. window.ontouchstart =
  41. window.ontouchmove =
  42. window.onmousemove =
  43. window.onmousedown =
  44. window.onmouseup =
  45. window.onwheel =
  46. window.onscroll =
  47. window.onkeydown =
  48. window.onkeyup =
  49. window.onfocus =
  50. function () {
  51. //console.log('clearinterval');
  52. clearInterval(wait);
  53. wait = setInterval(cb, ms);
  54. };
  55. }