跳至內容

MediaWiki:Common.js:修訂間差異

BraveYe留言 | 貢獻
建立內容為「// <![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"]…」的新頁面
標籤行動版編輯 行動版網頁編輯 進階行動版編輯
 
BraveYe留言 | 貢獻
清空全部內容
標籤清空 行動版編輯 行動版網頁編輯 進階行動版編輯
 
(未顯示同一使用者於中間所作的 2次修訂)
第1行: 第1行:
// <![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);
        }
    }
})();
// ]]>