Jump to content

User:ערן/veReplace

From Wikipedia, the free encyclopedia

This script adds option for replace and replace all in VisualEditor.

Usage

[edit]

The script adds replace option in VE toolbar, which opens dialog for replacing term:

screenshot for ve replace dialog
screenshot for ve replace dialog
screenshot for ve replace button
screenshot for ve replace button

Setup

[edit]

User setup

[edit]

Copy the following code to your Special:MyPage/common.js:

//translate the following:
mw.messages.set({
	've-SearchAndReplaceDialog-title': 'Search and replace',
	've-SearchAndReplaceDialog-from-label': 'From:',
	've-SearchAndReplaceDialog-to-label': 'To:',
	've-SearchAndReplaceDialog-from-placeholder': 'From text',
	've-SearchAndReplaceDialog-to-placeholder': 'To text',
	've-SearchAndReplaceDialog-replaceAll': 'Replace all',
	've-SearchAndReplaceDialog-replace': 'Replace',
	've-SearchAndReplaceDialog-matchcase': 'Match case',
	've-SearchAndReplaceDialog-replace-complete': 'Found and replaced $1 occurrences',
	've-ReplaceTool-ToolbarButton': 'Replace'
});
//end of translations
mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init', function(){
	mw.libs.ve.addPlugin( function() { 
		return $.getScript('https://wiki.riteme.site/w/index.php?title=User:ערן/veReplace.js&action=raw&ctype=text/javascript'); 
	} );
});

Project setup

[edit]

To turn it as a gadget that user can select in their preferences (requires sysop rights):

mw.libs.ve.addPlugin('ext.gadget.veReplace');
*veReplaceLoader[ResourceLoader|dependencies=ext.visualEditor.viewPageTarget.init]|veReplaceLoader.js
*veReplace[ResourceLoader|rights=hidden|hidden|dependencies=ext.visualEditor.core]|veReplace.js

(notice the first line is just a loader for the real script which is declared in the second line - this way it is possible to load the replace option only once VE is activated)