MediaWiki:Gadget-Purge.js:修订间差异

来自Vocawiki
跳转到导航 跳转到搜索
SaoMikoto留言 | 贡献
// Edit via InPageEdit
标签已被回退
SaoMikoto留言 | 贡献
(编辑自 Special:Permalink/86905) // Edit via InPageEdit
标签手工回退
 
第1行: 第1行:
"use strict";
/**
// <pre>
* 刷新缓存按钮
$(() => {
* 修改自 https://zh.wikipedia.org/w/index.php?title=User:%E6%A1%90%E7%94%9F%E3%81%93%E3%81%93/js/Gadget-purge.js&oldid=69943550
    if (!mw.config.get("wgIsArticle")) {
* @author [[zhwp:User:桐生ここ]]
        return;
*/
(function($, mw) {
    if ( mw.config.get( 'wgIsArticle' ) == true ) {
    if ( ( mw.config.get( 'wgMFAmc' ) == true ) && ( $( '#p-tb' ).length != 0 ) ) {
    $( '#p-tb' ).append( '<li class="toggle-list-item"><a class="toggle-list-item__anchor" href="' + $(location).attr( 'origin' ) + '/Special:Purge/' + mw.config.get( 'wgPageName' ) + '" data-mw="interface"><span class="mw-ui-icon mw-ui-icon-reload"></span>&nbsp;<span class="toggle-list-item__label">' + '刷新缓存' + '</span></a></li>' );
    }
    else {
    mw.util.addPortletLink( 'p-cactions' , $(location).attr( 'origin' ) + '/Special:Purge/' + mw.config.get( 'wgPageName' ), '刷新缓存' );
    }
     }
     }
 
})(jQuery, mw);
    const $purgeButton = (
        buttonText = wgULS("清除页面缓存", "清除頁面快取"),
        purgingText = wgULS("正在清除缓存", "正在清除快取"),
        succesText = wgULS("清除缓存成功!", "清除快取成功!"),
        failText = wgULS("清除缓存失败,点击可重试", "清除快取失敗,點選可重試", null, null, "清除快取失敗,點擊可重試")
    ) => {
        const $statusNode = $('<span class="n-button__content" />').text(buttonText);
        const $containerNode = $('<a class="n-button purgecache" />').append($statusNode);
        let runningStatus = false;
 
        $containerNode.on("click", async () => {
            if (runningStatus) {
                return;
            }
            $statusNode.text(purgingText);
            $statusNode.prepend('<img src="https://vj-wiki.top/images/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">');
            runningStatus = true;
 
            const api = new mw.Api();
            const opt = {
                action: "purge",
                format: "json",
                forcelinkupdate: true,
                titles: mw.config.get("wgPageName"),
            };
 
            try {
                await api.post(opt);
                $statusNode.text(succesText);
                setTimeout(() => location.reload(location, true), 200);
            } catch(e) {
                $statusNode.text(failText);
                // eslint-disable-next-line require-atomic-updates
                runningStatus = false;
                setTimeout(() => {
                    if (!runningStatus) {
                        $statusNode.text(buttonText);
                    }
                }, 5000);
            }
        });
        return $containerNode;
    };
 
    $("#p-cactions ul").append(
            $('<li class="mw-list-item mw-list-item-js" id="pt-purge" />').append($purgeButton())
    );
});
// </pre>

2025年9月14日 (日) 08:22的最新版本

/**
 * 刷新缓存按钮
 * 修改自 https://zh.wikipedia.org/w/index.php?title=User:%E6%A1%90%E7%94%9F%E3%81%93%E3%81%93/js/Gadget-purge.js&oldid=69943550
 * @author [[zhwp:User:桐生ここ]]
 */
(function($, mw) {
    if ( mw.config.get( 'wgIsArticle' ) == true ) {
    	if ( ( mw.config.get( 'wgMFAmc' ) == true ) && ( $( '#p-tb' ).length != 0 ) ) {
    		$( '#p-tb' ).append( '<li class="toggle-list-item"><a class="toggle-list-item__anchor" href="' + $(location).attr( 'origin' ) + '/Special:Purge/' + mw.config.get( 'wgPageName' ) + '" data-mw="interface"><span class="mw-ui-icon mw-ui-icon-reload"></span>&nbsp;<span class="toggle-list-item__label">' + '刷新缓存' + '</span></a></li>' );
    	}
    	else {
    		mw.util.addPortletLink( 'p-cactions' , $(location).attr( 'origin' ) + '/Special:Purge/' + mw.config.get( 'wgPageName' ), '刷新缓存' );
    	}
    }
})(jQuery, mw);