// ==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 // @downloadURL none // ==/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(); })();