MediaWiki:Gadget-titleparenthesis.js
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.
1 $(function () {
2 var conf = mw.config.get([
3 'wgNamespaceNumber',
4 'wgTitle'
5 ]);
6
7 if (conf.wgNamespaceNumber !== 0 || conf.wgTitle.lastIndexOf('(') < 0 ||
8 $('.no-parenthesis-style').length) {
9 return;
10 }
11
12 // use the title in the DOM so this respects DISPLAYTITLE
13 var title = mw.html.escape($('h1#firstHeading').text()),
14 start = title.lastIndexOf('('),
15 end = title.substring(start, title.length).lastIndexOf(')');
16
17 // add offset here
18 end += start + 1;
19
20 $('h1#firstHeading')
21 .empty()
22 .append(
23 title.substring(0, start),
24 $('<span>')
25 .addClass('title-parenthesis')
26 .html(title.substring(start, end)),
27 title.substring(end, title.length)
28 );
29 });