Jump to content

User:FR30799386/readonly.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$.when( mw.loader.using( 'mediawiki.util' ), $.ready ).then( function () { 
if(mw.config.get('wgNamespaceNumber')<0)
{
	return;
}
    if (typeof(Storage) !== "undefined") {
    	console.log('User:FR30799386/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 veiw source','ca-readonly',	'Make text-area read-only',	'6');
     $('#ca-readonly').click(music);
	}
    }catch(e){
    	console.log('User:FR30799386/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:FR30799386');
    }
}
else{
	 mw.notify($( '<span><a href="//en.wikipedia.org/wiki/User:FR30799386/readonly.js">User:FR30799386/readonly.js</a> is unable to function properly due to incompatible browser specifications. Please upgrade to one of the browsers listed <a href="//caniuse.com/#feat=namevalue-storage">here</a> <span style="color:green">(in green)</span> to run the script.</span>' ),{ autoHide: false,type:'warn'});
}
} );