Custom discord

Enlarge discord emojis and loop videos

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         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
        });
    }
})();