User:Diskdance/goto.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
( () => {
mw.loader.using( 'mediawiki.widgets' ).then( () => {
const windowManager = new OO.ui.WindowManager();
$( document.body ).append( windowManager.$element );
window.addEventListener( 'keydown', ( event ) => {
if ( event.ctrlKey && event.shiftKey && event.key === ' ' ) {
if ( windowManager.getCurrentWindow() !== null ) {
return;
}
event.preventDefault();
const titleWidget =
new mw.widgets.TitleInputWidget( {
$overlay: OO.ui.getDefaultOverlay(),
placeholder: 'Where\'d you go?',
showDescriptions: true,
showInterwikis: true
} ),
messageDialog = new OO.ui.MessageDialog();
titleWidget.on( 'enter', () => {
windowManager.closeWindow( messageDialog, { action: 'accept' } );
} );
windowManager.addWindows( [ messageDialog ] );
const instance = windowManager.openWindow( messageDialog, {
title: 'Go to',
message: titleWidget.$element
} );
instance.closed.then( ( { action = 'reject' } = {} ) => {
if ( action === 'accept' ) {
const input = titleWidget.getValue();
if ( input !== '' ) {
window.open( mw.format( mw.config.get( 'wgArticlePath' ), input ) );
}
}
} );
instance.opened.then( () => titleWidget.focus() );
}
} );
} );
} )();