User:V111P/js/Simple Keyboard Layout Changer

Simple Keyboard Layout Changer — with this script you can convert the characters you type in the search and resume input boxes and in the textarea into different characters — for example, into characters from a different language.

The script supports multiple layouts (multiple groups of characters to convert to) and you can switch between the different layouts with a click on a link. One link appears above the textarea and another one in the top right of the page (at least in the Monobook and Vector skins it's at the top right).

Warning: The way scripts that change the text in the textarea work is they overwrite the contents of the textarea with a new value on every change. In the case of SKLC this happens with every character you type (if it's a character that needs to be converted into another character). This affects how undo works, you can now undo only one character at a time (so now you need to press Ctrl-Z more). Test undo in your browser both with and without using this script to see the difference. In Google Chrome and Safari, undo doesn't appear to work at all after a script changes the contents of the textarea.

WikEd is also supported. If you turn WikEd on and off while editing, you may have to turn the SKLC off and on again to make it work. I could fix this, but probably won't unless somebody tells me they need it.

Installation
To install the script, you need to edit your common.js (or skin.js). First, add the configuration part. Here is an example of setting one layout consisting of only three characters:

Include the  line only if you want SKLC to be turned on and the (in this case) SY layout to be used by default. Without this you first need to click the link to activate the layout on every wiki page that you open.

Here's how the  property of each layout is used when that layout is active: The first character in , when you type it, is going to be converted into the first character of the   of the active layout, and so on. In the case of the example above, when the layout Symbols is activated, ^ will be converted into №, @ will be converted into §, and ` will be converted into €. Any other characters that you type won't be converted. Note that you need to escape \ and ' in the strings. Instead of a slash \ use two of them: \\ and instead of a single quote ' use a slash and a single quote after it: \'

You can also set the indicator's labels when turned off with the properties  (the default value is OFF) and   (the default value is The Keyboard Layout Changer is turned off). Set these just like you do the  property.

Then, include this line in your common.js:

To use this script on a wiki other than the English Wikipedia, instead of  use:

The default charsToConvert (that is, those used if you don't set the charsToConvert property of the sKLChangerConfig object) are:

One less important limitation of the application is that Caps Lock doesn't have any effect on character keys and its state can't be detected with JavaScript. If you want to use a letter on a character key, Caps Lock will not work there (of course, you can just use Shift).

Here is another example of setting sKLChangerConfig, this time with two layouts converting all character from the US standard keyboard other than the digits 0-9 into Cyrillic letters and other symbols:

You can, of course, type all the characters on one line if you prefer: