Jump to content

User:V111P/js/Simple Keyboard Layout Changer

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by V111P (talk | contribs) at 07:40, 11 November 2013 (update). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Simple Keyboard Layout Changer
DescriptionConverts the characters you type into other characters
Author(s)V111P
StatusBeta
UpdatedNovember 11, 2013; 11 years ago (2013-11-11)
BrowsersAll browsers
SkinsAll skins
SourceUser:V111P/SKLChanger.js

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 this application works is it overwrites the contents of the textarea 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 to see if you like it. In Google Chrome 30 it doesn't work at all (except if using WikEd).

WikEd is also supported.

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:

sKLChangerConfig = {
    charsToConvert: '^@`',
    layouts: [{
      // a short code name, such as EN, ES, etc, and a longer name
      name: 'SY', // a short, code name, such as EN, ES, etc.
	  label: 'Symbols', // a longer name
      // characters
      chars: '№§€'
    }]
};

Here's how the chars property of each layout is used when that layout is active: The first character in charsToConvert, when you type it, is going to be converted into the first character of the chars 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: \'

Then, include this line in your common.js:

importScript('User:V111P/SKLChanger.js'); // [[User:V111P/SKLChanger.js]]

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

mw.loader.load('//en.wikipedia.org/w/index.php?title=User:V111P/SKLChanger.js&action=raw&ctype=text/javascript');

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

'`-='
+ 'qwertyuiop[]\\'
+ 'asdfghjkl;\''
+ 'zxcvbnm,./'
// with shift
+ '~!@#$%^&*()_+'
+ 'QWERTYUIOP{}|'
+ 'ASDFGHJKL:"'
+ 'ZXCVBNM<>?';

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:

sKLChangerConfig = {
    charsToConvert: // These are the characters, which are going to be converted when you type them
      '', // Use an empty string to use the default string with the characters in the US standard keyboard order
    layouts: [{
      name: 'BG', // a short, code name, such as EN, ES, etc.
	  label: 'Bulgarian Standard', // a longer name
      chars: '`-.'
      + ',уеишщксдзц;('
      + 'ьяаожгтнвмч'
      + 'юйъэфхпрлб'
      + '~!?+"%=:/_№ІV'
      + 'ыУЕИШЩКСДЗЦ§)'
      + 'ЬЯАОЖГТНВМЧ'
      + 'ЮЙЪЭФХПРЛБ'
    },
    {
      name: 'BP',
	  label: 'Bulgarian Phonetic',
      chars: 'ч-='
      + 'явертъуиопшщю'
      + 'асдфгхйкл;\''
      + 'зьцжбнм,./'
      + '~!@#$%^&*()_+'
      + 'ЯВЕРТЪУИОПШЩЮ'
      + 'АСДФГХЙКЛ:"'
      + 'ЗЬЦЖБНМ<>?'
    }]
};

See also