User:SSethi (WMF)/Sandbox/SimpleUserScriptExamples.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Simple user script examples to demonstrate the use of ResourceLoader
core modules: https://www.mediawiki.org/wiki/ResourceLoader/Core_modules */ 

// Example 1: Use of jQuery function to make article font size bigger
$('body').css('font-size', '1.5em');

// Example 2: Use of `mw.config` & `mw.notify` module to send in a notification
// for groups a user is a part of
mw.notify(mw.config.get('wgUserGroups'));

// Example 3: Use of `mw.now` module and jQuery function to fetch the date and 
// display it beneath the article title
$('#bodyContent').prepend(new Date(mw.now()));

// Example 4: User script to calculate and display estimated reading time of an
// article
var words = $('#bodyContent').text().split(' ').length,
	avgSpeed = Math.round(words / 250);
$('#firstHeading').append("<small> (" + avgSpeed + " min" + " read) </small>");