DTF comment spoiler

Сворачивает раздел комментариев

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

Advertisement:

// ==UserScript==
// @name         DTF comment spoiler
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Сворачивает раздел комментариев
// @author       Fenrir
// @match        https://dtf.ru/*
// @run-at         document-start
// @grant        none
// ==/UserScript==

window.addEventListener('DOMContentLoaded', function headlapse() {
    if (document.getElementsByClassName('comments') !== null) {
        this.removeEventListener('DOMContentLoaded', headlapse);
        const comments = document.getElementsByClassName('comments')[0]
        comments.hidden = true;
        const dummyNode = comments.parentNode.insertBefore(document.createElement('div'), comments),
              show = '\u25BA Показать комментарии',
              hide = '\u25BC Скрыть комментарии';
        dummyNode.outerHTML = '<table width="95%" cellspacing="1" cellpadding="3" bgcolor="#999999" align="center" border="0"><tbody><tr><td valign="middle" bgcolor="#ffffff" align="left"></td></tr></tbody></table>';
        const spoilerHead = comments.previousElementSibling,
              spTitle = spoilerHead.getElementsByTagName('td')[0];
        spoilerHead.style.cssText = '-moz-user-select: none !important;-webkit-user-select: none !important; -ms-user-select: none !important; user-select: none !important; cursor: pointer !important';
        spTitle.textContent = show;
        spoilerHead.onclick = e => {
            if (e.button != 0) return;
            e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation();
            comments.hidden = !comments.hidden;
            spTitle.textContent = comments.hidden ? show : hide;
        }
        console.log("test comments spoiler");
    };
});