MediaWiki:Common.js

Revision as of 18:47, 14 July 2026 by Kuhlau (talk | contribs) (move to gadget)
(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.
/************************************************************************/
/* Any JavaScript here will be loaded for all users on every page load. */
/************************************************************************/

/* for [[w:c:dev:GlobalFileUsage]] */
window.globalFileUsageConfig = {
    'lang': ['pl', 'ru', 'vi', 'zh'],
    'auto_show': false
}

// Modifying redirect button from WikiEditor's source mode
mw.hook('ext.CodeMirror.ready').add(() => {
	$( '#wpTextbox1' ).on('wikiEditor-toolbar-buildSection-advanced', ( event, section ) => {
		// The exact paths are available in `jquery.wikiEditor.toolbar.config.js` file of the extension
		section.groups.insert.tools.redirect.action.options.pre = '#REDIRECT [[';
		section.groups.insert.tools.redirect.action.options.post = ']]\n\n[[Category:Redirect Pages]]';
	});
});

// Fix the search field not updating when ctrl+f with text selected (should be removed when/if fandom fixes it in native)
if (['edit', 'submit'].includes(mw.config.get('wgAction'))) {
	mw.hook('ext.CodeMirror.ready').add((cmDOM, cm)=>{
		cmDOM.find('.cm-content').get(0).addEventListener('keydown', (e)=>{
			if (e.key.toLowerCase()==='f' && e.ctrlKey) {
				const
				selected = cm.view.state.sliceDoc(
					cm.view.state.selection.main.from,
					cm.view.state.selection.main.to
				),
				search = cmDOM.find('.cdx-text-input__input[name="search"]');
				
				if (search.length>0 && selected.length>0) { search.val(selected); }
			}
		}, { capture: true });
	});
}