I need to automate the copying of a HTML link to the current page that is viewed in the current Firefox Tab into other WYSIWYG editors. This is not the same as copying just the plain-text of the URL, nor is it the same as pasting just the plain-text of the web pages title. This is also not the same thing as navigating to some other web page that has the HTML link to the page of interest, selecting the text with the mouse cursor, and typing CTRL-C to copy it into the current operating systems clipboard (both Linux and Windows, should not make any difference). Only the update to the clipboard is to be automated; the pasting from the clipboard into the target application will be done manually.
The desired use case is as follows:
http://...
For example, if the webpage browsed to was http://www.google.com, and
the user clicked the user-defined key sequence, and if the user pasted
it into some Google Document, what they would see in that document is
not http://www.google.com
nor would they see Google
, but instead
would see what you would see when you read this in StackOverflow in a
web browser: Google
Now, there are Firefox extensions and bookmarklets that come close, but they all involve no net reduction in mouse motion and/or key press overhead, which is the most time-wasting aspect of this frequently occuring use case. My searches for an existing extension turned up nothing that exactly meets my needs (see Research section below). Therefore, I think I may need to roll my own extension (or modify an existing one), unless someone can point me to an existing extension that provides this functionality.
The extension I have in mind should work in Firefox version 11 or greater running on either Linux or any version of Windows. Only Firefox and a suitable Firefox extension should be needed, and not any other special software.
Targets of the paste should be:
About user-specified key bindings: If there was an extension already that did the above but without providing the ability to bind a keybinding to it, then I would expect to be able to use the keyconfig extension extension to handle that aspect. Actually, that might even be preferable; I don't know yet.
Below are approaches I investigated that came close to what I want, but did not exactly meet the need:
I am answering my own question:
The CTRL-SHIFT-F11
binding will silently stop working if both keysnail and keyconfig are installed into the same Firefox browser. The fix for me was to simply uninstall keysnail as I don't use it.
I did not actually need to write my own Firefox extension, but I did need to scrape out a bit of code that copies the richtext link from the Copy Link Text (CoLT) extension and apply it directly as a binding into the keyconfig extension as follows:
CTRL-SHIFT-F12
to bring up the keyconfig configuration menu.Copy Rich Text Link to Current Page
.Type in the following chunk of Javascript code (This code I carved
out of the objCoLT.CopyBoth
function inside the content/colt.js
file inside the Copy Link Text (CoLT) extension):
var url = content.document.location.href;
var text = content.document.title;
// Use the users selection instead of the title if text is selected:
var selection = document.commandDispatcher.focusedWindow.getSelection().toString();
if (selection != "")
{
text = selection;
}
var richText = "<a href=\"" + url + "\">" + text + "</a>";
var xfer = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
xfer.addDataFlavor("text/html");
var htmlString = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
htmlString.data = richText;
xfer.setTransferData("text/html", htmlString, richText.length * 2);
var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);
clipboard.setData(xfer, null, Components.interfaces.nsIClipboard.kGlobalClipboard);
Click Ok.
<disabled>
should be shown in the text field to the left of the Apply button.CTRL-SHIFT-F11
.To test this out, proceed as follows:
CTRL-SHIFT-F11
(or whatever keybinding you chose above).CTRL-V
.Change
.