MediaWiki:Gadget-titleparenthesis.js

Revision as of 16:00, 19 February 2020 by Banri (talk | contribs) (Created page with "$(function () { var conf = mw.config.get([ 'wgNamespaceNumber', 'wgTitle', 'wgAction' ]); if (conf.wgNamespaceNumber !== 0 || conf.wgTitle.lastI...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
$(function () {
    var conf = mw.config.get([
       'wgNamespaceNumber',
       'wgTitle',
       'wgAction'
    ]);

	if (conf.wgNamespaceNumber !== 0 || conf.wgTitle.lastIndexOf('(') < 0 ||
		conf.wgAction !== 'view' || $('.no-parenthesis-style').length) {
		return;
	} 
	
	// use the title in the DOM so this respects DISPLAYTITLE
	var title = $('h1#firstHeading').text(),
		start = title.lastIndexOf('('),
		end = title.substring(start, title.length).lastIndexOf(')');

	// add offset here
	end += start + 1;
	
	$('h1#firstHeading')
		.empty()
		.append(
			title.substring(0, start),
			$('<span>')
				.addClass('title-parenthesis')
				.text(title.substring(start, end)),
			title.substring(end, title.length)
		);
});