Greasy Fork

Greasy Fork is available in English.

页面隐私保护

教练我在认真写代码!

当前为 2020-12-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         页面隐私保护
// @namespace    No Privacy Spys
// @version      2020.12.02.1
// @description  教练我在认真写代码!
// @author       PY-DNG
// @include      *
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_deleteValue
// @grant        GM_registerMenuCommand
// @run-at       document-start
// ==/UserScript==
(function() {
    let protectSites;
    let canvas;

    //GM_setValue('protectSites', ['www.lianaiyx.com']);

    // delete the item we want from the array we choose
    function delItem(array, item) {
        array.forEach(function(arritem, index, arr) {
            if(arritem === item) {
                arr.splice(index, 1);
            }
        })
    }

    let protect = function() {
        blur();
    }

    let recover = function() {
        cancelBlur();
    }

    let config = function() {
        // Initialize protectSites
        protectSites = GM_getValue('protectSites', '');
        if (protectSites === '') {
            protectSites = [];
            GM_setValue('protectSites', protectSites);
        }
    }

    function cancelBlur() {
        document.body.style.filter = 'none';
        document.body.style.pointerEvents = 'auto';
        canvas.style.display = 'none';
    }

    function blur() {
        console.log('blur');
        if (!canvas) {
            setTimeout(blur, 100);
            return;
        }
        document.body.style.filter = 'blur(40px)';
        document.body.style.pointerEvents = 'none';
        canvas.style.display = '';
    }

    let initGUI = function() {
        canvas = document.createElement('canvas');
        canvas.addEventListener('click', cancelBlur);
        canvas.style.position = 'fixed';
        canvas.style.left = 0;
        canvas.style.top = 0;
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        canvas.style.display = 'none';
        document.lastChild.appendChild(canvas);
    }

    let addThisSite = function() {
        const site = location.href.match(/^https?:\/\/(.*?)\//)[1];
        protectSites.push(site);
        GM_setValue('protectSites', protectSites);
        initGUI();
        protect();
        window.addEventListener('visibilitychange', protect);
        //GM_registerMenuCommand()
    }

    let delThisSite = function() {
        const site = location.href.match(/^https?:\/\/(.*?)\//)[1];
        delItem(protectSites, site);
        GM_setValue('protectSites', protectSites);
        recover();
        window.removeEventListener('visibilitychange', protect);
        //GM_registerMenuCommand()
    }

    let init = function() {
        config();
        const site = location.href.match(/^https?:\/\/(.*?)\//)[1];
        if (protectSites.indexOf(site) != -1) {
            window.addEventListener('load', initGUI);
            window.addEventListener('visibilitychange', protect);
            window.addEventListener('load', function() {if (Document.visibilityState === 'hidden') {protect();};})
        }
        GM_registerMenuCommand((protectSites.indexOf(site) === -1 ? '保护' : '不保护') + site, protectSites.indexOf(site) === -1 ? addThisSite : delThisSite);
    }

    init();
})();