Discord 隱藏圖片

使 Discord 聊天視窗的圖片較為透明

目前為 2020-05-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Discord: Hide Image
// @name:zh-TW   Discord 隱藏圖片
// @name:zh-CN   Discord 屏蔽图片
// @version      1.0.0
// @description  Make Discord images opacity lower.
// @description:zh-TW  使 Discord 聊天視窗的圖片較為透明
// @description:zh-CN  使 Discord 聊天视窗的图片较为透明
// @author       Hayao-Gai
// @namespace	 https://github.com/HayaoGai
// @icon         https://i.imgur.com/rE9N0R7.png
// @match        https://discord.com/channels/@me/*
// @grant        none
// ==/UserScript==

/* jshint esversion: 6 */

(function() {
    'use strict';

    let scrolling = false;

    css();
    locationChange();
    window.addEventListener("load", init);
    window.addEventListener("scroll", update, true);

    function init() {
        for (let i = 0; i < 5; i++) {
            setTimeout(getTarget, 500 * (i + 1));
        }
    }

    function getTarget() {
        document.querySelectorAll("img:not(.hide)").forEach(image => {
            image.classList.add("hide");
            image.addEventListener("mouseenter", showImage);
            image.addEventListener("mouseleave", hideImage);
        });
    }

    function showImage() {
        this.style.opacity = 1;
    }

    function hideImage() {
        this.style.opacity = 0.1;
    }

    function update() {
        if (scrolling) return;
        scrolling = true;
        init();
        setTimeout(() => { scrolling = false; }, 1000);
    }

    function css() {
        const style = document.createElement("style");
        style.type = "text/css";
        style.innerHTML =
            `.hide {
                 transition: opacity 0.3s;
                 opacity: 0.1;
             }`;
        document.head.appendChild(style);
    }

    function locationChange() {
        window.addEventListener('locationchange', init);
        // situation 1
        history.pushState = (f => function pushState(){
            var ret = f.apply(this, arguments);
            window.dispatchEvent(new Event('pushState'));
            window.dispatchEvent(new Event('locationchange'));
            return ret;
        })(history.pushState);
        // situation 2
        history.replaceState = (f => function replaceState(){
            var ret = f.apply(this, arguments);
            window.dispatchEvent(new Event('replaceState'));
            window.dispatchEvent(new Event('locationchange'));
            return ret;
        })(history.replaceState);
        // situation 3
        window.addEventListener('popstate', () => {
            window.dispatchEvent(new Event('locationchange'));
        });
    }

})();