MediaWiki:Common.js:修订间差异

来自赛尔号精灵图鉴
跳转到导航 跳转到搜索
无编辑摘要
Len留言 | 贡献
无编辑摘要
 
(未显示同一用户的46个中间版本)
第1行: 第1行:
$(function () {
$(function () {
   // 在线人数显示
   // 在线人数统计区域
   var $counter = $('<div id="online-counter">当前在线 <span style="color:#a782ff;">👥</span><span id="online-number">加载中...</span></div>');
   var $counter = $('<div id="online-counter">当前在线 <span style="color:#a782ff;">👥</span>: <span id="online-number">加载中...</span></div>');
   $('body').append($counter);
   $('body').append($counter);


  // 获取在线人数
   function updateOnlineNumber() {
   function updateOnlineNumber() {
     $.getJSON('/api/online.php', function (data) {
     $.getJSON('/api/online.php', function (data) {
第13行: 第14行:


   updateOnlineNumber();
   updateOnlineNumber();
   setInterval(updateOnlineNumber, 30000);
   setInterval(updateOnlineNumber, 30000); // 每 30 秒刷新一次
 
$(document).ready(function () {
  const $button = $('<a>', {
    href: '/index.php/首页',
    id: 'back-to-home-button',
    text: '🏠 返回主页'
  });
  $('body').append($button);
});
});


mw.loader.using('mediawiki.util', function () {
  if (document.getElementById('bgm')) return; // 防止重复添加


   const audio = document.createElement('audio');
   // ✅ 把这一行放进 function 内部!
  audio.src = 'https://d1rtq9slcl72gh.cloudfront.net/audio/home.mp3';
   mw.loader.load('/js/player.js?v=10');
  audio.loop = true;
}); // 👈 别忘了这个结束的大括号和括号
  audio.id = 'bgm';
 
  const lastTime = localStorage.getItem('bgm-time');
  if (lastTime) {
    audio.addEventListener('loadedmetadata', function () {
      audio.currentTime = parseFloat(lastTime);
    });
  }
 
  const player = document.createElement('div');
   player.innerHTML = "
    <button onclick="document.getElementById('bgm').play()">▶ 播放</button>
    <button onclick="document.getElementById('bgm').pause()">⏸ 暂停</button>
    <div style='flex-grow:1; height:6px; background:#444; border-radius:3px; overflow:hidden;'>
      <div id='bar' style='height:6px;width:0%;background:#66f;'></div>
    </div>
  ";
  player.style.cssText = `
    position: fixed;
    bottom: 10px;
    right: 10px;
    z-index: 9999;
    background: #111;
    color: white;
    padding: 10px 15px;
    border-radius: 10px;
    display: flex;
    gap: 10px;
    align-items: center;
    box-shadow: 0 0 10px #000;
    font-size: 14px;
  `;
 
  document.body.appendChild(audio);
  document.body.appendChild(player);
 
  document.body.addEventListener('click', function () {
    audio.play().catch(() => {});
  }, { once: true });
 
  setInterval(function () {
    if (!audio.duration) return;
    const percent = (audio.currentTime / audio.duration) * 100;
    document.getElementById('bar').style.width = percent + '%';
    localStorage.setItem('bgm-time', audio.currentTime);
  }, 300);
});

2025年6月21日 (六) 12:32的最新版本

$(function () {
  // 在线人数统计区域
  var $counter = $('<div id="online-counter">当前在线 <span style="color:#a782ff;">👥</span>: <span id="online-number">加载中...</span></div>');
  $('body').append($counter);

  // 获取在线人数
  function updateOnlineNumber() {
    $.getJSON('/api/online.php', function (data) {
      $('#online-number').text(data.count || 0);
    }).fail(function () {
      $('#online-number').text('获取失败');
    });
  }

  updateOnlineNumber();
  setInterval(updateOnlineNumber, 30000); // 每 30 秒刷新一次

$(document).ready(function () {
  const $button = $('<a>', {
    href: '/index.php/首页',
    id: 'back-to-home-button',
    text: '🏠 返回主页'
  });
  $('body').append($button);
});


  // ✅ 把这一行放进 function 内部!
  mw.loader.load('/js/player.js?v=10');
}); // 👈 别忘了这个结束的大括号和括号