MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
拦截AJAX退出 |
自定义退出URL |
||
| 第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'; | ||
var LOGOUT_URL = WIKI_BASE + '/wiki/首页?sso_action=logout'; | |||
function syncLoginState() { | function syncLoginState() { | ||
if ( mw.config.get( 'wgUserId' ) !== 0 ) return; | 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(r) { return r.json(); } ) | ||
.then( function(d) { | .then( function(d) { | ||
| 第39行: | 第14行: | ||
} | } | ||
} ).catch(function(){}); | } ).catch(function(){}); | ||
} | |||
function setupLogout() { | |||
// 把所有退出链接的 href 替换为自定义退出 URL | |||
$( document ).on( 'mouseenter', 'a[href*="action=logout"], a[href*="UserLogout"]', function() { | |||
$( this ).attr( 'href', LOGOUT_URL ); | |||
} ); | |||
// 直接点击拦截 | |||
$( document ).on( 'click', 'a[href*="action=logout"], a[href*="UserLogout"], a[href*="sso_action=logout"]', function(e) { | |||
e.preventDefault(); | |||
window.location.href = LOGOUT_URL; | |||
} ); | |||
} | } | ||
| 第66行: | 第53行: | ||
$( document ).ready( function() { | $( document ).ready( function() { | ||
syncLoginState(); | syncLoginState(); | ||
setupLogout(); | |||
interceptLoginButton(); | interceptLoginButton(); | ||
interceptRegisterButton(); | interceptRegisterButton(); | ||
2026年4月15日 (三) 02:20的版本
( function () {
'use strict';
var MAIN_SITE = 'https://www.dolshipmaker.vip';
var WIKI_BASE = 'https://wiki.dolshipmaker.vip';
var LOGOUT_URL = WIKI_BASE + '/wiki/首页?sso_action=logout';
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 setupLogout() {
// 把所有退出链接的 href 替换为自定义退出 URL
$( document ).on( 'mouseenter', 'a[href*="action=logout"], a[href*="UserLogout"]', function() {
$( this ).attr( 'href', LOGOUT_URL );
} );
// 直接点击拦截
$( document ).on( 'click', 'a[href*="action=logout"], a[href*="UserLogout"], a[href*="sso_action=logout"]', function(e) {
e.preventDefault();
window.location.href = LOGOUT_URL;
} );
}
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();
setupLogout();
interceptLoginButton();
interceptRegisterButton();
interceptEditForAnon();
} );
} );
}() );