User:DannyS712/Readonly.js

//Copied from User:FR30799386/readonly.js

$.when( mw.loader.using( 'mediawiki.util' ), $.ready ).then( function () {

if(mw.config.get('wgNamespaceNumber')<0)

{

return;

}

if (typeof(Storage) !== "undefined") {

console.log('User:DannyS712/Readonly.js says : localStorage found!😊');

try{

var music= function(clickEvent){

if ( clickEvent ) {

clickEvent.preventDefault();

}

mw.storage.session.set( 'script', 'ReadOnly' );

window.location.href =mw.util.getUrl(mw.config.get('wgPageName'),{action:'edit'});

};

if(mw.config.get('wgAction')=='edit'||mw.config.get('wgAction')=='submit')

{

if(mw.storage.session.get('script')=='ReadOnly')

{

document.getElementById('wpTextbox1').setAttribute('readonly', 'readonly');

mw.util.addCSS('.editOptions{display:none;}'+'#editpage-specialchars *{display:none;}');

mw.storage.session.remove( 'script' );

}

}

else{

mw.util.addPortletLink('p-cactions','#','Forced view source','ca-readonly', 'Make text-area read-only', '6');

$('#ca-readonly').click(music);

}

}catch(e){

console.log('User:DannyS712/Readonly.js has thrown the following error : ');

console.log(

'\t' + e.name + ' message: ' + e.message +

( e.at ? ' at: ' + e.at : '') +

( e.text ? ' text: ' + e.text : '')

);

console.log('If the script stops working, please report it to User talk:DannyS712');

}

}

else{

mw.notify($( 'User:DannyS712/Readonly.js is unable to function properly due to incompatible browser specifications. Please upgrade to one of the browsers listed here (in green) to run the script.' ),{ autoHide: false,type:'warn'});

}

} );