-
Getting copyurlplus to copy the HTML of the selection
-
Notelets
-
Work
-
Personal
-
Today's pictures
-
Yesterday's pictures
-
Open Threads
Getting copyurlplus to copy the HTML of the selection
I've found the
copyurlplus extension for Firefox very useful. It lets me make a selection in a HTML window and then invoke the context menu to format that selection in a variety of ways and place that formatted version on the clipboard. (I've put together a
little screencast to demonstrate the copyurlplus extension.)
I've been wanting to extend the functionality of the extension to enable grabbing of the HTML of the selection (and not just some text reduction of the selection). I thought that I'd be able to borrow an idea from http://www.squarefree.com/bookmarklets/webdevel.html#partial_source where there is a piece of code:
getSelSource() { x = document.createElement("div"); x.appendChild(window.getSelection().getRangeAt(0).cloneContents()); return x.innerHTML; }
that returns the HTML of the current selection. I can confirm that this code works in a greasemonkey script. Unfortunately, I've had not been able to use the logic of this script in the context of the extension.
That is, I've replaced
content/copyurlplus/copyurlplusOverlay.js with
my version.
Essentially, I've made two different attempts at applying the logic. The first is:
function getCurrentHTMLSelection() {
// borrowed from http://www.squarefree.com/bookmarklets/webdevel.html#partial_source
var sel = "";
try {
var x = document.createElement("div");
var focusedWindow = document.commandDispatcher.focusedWindow;
var selection = focusedWindow.getSelection.call(focusedWindow);
x.appendChild(selection.getRangeAt(0).cloneContents());
sel = x.innerHTML;
} catch(e) {
sel = "An exception occurred in the script. Error name: " + e.name + "Error message: " + e.message;
}
return sel
}
but get sel = undefined
When I try
function getCurrentHTMLSelection2() {
// borrowed from http://www.squarefree.com/bookmarklets/webdevel.html#partial_source
var sel = "";
try {
var x = document.createElement("div");
x.appendChild(window.getSelection().getRangeAt(0).cloneContents());
sel = x.innerHTML;
} catch(e) {
sel = "An exception occurred in the script. Error name: " + e.name + "Error message: " + e.message;
}
return sel
}
I get the error:
An exception occurred in the script.
Error name: NS_ERROR_ILLEGAL_VALUEError message: Component returned failure code: 0x80070057
(NS_ERROR_ILLEGAL_VALUE) [nsISelection.getRangeAt]
At this point, I don't really understand how document.commandDispatcher works.....
Oh, yes, I did a
customization of copyurlplus to get what I call %HTMLSEL%:
user_pref("copyurlplus.menus.7.label", "Copy URL + Title + HTML Sel (for wiki)");
user_pref("copyurlplus.menus.7.copy", "[%URL% %TITLE%]: {{{#!html %HTMLSEL% }}}");
Notelets
Work
Personal
Digital Photos Even a Miser Can Enjoy - New York Times:
Twelve manufacturers entered this fifth annual camera cook-off. Each submitted the one sub-$300 camera (online price) that it felt took the best pictures.
Several trends emerged. Picture quality continues to improve every year, and the megapixel race continues apace; this year, five- and six-megapixel cameras are standard. (More megapixels permit bigger enlargements and more room to crop, but do not affect photo quality.)
Today, I bought an issue of
Stone Soup Magazine as a present for a bright and energetic eight-year old girl. I'm glad for
an ad in the New York Review of Books that prompted me into looking at a magazine that I had never heard of before a couple of days ago.
Today's pictures
Yesterday's pictures
| | | | | | | | | |
| | |   |   |   |   |   |   |   |
Open Threads
I usually like to work in parallel on a number of entries. Here I list them so they can be easily noted and accessed: