×
创建新页面
在此填写您的页面标题:
我们当前在爆裂小队维基上拥有117个页面。请在上方输入您的页面名称或点击以下任意标题来开始编写页面!



爆裂小队维基

MediaWiki:Common.js:修订间差异

无编辑摘要
无编辑摘要
第70行: 第70行:




// Document ready event
document.addEventListener("DOMContentLoaded", function() {
    // Function to initialize the countdown
    function initializeCountdown(targetDate, countdownElementId) {
        function updateCountdown() {
            var now = new Date();
            var timeDifference = targetDate - now;
           
            if (timeDifference <= 0) {
                document.getElementById(countdownElementId).innerHTML = "The event has started or already ended.";
                return;
            }


(function() {
            var days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
  function updateCountdown(container) {
            var hours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var endTime = container.getAttribute('data-endtime');
            var minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60));
    var countdownElement = container.querySelector('.countdown');
            var seconds = Math.floor((timeDifference % (1000 * 60)) / 1000);
    var now = new Date().getTime();
    var endDate = new Date(endTime).getTime();
    var distance = endDate - now;


    if (distance < 0) {
            document.getElementById(countdownElementId).innerHTML =  
      countdownElement.innerHTML = "Countdown finished";
                days + " days " +
      return;
                hours + " hours " +
                minutes + " minutes " +
                seconds + " seconds left before the event.";
        }
 
        // Update countdown every second
        setInterval(updateCountdown, 1000);
        updateCountdown();
     }
     }


     var days = Math.floor(distance / (1000 * 60 * 60 * 24));
     // Find all countdown elements and initialize them
     var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
     var countdownElements = document.querySelectorAll('.countdown');
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
     countdownElements.forEach(function(element) {
     var seconds = Math.floor((distance % (1000 * 60)) / 1000);
        var targetDate = new Date(element.getAttribute('data-target-date'));
 
         initializeCountdown(targetDate, element.id);
    countdownElement.innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
  }
 
  function initCountdown() {
    var containers = document.querySelectorAll('.countdown-container');
    containers.forEach(function(container) {
      updateCountdown(container);
      setInterval(function() {
         updateCountdown(container);
      }, 1000);
     });
     });
  }
});
 
  document.addEventListener('DOMContentLoaded', initCountdown);
})();

2024年6月22日 (六) 16:27的版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */

$(document).ready(function () {

/* 生成音频播放-s按钮 */
(function (){
  var audios = document.getElementsByClassName('audio-player-s');
  var notValidAudio = /wpDestFile/;
  var currentPlaying = null;

  for(var i = 0; i < audios.length; i++) {
    var audio = audios[i];
    var linkEl = audio.firstElementChild;

    if (!linkEl) {
      continue;
    }

    var link = linkEl.href;

    if (notValidAudio.test(link)) {
      continue;
    }

    audio.innerHTML = '';
    audio.classList.add('has-audio-element');

    var a = document.createElement('audio');

    a.src = link;
    a.preload = 'none';

    a.onended = function () {
      currentPlaying = null;
      this.parentNode.classList.remove('audio-player-playing-s');
    };

    var button = document.createElement('button');

    button.classList.add('audio-player-button-s');
    button.append(a);
    button.onclick = function () {
      var a = this.firstElementChild;

      if (currentPlaying != null && currentPlaying != a) {
        currentPlaying.pause();
        currentPlaying.currentTime = 0;
        currentPlaying.parentNode.classList.remove('audio-player-playing-s');
      }

      if (a.paused) {
        a.play();
        currentPlaying = a;
        this.classList.add('audio-player-playing-s');
        this.classList.remove('audio-player-paused-s');
      } 
      else {
        a.pause();
        this.classList.add('audio-player-paused-s');
        this.classList.remove('audio-player-playing-s');
      };
    };
    
    audio.append(button);
  };
})();


});


// Document ready event
document.addEventListener("DOMContentLoaded", function() {
    // Function to initialize the countdown
    function initializeCountdown(targetDate, countdownElementId) {
        function updateCountdown() {
            var now = new Date();
            var timeDifference = targetDate - now;
            
            if (timeDifference <= 0) {
                document.getElementById(countdownElementId).innerHTML = "The event has started or already ended.";
                return;
            }

            var days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
            var hours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
            var minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60));
            var seconds = Math.floor((timeDifference % (1000 * 60)) / 1000);

            document.getElementById(countdownElementId).innerHTML = 
                days + " days " + 
                hours + " hours " + 
                minutes + " minutes " + 
                seconds + " seconds left before the event.";
        }

        // Update countdown every second
        setInterval(updateCountdown, 1000);
        updateCountdown();
    }

    // Find all countdown elements and initialize them
    var countdownElements = document.querySelectorAll('.countdown');
    countdownElements.forEach(function(element) {
        var targetDate = new Date(element.getAttribute('data-target-date'));
        initializeCountdown(targetDate, element.id);
    });
});