WaniKani Cursor Behavior

change cursor behavior so that it doesn't jump to the end when editing kana

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name          WaniKani Cursor Behavior
// @namespace     https://www.wanikani.com
// @description   change cursor behavior so that it doesn't jump to the end when editing kana
// @version       0.1.0
// @include       https://www.wanikani.com/review/session
// @include       https://www.wanikani.com/lesson/session
// @include       http://www.wanikani.com/review/session
// @include       http://www.wanikani.com/lesson/session
// @run-at        document-end
// @grant         none
// ==/UserScript==

/*global console, wanakana*/

/*
source very slightly modified from:
https://github.com/WaniKani/WanaKana
License: The MIT License (MIT)
*/

(function () {
    'use strict';
    wanakana._onInput = function (event) {
        var input, newText, normalizedInputString, range, startingCursor, startingLength;
        input = event.target;
        startingCursor = input.selectionStart;
        startingLength = input.value.length;
        normalizedInputString = wanakana._convertFullwidthCharsToASCII(input.value);
        newText = wanakana.toKana(normalizedInputString, {
            IMEMode: true
        });
        if (normalizedInputString !== newText) {
            input.value = newText;
            if (typeof input.selectionStart === "number") {
                // input.selectionStart = input.selectionEnd = input.value.length; // original line
                input.selectionStart = input.selectionEnd = startingCursor + input.value.length - startingLength;
            } else if (typeof input.createTextRange !== "undefined") {
                input.focus();
                range = input.createTextRange();
                range.collapse(false);
                range.select();
            }
        }
    };
    console.log('WaniKani Cursor Behavior: script load end');
}());