Hidder

Make "hide" button works

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Hidder
// @version      1.2
// @description  Make "hide" button works
// @author       Rst00
// @match        https://www.wykop.pl/wykopalisko/*
// @namespace WykopHidder
// ==/UserScript==

const localStorageKey = 'WykopHidder';

(function() {
    'use strict';

    hideAllArticles();

    hideOldButton();
    addNewButton();
    handleNewButtonClick();

    clearOldEnteries();
})();

function hideOldButton() {
    const allButtons = document.querySelectorAll('.fix-tagline a.ajax.affect.create');

    allButtons.forEach(button => button.style.display = 'none');
}

function addNewButton() {
    const allContainers = document.querySelectorAll('.fix-tagline');

    allContainers.forEach(container => {
        const newButton = document.createElement('button');

        newButton.type = 'button';
        newButton.classList = 'rst-hide-button';
        newButton.innerText = 'ukryj';

        container.appendChild(newButton);
    });
}

function handleNewButtonClick() {
    $(document).on('click', '.rst-hide-button', function() {
        const container = $(this).parents('li.link');
        const articleId = container.find('.article').attr('data-id');

        saveDataToLS({
            id: articleId,
            createdAt: getCurrentDate(),
        });
        $(this).closest('li.link').remove();
    });
}

function hideAllArticles() {
    const articlesToHide = getDataFromLS();
    const allIds = articlesToHide.reduce((allIds, currentArticle) => [...allIds, currentArticle.id], []);

    const allArticles = document.querySelectorAll('#itemsStream .article');

    allArticles.forEach((article) => {
        if (allIds.includes(article.getAttribute('data-id'))) {
            article.parentNode.remove();
        }
    });
    wykop.bindLazy();
}

function getDataFromLS() {
    const articles = localStorage.getItem(localStorageKey);

    return articles ? JSON.parse(articles) : [];
}

function saveDataToLS(articleData) {
    const newDataToSave = JSON.stringify([...getDataFromLS(), articleData]);

    localStorage.setItem(localStorageKey, newDataToSave);
}

function clearOldEnteries() {
    const allArticles = getDataFromLS();
    const nowDate = getCurrentDate();
    const filteredArticles = allArticles.filter(article => article.createdAt + 60*60*24*7 > nowDate);

    localStorage.setItem(localStorageKey, JSON.stringify(filteredArticles));
}

function getCurrentDate() {
    return Math.floor(new Date().getTime() / 1000);
}