跳转到内容

User:Chatsven/Fast-Submit.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
(function () {
    'use strict';

    if (mw.config.get('wgAction') !== 'view' || !mw.config.get('wgArticleId')) {
        return;
    }

    $(function () {
        const $resubmitLinks = $('#mw-content-text a').filter(function () {
            const text = $(this).text().trim();
            return text === '再次提交' || text === '再次遞交';
        });

        if (!$resubmitLinks.length) {
            return;
        }

        $resubmitLinks.on('click', async function (e) {
            e.preventDefault();
            e.stopPropagation();

            const $link = $(this);
            const $btn = $link.find('.mw-ui-button, .cdx-button').length
                ? $link.find('.mw-ui-button, .cdx-button')
                : $link;

            if ($link.data('submitting')) {
                return;
            }

            await mw.loader.using(['mediawiki.api', 'oojs-ui-windows']);

            const confirmed = await OO.ui.confirm('確定要直接再次提交此草稿以供審核嗎?');
            if (!confirmed) {
                return;
            }

            $link.data('submitting', true);
            const originalText = $btn.text();
            $btn.text('正在提交…').css('pointer-events', 'none');

            const api = new mw.Api();

            try {
                await api.postWithEditToken({
                    action: 'edit',
                    pageid: mw.config.get('wgArticleId'),
                    prependtext: '{' + '{subst:submit}}\n',
                    summary: '再次提交草稿以供審閱',
                    watchlist: 'nochange'
                });

                mw.notify('草稿已成功再次提交!正在重新整理頁面…', { type: 'success' });
                setTimeout(() => location.reload(), 800);
            } catch (err) {
                console.error('[AFC Quick Resubmit]', err);
                mw.notify('提交失敗:' + (err.message || err), { type: 'error' });
                $link.data('submitting', false);
                $btn.text(originalText).css('pointer-events', '');
            }
        });
    });
})();