Skip to content

Instantly share code, notes, and snippets.

@sulrich
Forked from al3xandru/gist:1169583
Created September 18, 2012 18:03
Show Gist options
  • Save sulrich/3744698 to your computer and use it in GitHub Desktop.
Save sulrich/3744698 to your computer and use it in GitHub Desktop.
OmniFocus Generalized Bookmarklet
javascript:(function(){
var w=window,d=document,selectedTxt=w.getSelection?w.getSelection():(d.getSelection)?d.getSelection():(d.selection?d.selection.createRange().text:0),pageUri=w.location.href,isGMail=w.location.host.match(/mail\.google\.com/),subject=d.title,source;
if(isGMail){
var msgFrm=d.getElementById("canvas_frame"),subjectSpans;
if(msgFrm){
subjectSpans=msgFrm.contentDocument.getElementsByClassName("hP");
if(subjectSpans)subject=subjectSpans[0].innerText;
};
if(!subjectSpans){
subject=d.title.substring(d.title.indexOf("-")+1,d.title.lastIndexOf("-")).replace(/^%20+/,"").replace(/%20+$/,"")
};
source="From:%20email%20subject:("+subject+")\n";
}
else {
source="From:%20"
}
if(selectedTxt)selectedTxt+="\n";
window.location='omnifocus:///add?note='+encodeURIComponent(selectedTxt+source+pageUri)+'&name='+encodeURIComponent(subject);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment