Hide pics

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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();
})();