Custom discord

Enlarge discord emojis and loop videos

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Custom discord
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Enlarge discord emojis and loop videos
// @author       Doni
// @match        https://discord.com/*
// @icon         https://i.imgur.com/rE9N0R7.png
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    registerCss("emojiEnlarger", `
        div:not([class^="repliedTextPreview"]) > div[id^="message-content"] img.emoji:not(.jumboable) {
            width: 2.5em;
            height: 2.5em;
        }
        div[id^="message-content"] img.emoji.jumboable {
            width: 6em;
            height: 6em;
        }
    `);

     registerCss("smallMode", `
        @media screen and (max-width: 720px) {
            div[class^="base-"] > div[class^="content-"] {
                position: relative;
                width: 100vmax;
                left: -241px;
            }
            div[class^="container-"] > nav[class^="wrapper-"] {
                visibility: hidden;
                display: none;
            }
            div[class^="content-"] > div[class^="sidebar-"] {
                visibility: hidden;
            }
            main[class^="chatContent-"] div[class^="buttons-"] > div:nth-child(1),
            main[class^="chatContent-"] div[class^="buttons-"] > div:nth-child(2),
            main[class^="chatContent-"] div[class^="buttons-"] > div:nth-child(3) {
                visibility: hidden;
            }
        }
    `);

    observeVideos(node => {
        if(node.tagName == "VIDEO") {
            node.loop = true;
        }
    });

    function registerCss(id, rules) {

        if(!id) return;

        let style = document.getElementById(id);

        if(!style) {
            style = document.createElement('style');
            style.id = id;
        }

        style.type = 'text/css';
        style.innerHTML = rules;
        document.getElementsByTagName('head')[0].appendChild(style);
    }

    function observeVideos(_callback) {
        const bodyObserver = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                mutation.addedNodes.forEach(addedNode => {
                    _callback(addedNode);
                    addedNode.querySelectorAll && addedNode.querySelectorAll("video").forEach(_callback);
                });
            });
        });

        bodyObserver.observe(document.body, {
            attributes: true,
            childList: true,
            subtree: true,
            characterData: true
        });
    }
})();