MediaWiki:Common.js
外觀
注意:在您發布之後,您可能需要清除瀏覽器快取才能看到變更。
- Firefox或Safari:按住Shift時點擊重新整理,或按Ctrl-F5或Ctrl-R(Mac則為⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac則為⌘-Shift-R)
- Edge:按住Ctrl時點擊重新整理,或按Ctrl-F5。
// <![CDATA[
(function() {
// 仅在包含 inputbox 的页面执行,避免全站性能损耗
var inputBox = document.querySelector('.mw-inputbox');
if (!inputBox) return;
var today = new Date();
var day = today.getDate();
var month = (today.getMonth() + 1).toString().padStart(2, '0');
var year = today.getFullYear();
// 精准定位 InputBox 生成的输入框
var targetInput = inputBox.querySelector('input[type="text"]');
if (!targetInput) return;
// 仅当用户未手动修改时自动填入
if (!targetInput.dataset.autoFilled) {
targetInput.value = day + '日';
targetInput.placeholder = '例如:' + day + '日';
targetInput.dataset.autoFilled = 'true';
// 同步更新 prefix 中的年月(防止跨月/跨年失效)
var prefix = '日誌/' + year + '年/' + month + '月/';
var form = inputBox.querySelector('form');
if (form && form.action.includes('title=')) {
form.action = form.action.replace(/日誌\/\d+年\/\d+月\//, prefix);
}
}
})();
// ]]>