MediaWiki:Common.js:修订间差异
外观
删除的内容 添加的内容
创建页面,内容为“$(function () { // 需要隱藏的地區變體代碼 var hideVariants = ['zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw']; // 遍歷並隱藏該選項 hideVariants.forEach(function (code) { $('#p-variants a[href*="' + code + '"]').closest('li').hide(); }); });” |
无编辑摘要 |
||
| (未显示同一用户的1个中间版本) | |||
| 第6行: | 第6行: | ||
hideVariants.forEach(function (code) { |
hideVariants.forEach(function (code) { |
||
$('#p-variants a[href*="' + code + '"]').closest('li').hide(); |
$('#p-variants a[href*="' + code + '"]').closest('li').hide(); |
||
}); |
|||
}); |
|||
$(function () { |
|||
// 建立顯示時間的 DOM 元素 |
|||
var $clock = $('<li>', { id: 'utc-live-clock' }).css({ |
|||
'display': 'inline-block', |
|||
'padding': '0 8px', |
|||
'font-family': 'monospace', |
|||
'font-weight': 'bold', |
|||
'vertical-align': 'middle', |
|||
'line-height': 'normal' |
|||
}); |
|||
// 將時間按鈕插入到右上角的個人選單最前方(也可依需求改插入位置) |
|||
$('#p-personal ul').prepend($clock); |
|||
// 更新時間的函式 (UTC 時區) |
|||
function updateClock() { |
|||
var now = new Date(); |
|||
// 格式化 UTC 時間為 HH:MM:SS |
|||
var hours = String(now.getUTCHours()).padStart(2, '0'); |
|||
var minutes = String(now.getUTCMinutes()).padStart(2, '0'); |
|||
var seconds = String(now.getUTCSeconds()).padStart(2, '0'); |
|||
$clock.text(hours + ':' + minutes + ':' + seconds + ' (UTC)'); |
|||
} |
|||
// 立即執行一次,並設定每秒更新 |
|||
updateClock(); |
|||
setInterval(updateClock, 1000); |
|||
}); |
|||
$(function () { |
|||
// 透過 MediaWiki API 取得全站統計資料(包含條目數量) |
|||
new mw.Api().get({ |
|||
action: 'query', |
|||
meta: 'siteinfo', |
|||
siprop: 'statistics', |
|||
formatversion: 2 |
|||
}).done(function (data) { |
|||
if (data && data.query && data.query.statistics) { |
|||
// 取得條目數(articles)並轉為帶有千分位逗號的格式 |
|||
var articleCount = data.query.statistics.articles.toLocaleString(); |
|||
// 組合提示文字 |
|||
var placeholderText = '搜尋 ' + articleCount + ' 個條目'; |
|||
// 修改傳統/Vector 版面的搜尋框 placeholder |
|||
$('#searchInput').attr('placeholder', placeholderText); |
|||
// 如果有使用新版 Vector 或其他搜尋輸入框,一併覆蓋 |
|||
$('input[name="search"]').attr('placeholder', placeholderText); |
|||
} |
|||
}); |
}); |
||
}); |
}); |
||
2026年8月4日 (二) 07:10的最新版本
$(function () {
// 需要隱藏的地區變體代碼
var hideVariants = ['zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw'];
// 遍歷並隱藏該選項
hideVariants.forEach(function (code) {
$('#p-variants a[href*="' + code + '"]').closest('li').hide();
});
});
$(function () {
// 建立顯示時間的 DOM 元素
var $clock = $('<li>', { id: 'utc-live-clock' }).css({
'display': 'inline-block',
'padding': '0 8px',
'font-family': 'monospace',
'font-weight': 'bold',
'vertical-align': 'middle',
'line-height': 'normal'
});
// 將時間按鈕插入到右上角的個人選單最前方(也可依需求改插入位置)
$('#p-personal ul').prepend($clock);
// 更新時間的函式 (UTC 時區)
function updateClock() {
var now = new Date();
// 格式化 UTC 時間為 HH:MM:SS
var hours = String(now.getUTCHours()).padStart(2, '0');
var minutes = String(now.getUTCMinutes()).padStart(2, '0');
var seconds = String(now.getUTCSeconds()).padStart(2, '0');
$clock.text(hours + ':' + minutes + ':' + seconds + ' (UTC)');
}
// 立即執行一次,並設定每秒更新
updateClock();
setInterval(updateClock, 1000);
});
$(function () {
// 透過 MediaWiki API 取得全站統計資料(包含條目數量)
new mw.Api().get({
action: 'query',
meta: 'siteinfo',
siprop: 'statistics',
formatversion: 2
}).done(function (data) {
if (data && data.query && data.query.statistics) {
// 取得條目數(articles)並轉為帶有千分位逗號的格式
var articleCount = data.query.statistics.articles.toLocaleString();
// 組合提示文字
var placeholderText = '搜尋 ' + articleCount + ' 個條目';
// 修改傳統/Vector 版面的搜尋框 placeholder
$('#searchInput').attr('placeholder', placeholderText);
// 如果有使用新版 Vector 或其他搜尋輸入框,一併覆蓋
$('input[name="search"]').attr('placeholder', placeholderText);
}
});
});