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

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
登录注册退出统一跳转主站
SSO状态同步
第3行: 第3行:
     var MAIN_SITE = 'https://www.dolshipmaker.vip';
     var MAIN_SITE = 'https://www.dolshipmaker.vip';
     var WIKI_BASE = 'https://wiki.dolshipmaker.vip';
     var WIKI_BASE = 'https://wiki.dolshipmaker.vip';
    function syncLoginState() {
        if ( mw.config.get( 'wgUserId' ) !== 0 ) return;
        fetch( MAIN_SITE + '/api/auth/verify', { method: 'POST', credentials: 'include' } )
        .then( function(r) { return r.json(); } )
        .then( function(d) {
            if ( d.valid && d.user && !window.location.search.includes('sso_refresh') ) {
                window.location.href = window.location.href + ( window.location.search ? '&' : '?' ) + 'sso_refresh=1';
            }
        } ).catch(function(){});
    }


     function interceptLogout() {
     function interceptLogout() {
         $( document ).on( 'click', 'a[href*="action=logout"], a[href*="Special:UserLogout"]', function ( e ) {
         $( document ).on( 'click', 'a[href*="action=logout"], a[href*="Special:UserLogout"]', function(e) {
             e.preventDefault();
             e.preventDefault(); e.stopPropagation();
            e.stopPropagation();
             fetch( MAIN_SITE + '/api/auth/cookie-logout', { method: 'POST', credentials: 'include' } )
             fetch( MAIN_SITE + '/api/auth/cookie-logout', {
             .finally( function() { window.location.href = WIKI_BASE + '/wiki/首页'; } );
                method: 'POST',
                credentials: 'include'
             } ).finally( function () {
                window.location.href = MAIN_SITE + '/login.html?redirect=' + encodeURIComponent( WIKI_BASE );
            } );
         } );
         } );
     }
     }


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


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


     mw.loader.using( 'mediawiki.util' ).done( function () {
     mw.loader.using( 'mediawiki.util' ).done( function() {
         $( document ).ready( function () {
         $( document ).ready( function() {
            syncLoginState();
             interceptLogout();
             interceptLogout();
             interceptLoginButton();
             interceptLoginButton();

2026年4月15日 (三) 01:29的版本

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

    function syncLoginState() {
        if ( mw.config.get( 'wgUserId' ) !== 0 ) return;
        fetch( MAIN_SITE + '/api/auth/verify', { method: 'POST', credentials: 'include' } )
        .then( function(r) { return r.json(); } )
        .then( function(d) {
            if ( d.valid && d.user && !window.location.search.includes('sso_refresh') ) {
                window.location.href = window.location.href + ( window.location.search ? '&' : '?' ) + 'sso_refresh=1';
            }
        } ).catch(function(){});
    }

    function interceptLogout() {
        $( document ).on( 'click', 'a[href*="action=logout"], a[href*="Special:UserLogout"]', function(e) {
            e.preventDefault(); e.stopPropagation();
            fetch( MAIN_SITE + '/api/auth/cookie-logout', { method: 'POST', credentials: 'include' } )
            .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() {
            syncLoginState();
            interceptLogout();
            interceptLoginButton();
            interceptRegisterButton();
            interceptEditForAnon();
        } );
    } );
}() );