Blur on inactivity Extended

https://greasyfork.org/en/scripts/466065-blur-on-inactivity with additional features

目前為 2023-10-14 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Blur on inactivity Extended
// @description https://greasyfork.org/en/scripts/466065-blur-on-inactivity with additional features
// @author      Sadulisten @ Greasyfork
// @author      Schimon Jehudah, Adv.
// @namespace   Sadulisten
// @copyright   2023, Schimon Jehudah (http://schimon.i2p)
// @license     MIT; https://opensource.org/licenses/MIT
// @exclude     devtools://*
// @match       *://*/*
// @version     24.2
// @run-at      document-end
// @grant       GM_addStyle
// @icon        data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7wn5al77iPPC90ZXh0Pjwvc3ZnPgo=
// ==/UserScript==

const originalFilter = document.body.style.filter;
const blurIntensity = 75;
const inactivityThresholdSeconds = 30;
const inactivityThresholMiliseconds = inactivityThresholdSeconds * 1000;

function clamp(num, min, max) {
  return num <= min
    ? min
    : num >= max
      ? max
      : num
}
function addUnblurButton() {
    const btn = document.createElement("button");
    btn.id = blurButtonId;
    btn.innerHTML = "<span>👀</span>";
    btn.onclick = function() {
        document.querySelector("body").classList.remove("preventClicks");
        document.body.style.filter = originalFilter;
        blurButton.style.display = "none";
        blurCss.remove();
        blurCss = null;
    }

    GM_addStyle(
       `#${blurButtonId}
        {
            z-index:9999;
            position:fixed;

            /*
            bottom:10px;
            right:10px;
            */
            top:50%;
            left:47%;

            display: none;
            box-shadow:inset 0px 1px 0px 0px #cf866c;
	        background:linear-gradient(to bottom, #d0451b 5%, #bc3315 100%);
	        background-color:#d0451b;
            color:#ffffff;
	        border-radius:3px;
	        border:1px solid #942911;
	        cursor:pointer;
	        font-family:Arial;
	        font-size:13px;
	        padding:6px 24px;
	        text-decoration:none;
	        text-shadow:0px 1px 0px #854629;
        }
        #${blurButtonId}:hover
        {
            background:linear-gradient(to bottom, #bc3315 5%, #d0451b 100%);
	        background-color:#bc3315;
        }
        #${blurButtonId}:hover:after
        {
            content: " Unblur Page";
        }
      `
    );
    document.body.appendChild(btn);
    return btn;
}

let wrapperNextId = -1;
function wrapAll(elementToWrap , optionalWrapperElementCssText = "") {
    if (!elementToWrap) return null;
    const wrapperId = `wrapperElement_${++wrapperNextId}`;
    let org_html = elementToWrap.innerHTML;
    let new_html = `<div id='${wrapperId}'>` + org_html + "</div>";
    elementToWrap.innerHTML = new_html;
    let wrapperElement = document.getElementById(wrapperId);
    if (optionalWrapperElementCssText) {
        wrapperElement.style.cssText = optionalWrapperElementCssText;
    }
    return wrapperElement;
}

//var clickThroughElement = null;
const blurButtonId = "unblurButton";
const blurButton = addUnblurButton();
var blurCss = null;

onInactive(inactivityThresholMiliseconds, function () {
    if (blurCss == null) {
        blurCss = GM_addStyle(
            `body > *:not(#${blurButtonId}) {
                filter: blur(${clamp(blurIntensity, 1, 100)}px) !important;
                pointer-events: none !important;
            }`
        );
    }

    blurButton.style.display = "block";
});

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 () {
    clearInterval(wait);
    wait = setInterval(cb, ms);
  };
}