Next Spaceflight Countdown

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

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

  1. // ==UserScript==
  2. // @name Next Spaceflight Countdown
  3. // @version 1.1
  4. // @description Adds a countdown timer to upcoming space launches on NextSpaceflight.com
  5. // @match https://nextspaceflight.com/*
  6. // @grant none
  7. // @namespace https://greasyfork.org/users/1435046
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. function updateCountdowns() {
  14. document.querySelectorAll('.mdl-card').forEach(card => {
  15. const timeElement = card.querySelector('.mdl-card__supporting-text span[id^="localized"]');
  16. if (!timeElement) return;
  17.  
  18. const launchTime = new Date(timeElement.textContent.trim());
  19. if (isNaN(launchTime)) return;
  20.  
  21. const tagsContainer = card.querySelector('.csscolumns');
  22. if (tagsContainer) {
  23. let countdownTag = tagsContainer.querySelector('.countdown-tag');
  24. if (!countdownTag) {
  25. countdownTag = document.createElement('div');
  26. countdownTag.className = 'countdown-tag';
  27. countdownTag.style.marginTop = '5px';
  28. countdownTag.style.color = 'rgb(209, 205, 199)';
  29. tagsContainer.appendChild(countdownTag);
  30. }
  31.  
  32. const now = new Date();
  33. let diff = launchTime - now;
  34. const prefix = diff < 0 ? 'T+' : 'T-';
  35. diff = Math.abs(diff);
  36. const days = Math.floor(diff / (1000 * 60 * 60 * 24));
  37. const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  38. const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
  39. const seconds = Math.floor((diff % (1000 * 60)) / 1000);
  40. countdownTag.textContent = `${prefix}${days}d ${hours}h ${minutes}m ${seconds}s`;
  41. }
  42. });
  43.  
  44. setTimeout(updateCountdowns, 1000 - new Date().getMilliseconds());
  45. }
  46.  
  47. updateCountdowns();
  48. })();