JS bookmarklet to apply multiple tags to text - by Rathmun
JAVASCRIPT BOOKMARKLET FOR APPLYING MULTIPLE TAGS TO TEXT - BY RATHMUN
When certain characters or situations routinely call for a combination of tags, placing all of them every time can grow awkward and result in mistakes. For example, if a character uses periwinkle as their voice color, and usually speaks Elven, then you're left applying both tags to all their speech every time.
Most modern browsers support something called a "bookmarklet", where you can place javascript in the destination URL field of a bookmark, which will be executed on the current page when you click on it. This allows the creation of a single button to apply any number of tags to a selected section of text.
The base form for this useful script is as follows.
javascript:(function(a){a.value=a.value.slice(0,a.selectionStart)+"YOUR STARTING TAGS GO IN THESE QUOTES"+a.value.slice(a.selectionStart,a.selectionEnd)+"YOUR ENDING TAGS GO IN THESE QUOTES"+a.value.slice(a.selectionEnd);})(document.activeElement);
Here are a few examples to illustrate usage.
For a character who speaks with green text, and usually in the Elven language, it would be as follows.
javascript:(function(a){a.value=a.value.slice(0,a.selectionStart)+"[Language Elven: <Green>"+a.value.slice(a.selectionStart,a.selectionEnd)+"</Green>]"+a.value.slice(a.selectionEnd);})(document.activeElement);
For a pixie speaking with small periwinkle text, this will work.
javascript:(function(a){a.value=a.value.slice(0,a.selectionStart)+"<Small><Periwinkle>"+a.value.slice(a.selectionStart,a.selectionEnd)+"</Periwinkle></Small>"+a.value.slice(a.selectionEnd);})(document.activeElement);
Or perhaps you want something for Signage.
javascript:(function(a){a.value=a.value.slice(0,a.selectionStart)+"<Mono><smallcaps><b>"+a.value.slice(a.selectionStart,a.selectionEnd)+"</b></smallcaps></Mono>"+a.value.slice(a.selectionEnd);})(document.activeElement);
To use these, simply create a bookmark, place the script in the destination field, and name the bookmark as you wish. Personally I usually use the name of the character who uses that set of tags.