RPP Counter

Its the RPP countdown

  1. // ==UserScript==
  2. // @name RPP Counter
  3. // @namespace http://tampermonkey.net/
  4. // @license MIT
  5. // @version 0.5
  6. // @description Its the RPP countdown
  7. // @author Printf
  8. // @match https://www.wykop.pl/tag/nieruchomosci/*
  9. // @match https://www.wykop.pl/tag/znaleziska/nieruchomosci/*
  10. // @match https://www.wykop.pl/tag/wpisy/nieruchomosci/*
  11. // @icon https://www.google.com/s2/favicons?domain=wykop.pl
  12. // @grant GM_addStyle
  13. // ==/UserScript==
  14.  
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. GM_addStyle(`#counterContainer { bottom:0; right:0; width:auto; height:auto; background-color:rgba(0, 0, 0, 0.8);}`);
  20. GM_addStyle(`#counterText {padding:6px; display:block; font-size:14px; font-weight:bolder;color:#eec630}`);
  21.  
  22. const EVENT_HOUR_START = 12;
  23. const EVENT_HOUR_STOP = 24;
  24.  
  25. const EVENTS_LIST = ["Jan 3, 2023",
  26. "Feb 7, 2023",
  27. "Mar 7, 2023",
  28. "Apr 4, 2023",
  29. "May 9, 2023",
  30. "Jun 5, 2023",
  31. "Jul 5, 2023",
  32. "Aug 21, 2023",
  33. "Sep 5, 2023",
  34. "Oct 3, 2023",
  35. "Nov 7, 2023",
  36. "Dec 5, 2023",
  37. "Jan 10, 2023"];
  38.  
  39.  
  40. /**
  41. * Return string with remaining time base on input value
  42. * @param {number} timeLeftMs - Time in miliseconds
  43. */
  44. function getCounterString(timeLeftMs) {
  45. var timeLeftSeconds = (timeLeftMs / 1000);
  46.  
  47. var days = Math.floor(timeLeftSeconds / (60 * 60 * 24));
  48. timeLeftSeconds -= (days * (60 * 60 * 24));
  49.  
  50. var hours = Math.floor(timeLeftSeconds / (60 * 60));
  51. timeLeftSeconds -= (hours * (60 * 60));
  52.  
  53. var minutes = Math.floor(timeLeftSeconds / (60));
  54. timeLeftSeconds -= (minutes * 60);
  55.  
  56. var seconds = Math.floor(timeLeftSeconds % 60);
  57.  
  58. //Add leading zeros
  59. hours = hours.toString().padStart(2, "0");
  60. minutes = minutes.toString().padStart(2, "0");
  61. seconds = seconds.toString().padStart(2, "0");
  62.  
  63. if(days > 1) {
  64. return `${days} dni ${hours}:${minutes}:${seconds}`
  65. } else if(days == 1) {
  66. return `${days} dzień ${hours}:${minutes}:${seconds}`
  67. } else {
  68. return `${hours}:${minutes}:${seconds}`
  69. }
  70. }
  71.  
  72. /**
  73. * Show HTML on page
  74. * @param {string} html_string - String with HTML code
  75. */
  76. function showHTML(html_string) {
  77. if (document.querySelector(`#counterText`) === null) {
  78. document.querySelector('.commercial-header').innerHTML = `<div id='counterContainer'>
  79. <span id='counterText'>
  80. ${html_string}
  81. </span>
  82. </div>`;
  83. } else {
  84. document.querySelector("#counterText").innerHTML = `${html_string}`;
  85. }
  86. }
  87.  
  88.  
  89. setInterval(function(){
  90.  
  91. var eventDate = new Date(Date.parse(EVENTS_LIST.find((event) => (Date.parse(event) + EVENT_HOUR_STOP*(60*60*1000) - Date.now()) > 0))).getTime();
  92. var timeLeft = eventDate + EVENT_HOUR_START*(60*60*1000) - Date.now();
  93.  
  94. if(timeLeft > 0) {
  95. showHTML(`Do posiedzenia RPP pozostało: ${getCounterString(timeLeft)}`);
  96. } else {
  97. showHTML(`Posiedzenie trwa, ale on już jest wielki!`);
  98. }
  99. },1000);
  100.  
  101. })();