Greasy Fork is available in English.

CW Game Time

Показывает время и дату

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

Advertisement:

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.

(I already have a user style manager, let me install it!)

Advertisement:

// ==UserScript==
// @name         CW Game Time
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Показывает время и дату
// @author       Why? Ева
// @match        https://playtest.cw-game.ru/play
// @icon         https://www.google.com/s2/favicons?sz=64&domain=cw-game.ru
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    function findPlace() {
        const targetDiv = document.querySelector(".css-1byqyzy");
        const dataRect = document.createElement('div');
        const timeRect = document.createElement('div');
        timeRect.id = 'timetime';
        dataRect.id = 'datadata';
        timeRect.style.cssText = "width: 52px; height: 30px; border-radius: 30px; margin-left: 7.99px; display: inline-block; background: rgba(10, 10, 20, 0.63); font-family: 'Neucha', Arial, sans-serif; color: #ffffff; text-align: center; line-height: 30px; font-size: 17px;"
        dataRect.style.cssText = "width: 52px; height: 30px; border-radius: 30px; margin-left: 7.99px; display: inline-block; background: rgba(10, 10, 20, 0.63); font-family: 'Neucha', Arial, sans-serif; color: #ffffff; text-align: center; line-height: 30px; font-size: 17px;"
        targetDiv.parentNode.insertBefore(timeRect, targetDiv.nextSibling);
        timeRect.parentNode.insertBefore(dataRect, timeRect.nextSibling);
    };

    function setTime() {
        const timeRect = document.getElementById('timetime');
        if (!timeRect) return;
        const game = (typeof unsafeWindow !== 'undefined' ? unsafeWindow.CWGPlayground : window.CWGPlayground);
        const virtualDate = game?.getVirtualTime?.().virtualDate || game?.virtualTime?.virtualDate;
        if (!virtualDate || virtualDate.hour === undefined || virtualDate.minute === undefined) {
            timeRect.textContent = "--:--";
            return;
        }
        const hour = String(virtualDate.hour).padStart(2, '0');
        const minute = String(virtualDate.minute).padStart(2, '0');
        timeRect.textContent = `${hour}:${minute}`;
    }

    function setData() {
        const dataRect = document.getElementById('datadata');
        if (!dataRect) return;
        const game = (typeof unsafeWindow !== 'undefined' ? unsafeWindow.CWGPlayground : window.CWGPlayground);
        const virtualDate = game?.getVirtualTime?.().virtualDate || game?.virtualTime?.virtualDate;
        if (!virtualDate || virtualDate.moon === undefined || virtualDate.date === undefined) {
            dataRect.textContent = "--:--";
            return;
        }
        let color = '#ffffff';
        if ((1 <= virtualDate.moon && virtualDate.moon <= 2) || virtualDate.moon == 12){
            color = '#7ad5ff';
        } else if (3 <= virtualDate.moon && virtualDate.moon <= 5){
            color = '#c8ffa8';
        } else if (6 <= virtualDate.moon && virtualDate.moon <= 8){
            color = '#a9ff7a';
        } else if (9 <= virtualDate.moon && virtualDate.moon <= 11){
            color = '#ff997a';
        }
        const day = String(virtualDate.date + 1).padStart(2, '0');
        const month = String(virtualDate.moon + 1).padStart(2, '0');
        dataRect.textContent = `${day}.${month}`;
        dataRect.style.color = color;
    }

    const checkInterval = setInterval(() => {
        if (document.querySelector(".css-1byqyzy")){
            clearInterval(checkInterval);
            findPlace();
            setTime();
            setData();
            setInterval(setTime, 2000);
        }
    }, 1000);
})();