User:Edokter/FontSizer.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Edokter/FontSizer. This user script seems to have an accompanying .css page at User:Edokter/FontSizer.css. |
/**
* Add an experimental fontsizer applet to the Tools menu.
*
* @dependencies: mediawiki.cookie
* @source: [[User:Edokter/FontSizer.js]] / [[User:Edokter/FontSizer.css]]
* @revision 3.1
* @author: Edokter ([[User:Edokter]])
**/
/* Load dependencies (remove when loading through ResourceLoader) */
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:Edokter/FontSizer.css&action=raw&ctype=text/css', 'text/css' );
mw.loader.using( 'mediawiki.cookie', function() {
/* Begin of mw.loader.using callback */
$( document ).ready( function() {
var fontsizerButtons =
'<li id="t-fontsizer">' +
'<input type="submit" id="t-fontsizer-minus" name="minus" title="Decrease fontsize [alt--]" accesskey="-" value="−">' +
'<input type="submit" id="t-fontsizer-reset" name="reset" title="Reset fontsize [alt-0]" accesskey="0" value="100%">' +
'<input type="submit" id="t-fontsizer-plus" name="plus" title="Increase fontsize [alt-+]" accesskey="+" value="+">' +
'</li>';
var bodyStyle = document.getElementsByTagName( 'body' )[0].style;
function getSize() {
return parseInt( bodyStyle.fontSize.replace( '%', '' ) );
}
function setSize( size ) {
bodyStyle.fontSize = size == 100 ? '' : size + '%';
mw.cookie.set( 'fontSizer.size', size == 100 ? null : size, { prefix: '' } );
$( '#t-fontsizer-reset' ).attr( 'value', size + '%' );
}
/* Initialize */
$( '#p-tb' ).find( 'ul' ).prepend( fontsizerButtons );
var cookie = mw.cookie.get( 'fontSizer.size', '' );
if ( cookie ) {
setSize( cookie );
}
$( '#t-fontsizer-minus' ).click( function() {
var newSize = getSize();
if ( !newSize ) {
newSize = 100;
}
if ( newSize > 50 ) {
newSize <= 100 ? newSize -= 5 : newSize -= 10;
}
setSize( newSize );
});
$( '#t-fontsizer-plus' ).click( function() {
var newSize = getSize();
if ( !newSize ) {
newSize = 100;
}
if ( newSize < 200 ) {
newSize < 100 ? newSize += 5 : newSize += 10;
}
setSize(newSize);
});
$( '#t-fontsizer-reset' ).click( function() {
setSize( 100 );
});
});
/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */