MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
移除syncLoginState,统一认证扩展已正常工作 |
退出不拦截MediaWiki原生流程,异步清除主站Cookie |
||
| 第4行: | 第4行: | ||
var WIKI_BASE = 'https://wiki.dolshipmaker.vip'; | var WIKI_BASE = 'https://wiki.dolshipmaker.vip'; | ||
// ── 退出登录 ────────────────────────────────────────── | |||
// MediaWiki 正常退出后,同步清除主站 Cookie | |||
function setupLogout() { | function setupLogout() { | ||
$( document ).on( 'click', '[href*="action=logout"], [href*="UserLogout"], [data-mw-logouturl]', function( | $( document ).on( 'click', '[href*="action=logout"], [href*="UserLogout"], [data-mw-logouturl]', function() { | ||
// 不阻止默认行为,让 MediaWiki 正常退出 | |||
// 同时异步通知主站清除 Cookie | |||
fetch( MAIN_SITE + '/api/auth/cookie-logout', { method: 'POST', credentials: 'include' } ) | |||
.catch( function(){} ); | |||
} ); | } ); | ||
} | } | ||
// ── 登录/注册按钮重定向到主站 ───────────────────────── | |||
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) { | ||
| 第32行: | 第30行: | ||
} | } | ||
// ── 匿名用户点编辑时跳转登录 ───────────────────────── | |||
function interceptEditForAnon() { | function interceptEditForAnon() { | ||
if ( mw.config.get( 'wgUserId' ) !== 0 ) return; | if ( mw.config.get( 'wgUserId' ) !== 0 ) return; | ||
2026年4月15日 (三) 13:06的版本
( function () {
'use strict';
var MAIN_SITE = 'https://www.dolshipmaker.vip';
var WIKI_BASE = 'https://wiki.dolshipmaker.vip';
// ── 退出登录 ──────────────────────────────────────────
// MediaWiki 正常退出后,同步清除主站 Cookie
function setupLogout() {
$( document ).on( 'click', '[href*="action=logout"], [href*="UserLogout"], [data-mw-logouturl]', function() {
// 不阻止默认行为,让 MediaWiki 正常退出
// 同时异步通知主站清除 Cookie
fetch( MAIN_SITE + '/api/auth/cookie-logout', { method: 'POST', credentials: 'include' } )
.catch( function(){} );
} );
}
// ── 登录/注册按钮重定向到主站 ─────────────────────────
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() {
setupLogout();
interceptLoginButton();
interceptRegisterButton();
interceptEditForAnon();
} );
} );
}() );