Filter topics

Hide topics without new messages

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

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 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!)

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!)

// ==UserScript==
// @name         Filter topics
// @license      MIT
// @namespace    http://websight.blue
// @version      1.01
// @description  Hide topics without new messages
// @author       Milan
// @match        *://*.websight.blue/threads/*
// @match        *://websight.blue
// @icon         https://lore.delivery/static/blueshi.png
// ==/UserScript==

const hideTopics = button => {
    button.innerText = "Unfilter topics";
    document.querySelectorAll("#thread-list>tbody>tr").forEach( row => {
        if(!!row.id && !!row.querySelector(".thread-unread").style.display) { row.style.display = "none"; }
    });
}

const showTopics = button => {
    button.innerText = "Filter topics";
    document.querySelectorAll("#thread-list>tbody>tr").forEach( row => {
        row.style.display = "table-row";
    });
}

let filtered = JSON.parse(localStorage.getItem("filterlock")) || false;

const placeButton = menu => {
    const button = document.createElement("a");
    button.href = "#";
    button.id = "GM-filter-button";
    button.title = "Only show updated topics";
    button.innerText = "Filter topics";
    button.addEventListener('click', () => {
        if (filtered) {
            showTopics(button);
            filtered = false;
        }
        else {
            hideTopics(button);
            filtered = true;
        }
    });

    button.addEventListener('dblclick', () => {
        if(JSON.parse(localStorage.getItem("filterlock"))) {
            localStorage.setItem("filterlock", "false");
            showTopics(button);
            menu.lastChild.remove();
        }
        else {
            localStorage.setItem("filterlock", "true");
            hideTopics(button);
            menu.append(" 🔒");
        }
    });
    menu.append(" | ");
    menu.append(button);
    if (JSON.parse(localStorage.getItem("filterlock"))) { menu.append(" 🔒"); }
    document.addEventListener('keydown', function(e) {
        if (e.key == 'o') {
            button.click();
        }
    });
}

(() => {
    'use strict';
    const buttonLocation = document.querySelector(".userbar");
    placeButton(buttonLocation);
    if (JSON.parse(localStorage.getItem("filterlock"))) {
        hideTopics(document.getElementById("GM-filter-button"));
        filtered = true;
    }
})();