Next Spaceflight Countdown

Adds a countdown timer to upcoming space launches on NextSpaceflight.com

目前為 2025-02-26 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Next Spaceflight Countdown
// @version      1.1
// @description  Adds a countdown timer to upcoming space launches on NextSpaceflight.com
// @match        https://nextspaceflight.com/*
// @grant        none
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function() {
    'use strict';

    function updateCountdowns() {
        document.querySelectorAll('.mdl-card').forEach(card => {
            const timeElement = card.querySelector('.mdl-card__supporting-text span[id^="localized"]');
            if (!timeElement) return;

            const launchTime = new Date(timeElement.textContent.trim());
            if (isNaN(launchTime)) return;

            const tagsContainer = card.querySelector('.csscolumns');
            if (tagsContainer) {
                let countdownTag = tagsContainer.querySelector('.countdown-tag');
                if (!countdownTag) {
                    countdownTag = document.createElement('div');
                    countdownTag.className = 'countdown-tag';
                    countdownTag.style.marginTop = '5px';
                    countdownTag.style.color = 'rgb(209, 205, 199)';
                    tagsContainer.appendChild(countdownTag);
                }

                const now = new Date();
                let diff = launchTime - now;
                const prefix = diff < 0 ? 'T+' : 'T-';
                diff = Math.abs(diff);
                
                const days = Math.floor(diff / (1000 * 60 * 60 * 24));
                const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
                const seconds = Math.floor((diff % (1000 * 60)) / 1000);
                
                countdownTag.textContent = `${prefix}${days}d ${hours}h ${minutes}m ${seconds}s`;
            }
        });

        setTimeout(updateCountdowns, 1000 - new Date().getMilliseconds());
    }

    updateCountdowns();
})();