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.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript== 
// @name        Blur on inactivity
// @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.
// @author      Schimon Jehudah, Adv.
// @namespace   i2p.schimon.blur
// @homepageURL https://greasyfork.org/en/scripts/466065-blur-on-inactivity
// @supportURL  https://greasyfork.org/en/scripts/466065-blur-on-inactivity/feedback
// @copyright   2023, Schimon Jehudah (http://schimon.i2p)
// @license     MIT; https://opensource.org/licenses/MIT
// @exclude     devtools://*
// @match       *://*/*
// @version     23.06
// @run-at      document-end
// @icon        data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7wn5al77iPPC90ZXh0Pjwvc3ZnPgo=
// ==/UserScript==

// 'unset' is probably the most preferable
const originalFilter = document.body.style.filter;

window.addEventListener('keydown',event => {
  document.body.style.filter = originalFilter;
});

window.addEventListener('mousemove',event => {
  document.body.style.filter = originalFilter;
});

// Source: /questions/24338450/how-to-detect-user-inactivity-with-javascript
onInactive(90000, function () {
  //console.log('Inactivity detected');
  if (document.querySelector('video')) {
    if (document.querySelector('video').paused) {
      document.body.style.filter = 'blur(10px)';
    }
  }
});

function onInactive(ms, cb) {
  var wait = setInterval(cb, ms);
  window.ontouchstart = 
  window.ontouchmove = 
  window.onmousemove = 
  window.onmousedown = 
  window.onmouseup = 
  window.onwheel = 
  window.onscroll = 
  window.onkeydown = 
  window.onkeyup = 
  window.onfocus = 
  function () {
    //console.log('clearinterval');
    clearInterval(wait);
    wait = setInterval(cb, ms);
  };
}