RPP Counter

Its the RPP countdown

Versión del día 03/02/2022. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name         RPP Counter
// @namespace    http://tampermonkey.net/
// @license      MIT
// @version      0.2
// @description  Its the RPP countdown
// @author       Printf
// @match        https://www.wykop.pl/tag/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 = 15;
    const EVENT_HOUR_STOP = 17;

    var events = ["Jan  4, 2022",
                  "Feb  8, 2022",
                  "Mar  8, 2022",
                  "Apr  6, 2022",
                  "May  5, 2022",
                  "Jun  8, 2022",
                  "Jul  7, 2022",
                  "Aug 23, 2022",
                  "Sep  7, 2022",
                  "Oct  5, 2022",
                  "Nov  9, 2022",
                  "Dec  7, 2022",
				  "Jan  4, 2023"];

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


    setInterval(function(){

        var timeLeft = eventDate + EVENT_HOUR_STOP*(60*60*1000) - Date.now();
        var days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
        var hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)).toString().padStart(2, "0");
        var minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60)).toString().padStart(2, "0");
        var seconds = Math.floor((timeLeft % (1000 * 60)) / 1000).toString().padStart(2, "0");

        var retval = "";

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

        if (document.querySelector(`#counterText`) === null) {
            document.querySelector('.commercial-header').innerHTML = `<div id='counterContainer'>
                                                                           <span id='counterText'>
                                                                             Do posiedzenia RPP pozostało: ${retval}
                                                                           </span>
                                                                         </div>`;
        } else {
            document.querySelector("#counterText").innerHTML = `Do posiedzenia RPP pozostało: ${retval}`;
        }

    },1000);

})();
长期地址
遇到问题?请前往 GitHub 提 Issues。