MediaWiki:Gadget-RightToolbar.js:修订间差异
删除的内容 添加的内容
小 功能增强v2 |
小 修改bug |
||
第1行:
/* ================================================================
MediaWiki Gadget: Custom Tools
功能:
- 回到顶部 / 回到底部按钮
-
- 深色模式自动适配
- 动态显示按钮 + 平滑动画
作者:你自己
================================================================= */
mw.loader.using(['mediawiki.util', 'mediawiki.
function updateClock(
var local = new Date();
// UTC 时间,从浏览器系统获取即可
var utc = new Date(local.getTime() + local.getTimezoneOffset() * 60000);
//
var
year: 'numeric', month: '2-digit', day: '2-digit',▼
// dateStyle/timeStyle 采用 Intl.DateTimeFormat 可选参数,也可以用短/长格式
hour: '2-digit', minute: '2-digit', second: '2-digit',
hour12: false
}).format(local);
var utcString = new Intl.DateTimeFormat(userLang, {
▲ // UTC 格式
▲ var utcFormatter = new Intl.DateTimeFormat('en-US', {
▲ year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', second: '2-digit',
hour12: false, timeZone: 'UTC
}).format(utc);
$('#current-local-time').text(
$('#current-utc-time').text(
}
$(function () {
var isMobile = window.innerWidth <= 768;
/* ---------- 深色模式检测 ---------- */
第81行 ⟶ 第82行:
}
/* ----------
var $topButton = createButton('mw-scroll-top', '▲', '回到顶部', function () {
$('html, body').animate({ scrollTop: 0 }, { duration: 500, easing: 'swing' });
});
var $bottomButton = createButton('mw-scroll-bottom', '▼', '回到底部', function () {
$('html, body').animate({ scrollTop: $(document).height() }, { duration: 500, easing: 'swing' });
});
/* ---------- 时钟
if (!isMobile) {
var $clockDiv = $('<div id="current-clock"></div>').css({
第103行 ⟶ 第105行:
backdropFilter: 'blur(4px)'
}).append(
$('<div id="current-local-time">加载中...</div>'),
$('<div id="current-utc-time">加载中...</div>')
);
$container.append($clockDiv);
第112行 ⟶ 第114行:
$container.append($topButton, $bottomButton);
/* ---------- 初次进入
$container.animate({ opacity: 1, transform: 'translateY(0)' }, 600);
/* ---------- 时钟定时更新 ---------- */
if (!isMobile) {
updateClock(
setInterval(
}
/* ---------- 滚动动态控制按钮显示 ---------- */
$topButton.hide(); // 初始隐藏
$(window).on('scroll', function () {
var scrollTop = $(this).scrollTop();
| |||