Next Spaceflight Countdown

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

当前为 2025-02-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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();
})();