RPP Counter

Its the RPP countdown

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         RPP Counter
// @namespace    http://tampermonkey.net/
// @license      MIT
// @version      0.5
// @description  Its the RPP countdown
// @author       Printf
// @match        https://www.wykop.pl/tag/nieruchomosci/*
// @match        https://www.wykop.pl/tag/znaleziska/nieruchomosci/*
// @match        https://www.wykop.pl/tag/wpisy/nieruchomosci/*
// @icon         https://www.google.com/s2/favicons?domain=wykop.pl
// @grant        GM_addStyle
// ==/UserScript==


(function() {
    'use strict';

    GM_addStyle(`#counterContainer { bottom:0; right:0; width:auto; height:auto; background-color:rgba(0, 0, 0, 0.8);}`);
    GM_addStyle(`#counterText {padding:6px; display:block; font-size:14px; font-weight:bolder;color:#eec630}`);

    const EVENT_HOUR_START = 12;
    const EVENT_HOUR_STOP = 24;

    const EVENTS_LIST = ["Jan  3, 2023",
                         "Feb  7, 2023",
                         "Mar  7, 2023",
                         "Apr  4, 2023",
                         "May  9, 2023",
                         "Jun  5, 2023",
                         "Jul  5, 2023",
                         "Aug 21, 2023",
                         "Sep  5, 2023",
                         "Oct  3, 2023",
                         "Nov  7, 2023",
                         "Dec  5, 2023",
                         "Jan 10, 2023"];


    /**
     * Return string with remaining time base on input value
     * @param {number} timeLeftMs - Time in miliseconds
     */
    function getCounterString(timeLeftMs) {
        var timeLeftSeconds = (timeLeftMs / 1000);

        var days = Math.floor(timeLeftSeconds / (60 * 60 * 24));
        timeLeftSeconds -= (days * (60 * 60 * 24));

        var hours = Math.floor(timeLeftSeconds / (60 * 60));
        timeLeftSeconds -= (hours * (60 * 60));

        var minutes = Math.floor(timeLeftSeconds / (60));
        timeLeftSeconds -= (minutes * 60);

        var seconds = Math.floor(timeLeftSeconds % 60);

        //Add leading zeros
        hours = hours.toString().padStart(2, "0");
        minutes = minutes.toString().padStart(2, "0");
        seconds = seconds.toString().padStart(2, "0");

        if(days > 1) {
            return `${days} dni ${hours}:${minutes}:${seconds}`
        } else if(days == 1) {
            return `${days} dzień ${hours}:${minutes}:${seconds}`
        } else {
            return `${hours}:${minutes}:${seconds}`
        }
    }

    /**
     * Show HTML on page
     * @param {string} html_string - String with HTML code
     */
    function showHTML(html_string) {
        if (document.querySelector(`#counterText`) === null) {
            document.querySelector('.commercial-header').innerHTML = `<div id='counterContainer'>
                                                                           <span id='counterText'>
                                                                             ${html_string}
                                                                           </span>
                                                                         </div>`;
        } else {
            document.querySelector("#counterText").innerHTML = `${html_string}`;
        }
    }


    setInterval(function(){

        var eventDate = new Date(Date.parse(EVENTS_LIST.find((event) => (Date.parse(event) + EVENT_HOUR_STOP*(60*60*1000) - Date.now()) > 0))).getTime();
        var timeLeft = eventDate + EVENT_HOUR_START*(60*60*1000) - Date.now();

        if(timeLeft > 0) {
            showHTML(`Do posiedzenia RPP pozostało: ${getCounterString(timeLeft)}`);
        } else {
            showHTML(`Posiedzenie trwa, ale on już jest wielki!`);
        }
    },1000);

})();