MediaWiki
Gadget-sandbox.js
From Dogcraft Wiki
m (-) |
m (async/await) |
||
Line 4: | Line 4: | ||
mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows'] ).done( function () { | mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows'] ).done( function () { | ||
async function confirmDialoge() { | |||
return await (OO.ui.confirm( 'Are you sure?' ).done( async function ( confirmed ) { | |||
console.log('2'); | |||
if ( confirmed ) { | |||
console.log( 'User clicked "OK"!' ); | |||
//window.location.href = e.target.href; | |||
return true; | |||
} else { | |||
console.log( 'User clicked "Cancel" or closed the dialog.' ); | |||
return false; | |||
} | |||
})); | |||
} | |||
$( function () { | $( function () { | ||
var button = new OO.ui.ButtonWidget( { | var button = new OO.ui.ButtonWidget( { | ||
Line 27: | Line 41: | ||
e.preventDefault(); | e.preventDefault(); | ||
console.log('1'); | console.log('1'); | ||
var result = await confirmDialoge(); | |||
console.log('3'); | console.log('3'); | ||
return result; | |||
}); | }); | ||
Revision as of 17:14, 27 November 2021
$(document).ready(function() {
if (mw.config.get('wgPageName') === 'User:Domino/Sandbox') {
mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows'] ).done( function () {
async function confirmDialoge() {
return await (OO.ui.confirm( 'Are you sure?' ).done( async function ( confirmed ) {
console.log('2');
if ( confirmed ) {
console.log( 'User clicked "OK"!' );
//window.location.href = e.target.href;
return true;
} else {
console.log( 'User clicked "Cancel" or closed the dialog.' );
return false;
}
}));
}
$( function () {
var button = new OO.ui.ButtonWidget( {
label: 'Click me!',
classes: [ 'confirm-sandbox' ]
});
//button.on( 'click', function () {
//alert( 'You clicked the button!' );
/*OO.ui.alert( 'Something happened!' ).done( function () {
console.log( 'User closed the dialog.' );
});*/
/*OO.ui.confirm( 'Are you sure?' ).done( function ( confirmed ) {
if ( confirmed ) {
console.log( 'User clicked "OK"!' );
} else {
console.log( 'User clicked "Cancel" or closed the dialog.' );
}
});
});*/
$( '#mw-content-text' ).append( button.$element );
$( '.page-User_Domino_Sandbox a[href="https://discord.gg/r5xDRcy"]' ).on('click', function (e) {
e.preventDefault();
console.log('1');
var result = await confirmDialoge();
console.log('3');
return result;
});
});
});
}
});
This page was last modified on 27 November 2021, at 17:14. (2 years ago)