Custom Key Commands

Allows custom key commands in text fields, so far I have added Bold and Italic

2016-05-10 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Custom Key Commands
// @namespace    PXgamer
// @version      0.4
// @description  Allows custom key commands in text fields, so far I have added Bold and Italic
// @author       PXgamer
// @include      *kat.cr/*
// @require      https://greasyfork.org/scripts/19569-jquery-selection-jquery-plugin/code/jQueryselection%20-%20jQuery%20Plugin.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var arrShortCut = [{ name: 'Bold', key: 66, fx: 'bold' }, { name: 'Italic', key: 73, fx: 'italic'}, { name: 'Preview', key: 13, fx: 'preview'}];

    var ctrl = 17; // CTRL Key
    var ctrlKeyActived = false;
    var ta = $('textarea#replytext');
    var isBBaction = false;
    var previewAction = false;

    $(document).keyup(function(e) {
        if (e.which == ctrl) ctrlKeyActived = false;
    }).keydown(function(e) {
        if (e.which == ctrl) ctrlKeyActived = true;
        if (ctrlKeyActived === true && ta.is(":focus")) {
            jQuery.each(arrShortCut, function(i) {
                if (arrShortCut[i].key == e.which) {
                    exec(arrShortCut[i].fx, ta);
                    return;
                }
            });
        }
    });

    function exec(fx, ta) {
        console.info(fx);
        var strings = [];
        switch (fx) {
            case 'bold':
                strings[0] = "[b]";
                strings[2] = "[/b]";
                isBBaction = true;
                break;
            case 'italic':
                strings[0] = "[i]";
                strings[2] = "[/i]";
                isBBaction = true;
                break;
            case 'preview':
                isBBaction = false;
                previewAction = true;
                break;
            default:
                strings[0] = "";
                strings[2] = "";
                isBBaction = false;
        }
        if (isBBaction === true) {
            if (window.getSelection) {
                strings[1] = window.getSelection().toString();
            } else if (document.selection && document.selection.type != "Control") {
                strings[1] = document.selection.createRange().text;
            }

            ta.selection('replace', { text: strings[0]+strings[1]+strings[2] });
        }
        if (previewAction === true) {
            $('span.ka.ka-preview.bbedit-preview[data-preview="#post_preview"]').click();
        }
    }
})();