2nd
html fragment from opera into html clipboard
I’m a user of Supermemo and lately Evernote, and of course Opera. Now as with many softwares i use they work great alone, but their lack of cooperation is severely cripling to their ultimate usefulness together. Wouldnt it be great if (like with Firefox, which i don’t use simply because it is too slow) a selected html fragment from Opera can be copied to the clipboard into the windows HTML Clipboard format so that it can be pasted to any supported application, with the formatting mostly intact? Yes, but no I don’t have a user friendly solution, since I am myself an amateur programmer I can only give you amateurish javascript and python scripts to deal with this problem. Sorry.
first place this piece of Opera command somewhere, either as a shortcut or a menu command. (for example, in preferences -> advanced -> shortcuts -> edit (either mouse or keyboard setup)
Copy & Go to Page, “javascript:(function(){var html_selection=document.createElement(‘div’); html_selection.appendChild(window.getSelection().getRangeAt(0).cloneContents()); document.location=’data:text/cwf;charset=UTF-8,’+encodeURIComponent(document.location+’\r\n’+html_selection.innerHTML);})()”“
also add a mime type “text/cwf” which opens a python script with the following code
from sys import argv as arguments
import htmlclipboard # the module to deal with “HTML Format” (a clipboard format for formatted text)
tempfile=arguments[1] # the file opera places the copied content into
f=open(tempfile,’r’)
source=f.readline()[:-1] #source url
content=f.read() #html fragment
f.close()
cb=htmlclipboard.HtmlClipboard()
cb.PutFragment(content,None,None,source)
get the htmlclipboard module from here. if you dont have pywin32, get it here
and you are done! to copy text you just execute the Opera command with your set keyboard or mouse or menu shortcut or whatever. The formatted text will be in your clipboard.
EDITED: to include source url so that you can paste it in Evernote with the source url attribute set
references:
http://my.opera.com/community/forums/topic.dml?id=182633&t=1233471387&page=1
http://code.activestate.com/recipes/474121/
http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html
http://web.archive.org/web/20070827011520/http://forum.evernote.com/phpbb/viewtopic.php?t=195