MediaWiki:Gadget-adminHighlight.js

From PUBG Wiki
Jump to navigation Jump to search

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.
// page that contains the list of admins on this wiki:
var adminListPage = 'MediaWiki:Gadget-adminHighlight/AdminList.json';

// load array of admins
$.getJSON(encodeURIComponent(adminListPage) + '?action=raw&ctype=text/json').then(function(data) {
	// add 'User:' to each admin name
	var admins = data.map(function(username) { return 'User:' + username; });
	mw.hook('wikipage.content').add(function() {
		// for each link with a title attribute:
		$('#mw-content-text a[title]').each(function() {
			var $this = $(this);
			var thisuser = $this.attr('title');
			// check if the title attribute is in the list of admins
			if (!$this.hasClass('admin-highlight') && $.inArray(thisuser, admins) > -1) {
				$this.addClass('admin-highlight');
			}
		});
	});
});