MediaWiki:Common.js:修訂間差異
外觀
無編輯摘要 標籤:行動版編輯 行動版網頁編輯 進階行動版編輯 |
小 受保護 "MediaWiki:Common.js"([編輯=僅允許管理員](無限期)[移動=僅允許管理員](無限期)) 標籤:行動版編輯 行動版網頁編輯 進階行動版編輯 |
||
(無差異)
| |||
2026年9月20日 (日) 01:25的版本
// <![CDATA[
(function() {
// 等待 DOM 載入完成
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
function init() {
// 嘗試多種可能的 container class
var container = document.querySelector('.mw-inputbox') ||
document.querySelector('.wb-inputbox') ||
document.querySelector('form[action*="action=edit"] input[type="text"]');
if (!container) return;
// 確保只對 inputbox 有效
if (!container.closest && container.tagName !== 'FORM') return;
var input = container.querySelector('input[type="text"]');
if (!input) return;
// 防重複執行
if (input.dataset.autoFilled) return;
var d = new Date();
var day = d.getDate();
var mon = ('0' + (d.getMonth() + 1)).slice(-2);
var yr = d.getFullYear();
// 填入日期
input.value = day + '日';
input.placeholder = '例如:' + day + '日';
input.dataset.autoFilled = 'true';
// 修正 form action 中的年月
var form = input.closest('form');
if (form) {
var action = form.getAttribute('action') || '';
if (action.includes('日誌/') && !action.includes('日誌/' + yr + '年/' + mon + '月/')) {
form.setAttribute('action', action.replace(/日誌\/\d{4}年\/\d{2}月\//, '日誌/' + yr + '年/' + mon + '月/'));
}
}
}
})();
// ]]>