Greasy Fork is available in English.

Hide pics

Hide pics so that don't be seen by leaders.

// ==UserScript==
// @name         Hide pics
// @namespace    https://greasyfork.org/
// @version      0.3
// @description  Hide pics so that don't be seen by leaders.
// @author       JMRY
// @include      *://*
// @exclude      *://*.google.*
// @exclude      *://*.conoha.*
// @exclude      *://*.alipay.*
// @grant        none
// ==/UserScript==

/*
v0.3
- 小幅调整文字变淡效果的可读性。
- 修复脚本会覆盖window.load导致页面跳转失效的bug。
v0.2
- 优化代码结构,提升性能。
- 优化特殊框架下,隐藏图片按钮会被删除的问题。
*/

function applyNoPic(){
    var show=true;

	var imgStyle;
	var style=document.createElement('style');

	/*var imgShowListener=setInterval(function(){
		if(show==false){
			imgStyle=`img{
                opacity:0.05;
            }`;
		}else{
			imgStyle=`img{
            }`;
		}

		style.innerHTML=`#toggleImg{
		    position:fixed;left:0px;bottom:0px;z-index:999999;opacity:0;
	    }
	    #toggleImg:hover{
		    opacity:1;
	    }
	    #toggleImg:active{
		opacity:1;
	    }
	    ${imgStyle}`;
		//
		var imgList=document.getElementsByTagName('img');
		for(var i=0; i<imgList.length; i++){
			var img=imgList[i];
			if(show==false){
				img.classList.add('hideImg');
				//$('img').addClass('hideImg');
			}else{
				img.classList.remove('hideImg');
				//$('img').removeClass('hideImg');
			}
		}//
	},500);*/

	var head=document.getElementsByTagName('head')[0];
	var body=document.getElementsByTagName('body')[0];

	style.innerHTML=`.toggleImg{
		position:fixed;left:0px;bottom:0px;z-index:999999;opacity:0;
	}
	.toggleImg:hover{
		opacity:1;
	}
	.toggleImg:active{
		opacity:1;
	}
	.hideImg{
		opacity:0.05;
	}`;

	head.appendChild(style);

	function showImg(){
		if(show==false){
			document.getElementById('toggleImg').innerHTML='■PIC SHIFT+`';
			document.getElementById('toggleImg').style='';
			//$('#toggleImg').html('■PIC SHIFT+`');
			//$('#toggleImg').css('opacity','');
			show=true;
		}else{
			document.getElementById('toggleImg').innerHTML='□PIC SHIFT+`';
			document.getElementById('toggleImg').style='opacity:1;';
			//$('#toggleImg').html('□PIC SHIFT+`');
			//$('#toggleImg').css('opacity',1);
			show=false;
		}

		if(show==false){
			imgStyle=`
            img, video, .VideoCard{
                opacity:0.05 !important;
            }
            body{
                opacity:0.75 !important;
            }
            *{
                font-weight:lighter !important;
            }
            `;
		}else{
			imgStyle=`
            img, video, .VideoCard{
            }
            body{
            }
            *{
            }
            `;
		}

		style.innerHTML=`
        .toggleImg{
		    position:fixed;left:0px;bottom:0px;z-index:999999;opacity:0;
	    }
	    .toggleImg:hover{
		    opacity:1;
	    }
	    .toggleImg:active{
		    opacity:1;
	    }
	    ${imgStyle}
        `;
	}

	var toggleBu=document.createElement('button');
	toggleBu.id='toggleImg';
    toggleBu.classList.add('toggleImg');
	toggleBu.onclick=function(){
		showImg();
	};
    window.onkeypress=function(e){
        //console.log(e);
        if (e.shiftKey==true && e.code=='Backquote'){
            showImg();
        }
    }
	toggleBu.innerHTML='■PIC SHIFT+`';

	body.appendChild(toggleBu);

    setTimeout(()=>{
        console.log('Auto init status');
        for(var i=0; i<10; i++){
            showImg();
        }
    },1000);

    /*window.onload=()=>{
        setTimeout(()=>{
            console.log('Auto init status');
            for(var i=0; i<10; i++){
                showImg();
            }
        },1000);
    }*/

	//$('body').prepend('<button id="toggleImg" style="">■PIC</button>');
	//$('#toggleImg').bind('click',function(){
		//showImg();
	//});
}
/*
(function() {
    'use strict';
    window.onload=function(){
        applyNoPic();
        //检测页面中是否存在按钮,如果不存在,则重新插入
        var npIntervalCount=0;
        var npInterval=setInterval(()=>{
            if(!document.getElementById(`toggleImg`)){
                applyNoPic();
            }
            npIntervalCount++;
            if(npIntervalCount>=80){ //250*80=20000,即20秒后如果仍然插入不成功,就停止,以提升性能
                clearInterval(npInterval);
            }
        },250);
    }
})();*/
(function() {
    'use strict';
    applyNoPic();
    //检测页面中是否存在按钮,如果不存在,则重新插入
    var npIntervalCount=0;
    var npInterval=setInterval(()=>{
        if(!document.getElementById(`toggleImg`)){
            applyNoPic();
        }
        npIntervalCount++;
        if(npIntervalCount>=80){ //250*80=20000,即20秒后如果仍然插入不成功,就停止,以提升性能
            clearInterval(npInterval);
        }
    },250);
})();