您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds a countdown timer to upcoming space launches on NextSpaceflight.com
当前为
- // ==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();
- })();