跳至內容

MediaWiki:Common.js:修訂間差異

BraveYe留言 | 貢獻
無編輯摘要
標籤行動版編輯 行動版網頁編輯 進階行動版編輯
BraveYe留言 | 貢獻
清空全部內容
標籤清空 行動版編輯 行動版網頁編輯 進階行動版編輯
 
(未顯示同一使用者於中間所作的 1次修訂)
第1行: 第1行:
// <![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 + '月/'));
            }
        }
    }
})();
// ]]>