打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
退出后always跳首页
不拦截退出,在退出完成页清除主站Cookie
第4行: 第4行:
     var WIKI_BASE = 'https://wiki.dolshipmaker.vip';
     var WIKI_BASE = 'https://wiki.dolshipmaker.vip';


     function setupLogout() {
    // 如果当前页面是退出完成页,清除主站 Cookie 并跳回首页
         $( document ).on( 'click', '[href*="action=logout"], [href*="UserLogout"], [data-mw-logouturl]', function(e) {
     function handlePostLogout() {
            e.preventDefault();
         var title = mw.config.get( 'wgCanonicalSpecialPageName' );
            e.stopImmediatePropagation();
        if ( title === 'Userlogout' && mw.config.get( 'wgUserId' ) === 0 ) {
 
            fetch( MAIN_SITE + '/api/auth/cookie-logout', { method: 'POST', credentials: 'include' } )
            new mw.Api().postWithToken( 'csrf', { action: 'logout' } )
            .catch( function(){} )
            .always( function() {
            .finally( function() {
                fetch( MAIN_SITE + '/api/auth/cookie-logout', { method: 'POST', credentials: 'include' } )
                window.location.href = WIKI_BASE + '/wiki/首页';
                .catch( function(){} )
                .finally( function() {
                    window.location.href = WIKI_BASE + '/wiki/首页';
                } );
             } );
             } );
 
         }
            return false;
         } );
     }
     }


第46行: 第40行:
     mw.loader.using( 'mediawiki.util' ).done( function() {
     mw.loader.using( 'mediawiki.util' ).done( function() {
         $( document ).ready( function() {
         $( document ).ready( function() {
             setupLogout();
             handlePostLogout();
             interceptLoginButton();
             interceptLoginButton();
             interceptRegisterButton();
             interceptRegisterButton();

2026年4月15日 (三) 17:05的版本

( function () {
    'use strict';
    var MAIN_SITE = 'https://www.dolshipmaker.vip';
    var WIKI_BASE = 'https://wiki.dolshipmaker.vip';

    // 如果当前页面是退出完成页,清除主站 Cookie 并跳回首页
    function handlePostLogout() {
        var title = mw.config.get( 'wgCanonicalSpecialPageName' );
        if ( title === 'Userlogout' && mw.config.get( 'wgUserId' ) === 0 ) {
            fetch( MAIN_SITE + '/api/auth/cookie-logout', { method: 'POST', credentials: 'include' } )
            .catch( function(){} )
            .finally( function() {
                window.location.href = WIKI_BASE + '/wiki/首页';
            } );
        }
    }

    function interceptLoginButton() {
        $( document ).on( 'click', 'a[href*="Special:UserLogin"], a[href*="action=login"]', function(e) {
            e.preventDefault();
            window.location.href = MAIN_SITE + '/login.html?redirect=' + encodeURIComponent( window.location.href );
        } );
    }

    function interceptRegisterButton() {
        $( document ).on( 'click', 'a[href*="Special:CreateAccount"], a[href*="action=createaccount"]', function(e) {
            e.preventDefault();
            window.location.href = MAIN_SITE + '/register.html?redirect=' + encodeURIComponent( window.location.href );
        } );
    }

    function interceptEditForAnon() {
        if ( mw.config.get( 'wgUserId' ) !== 0 ) return;
        $( document ).on( 'click', 'a[href*="action=edit"], a[href*="veaction=edit"]', function(e) {
            e.preventDefault();
            window.location.href = MAIN_SITE + '/login.html?redirect=' + encodeURIComponent( window.location.href );
        } );
    }

    mw.loader.using( 'mediawiki.util' ).done( function() {
        $( document ).ready( function() {
            handlePostLogout();
            interceptLoginButton();
            interceptRegisterButton();
            interceptEditForAnon();
        } );
    } );
}() );