Javascript help for novice

Hi…I am both a novice to KM and JavaScript. I want to create a little script that will convert selected text to UPPERCASE in Gmail using hotkey CTL+CMD+V. I have written the following JavaScript…and I am not sure if the script is correct nor am I sure I know what to do with it inside of KM to create the macro. I would appreciate any help you can offer, thanks!

function selectText() {
    var selection = window.getSelection().getRangeAt(0);
    var selectedText = selection.extractContents();
    var span = document.createElement('span');
        
    span.setAttribute("style", "text-transform: Uppercase");
    
    span.className = 'selected-text';
    span.appendChild(selectedText);
    selection.insertNode(span);
}

$(document).on('mouseup', function () {
    selectText();
});

Thank you!

Gregg

Hi Gregg,

I know even less JavaScript than you do (which is to say, precisely none) but I can show you an easy way to convert selected text to UPPERCASE in any copy-and-pasteable application using just KM:
Make Selected Text UPPERCASE.kmmacros (3.3 KB)


Incidentally, the reason this macro is titled "3." is because it's part of a group of text macros I've used for years to convert selected text into numerous forms (using the same hotkey for all of them triggers a palette from which I can then press the corresponding number to use that text conversion). KM can do a lot more with text than just these, but IMO they're a great starting point:

This awesome…I will try it! You might check out PopClip, which probably does similar things and more: http://docs.pilotmoon.com/collection/1-popclip

For others reading this thread…I would still love help with my little Javascript and how to use it…as part of my own ongoing education. Thanks for helping if you can!

Gregg

1 Like