Hide pics

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Hide pics
// @namespace    https://greatest.deepsurf.us/
// @version      1.0.2
// @description  Hide pics so that don't be seen by leaders. Refactor version.
// @author       JMRY
// @include      *://*
// @exclude      *://*.google.*
// @exclude      *://*.conoha.*
// @exclude      *://*.alipay.*
// @grant        none
// @run-at       document-body
// ==/UserScript==
/*
1.0.2 20240513
- 优化脚本注入速度,提升刷新后的隐藏图片响应速度。

1.0.1 20240425
- 加入页面减淡的开关。

1.0 20240425
- 重构自Hide Pics 0.3.
- 加入background-image的处理。
- 加入网站级别的图片显示/隐藏网站记忆功能。
*/

let show=getShow();
if(show==undefined || show==null){
    show=true;
    setShow(show);
}

let lighter=getLighter();
if(lighter==undefined || lighter==null){
    lighter=true;
    setLighter(lighter);
}


const buttonStyle=`
.toggleImg{
	position:fixed;left:0px;bottom:0px;z-index:999999;opacity:0;
}
.toggleImg:hover{
	opacity:1;
}
.toggleImg:active{
	opacity:1;
}
`;

const hideStyle=`
img, video, .VideoCard{
    opacity:0.05 !important;
}
body{
    ${lighter==true?`opacity:0.75 !important;`:``}
}
*{
    background-image:none !important;
    ${lighter==true?`font-weight:lighter !important;`:``}
}
`;


function getShow(){
    return JSON.parse(localStorage.getItem(`hidePicBool`));
}
function setShow(bool){
    return localStorage.setItem(`hidePicBool`,JSON.stringify(bool));
}
function getLighter(){
    return JSON.parse(localStorage.getItem(`hidePicLighter`));
}
function setLighter(bool){
    return localStorage.setItem(`hidePicLighter`,JSON.stringify(bool));
}

function applyNoPic(){
    setShow(show);
    let noPicStyle=document.getElementById(`hideStyleEl`);
    let toggleBu=document.getElementById(`toggleImg`);
    if(noPicStyle){
        if(show==true){
            noPicStyle.innerHTML=``;
            toggleBu.innerHTML=`☑PIC ↑+\``;
            toggleBu.style='';
        }else{
            noPicStyle.innerHTML=hideStyle;
            toggleBu.innerHTML=`☒PIC ↑+\``;
            toggleBu.style='opacity:1;';
        }
    }
    return show;
}

function toggleShowImg(){
    show=!show;
    applyNoPic();
}

function insertNoPic(){
    let hideStyleEl=document.createElement('style');
    hideStyleEl.id=`hideStyleEl`;
    hideStyleEl.innerHTML=``;
    document.head.appendChild(hideStyleEl);

    let buttonStyleEl=document.createElement('style');
    buttonStyleEl.id=`buttonStyleEl`;
    buttonStyleEl.innerHTML=buttonStyle;
    document.head.appendChild(buttonStyleEl);

    let toggleBu=document.createElement('button');
	toggleBu.id='toggleImg';
    toggleBu.classList.add('toggleImg');
	toggleBu.onclick=function(){
		toggleShowImg();
	};
    window.onkeypress=function(e){
        if (e.shiftKey==true && e.code=='Backquote'){
            toggleShowImg();
        }
    }
	document.body.appendChild(toggleBu);
}


(function() {
    'use strict';
    insertNoPic();
    applyNoPic();
})();