Bakko - Transformations of FARR Text Field Content
Introduction The main point of this plugin is to provide a customizable means for transforming the main FARR window's text field content. At the moment, "customizable" means that the user can write a bit of JavaScript to operate on the text field content. It's also possible that people could share these bits of JavaScript
Usage Examples 1. Bring up FARR and type some text into the text field.
2. A statusbar icon should appear at (or near) the bottom right of the FARR main window, Click (currently, left-click) on this icon to bring up some possible transformations.
3. Some or all of the following may appear -- try one by clicking on the corresponding context menu item.
Evaluate
original text:
2 / 3
replaced with:
0.6666666666666666
original text:
(1 + 2 + 3) * (-1 + Math.pow(2, 3)) // note: use of JavaScript
replaced with:
42
Factor
original text:
6
replaced with:
1 * 2 * 3
ROT13
original text:
or fher gb qevax lbhe binygvar
replaced with:
be sure to drink your ovaltine
Sanitize Amazon.com URL
original text:
http://www.amazon.com/Mythical-Man-Month-Software-Engineering-Anniversary/dp/0201835959/ref=stuff
replaced with:
http://www.amazon.com/Mythical-Man-Month-Software-Engineering-Anniversary/dp/0201835959/
4. There is rudimentary support for access to a history of text strings which were successfully operated on (but not the results). The strings in the history may be accessed via the History submenu of the statusbar menu. NOTE: The history does not currently survive plugin reloads nor FARR restarts.
Creating a Transformation Each transformation is implemented as a JavaScript file living in the directory %PLUGINDIR%\transformations\. Before reading further, I suggest opening up one of the samples in a text editor -- the following description may be easier to follow. Choosing the shortest sample may be a good idea
The JavaScript file gets eval()-ed (nasty word, eh?) and the plugin expects the eval() result to be an object.
The samples accomplish this by starting the file w/:
(function () {
and ending it w/:
return {name: name,
caption: caption,
hint: hint,
icon: icon,
launch: launch,
display: display,
code: code};
} ());
(In case it wasn't obvious, what evaluation of that does (as I understand it), is to call a function which returns an object.)
In between, define the following (some optional):
name
string
no spaces
caption(stxt)
function
returns a string for the menu item's caption. currently, the returned string gets truncated and " ..." is appended if it is too long (see source of plugin for details).
stxt is the string value of the content of FARR's main window text field at the time the context menu is being constructed.
hint(stxt) optional
function
returns a string for the hint of the menu item.
stxt is the string value of the content of FARR's main window text field at the time the context menu is being constructed.
icon(stxt) optional
function
returns a string of the path to an icon for the menu item.
stxt is the string value of the content of FARR's main window text field at the time the context menu is being constructed.
launch(stxt)
function
returns a string used by FARR to execute the transformation code -- typically returns values looking like:
farr://pcommand bakko xform <name> <stxt>
stxt is the string value of the content of FARR's main window text field at the time the context menu is being constructed.
display(stxt) (optional)
function
returns a boolean, true if the transformation should show up in the context menu, false if not.
stxt is the string value of the content of FARR's main window text field at the time the context menu is being constructed.
code(argtxt)
function
returns a string or null.
a string value represents a successful transformation and FARR's main window text field should be replaced with it.
a null value means failure.
argtxt is currently the same as stxt (as mentioned above).
The transformation has access to variables and functions within the plugin's (function () {} ()) scope (I think). What this means is that displayname, aliasstr, pu, and the like may all be used within transformations.
If something isn't clear (or you think there are mistakes) here, I suggest asking on the forums and/or "Use the source, Luke"
Tips Having a hotkey defined to bring up FARR with clipboard content pasted in FARR's main window can be handy.
Bugs Probably
Credits Thanks go out to:
mouser
ecaradec
Plugin authors that provided source and/or comments on the forums
DC Forums participants
DC Supporters
Download Experimental -
please ensure that the parent directory of the contained fscript.js file is named Bakko.