MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
恢复含退出拦截版本 |
退出后自动刷新 |
||
| 第4行: | 第4行: | ||
var WIKI_BASE = 'https://wiki.dolshipmaker.vip'; | var WIKI_BASE = 'https://wiki.dolshipmaker.vip'; | ||
function | // 拦截 mw.Api,屏蔽退出错误并自动刷新 | ||
fetch( MAIN_SITE + '/api/auth/cookie-logout', { method: 'POST', credentials: 'include' } ) | mw.loader.using( 'mediawiki.api' ).done( function() { | ||
var origPost = mw.Api.prototype.post; | |||
} | mw.Api.prototype.post = function( params ) { | ||
if ( params && params.action === 'logout' ) { | |||
var result = origPost.apply( this, arguments ); | |||
result.always( function() { | |||
fetch( MAIN_SITE + '/api/auth/cookie-logout', { method: 'POST', credentials: 'include' } ) | |||
.finally( function() { | |||
window.location.href = WIKI_BASE + '/wiki/首页'; | |||
} ); | |||
} ); | |||
return $.Deferred().resolve( {} ); | |||
} | |||
return origPost.apply( this, arguments ); | |||
}; | |||
} ); | |||
function syncLoginState() { | function syncLoginState() { | ||
| 第18行: | 第31行: | ||
} | } | ||
} ).catch(function(){}); | } ).catch(function(){}); | ||
} | } | ||
| 第64行: | 第58行: | ||
$( document ).ready( function() { | $( document ).ready( function() { | ||
syncLoginState(); | syncLoginState(); | ||
interceptLoginButton(); | interceptLoginButton(); | ||
interceptRegisterButton(); | interceptRegisterButton(); | ||
2026年4月15日 (三) 03:05的版本
( function () {
'use strict';
var MAIN_SITE = 'https://www.dolshipmaker.vip';
var WIKI_BASE = 'https://wiki.dolshipmaker.vip';
// 拦截 mw.Api,屏蔽退出错误并自动刷新
mw.loader.using( 'mediawiki.api' ).done( function() {
var origPost = mw.Api.prototype.post;
mw.Api.prototype.post = function( params ) {
if ( params && params.action === 'logout' ) {
var result = origPost.apply( this, arguments );
result.always( function() {
fetch( MAIN_SITE + '/api/auth/cookie-logout', { method: 'POST', credentials: 'include' } )
.finally( function() {
window.location.href = WIKI_BASE + '/wiki/首页';
} );
} );
return $.Deferred().resolve( {} );
}
return origPost.apply( this, arguments );
};
} );
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 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();
interceptLoginButton();
interceptRegisterButton();
interceptEditForAnon();
} );
} );
}() );