Skip to content

Instantly share code, notes, and snippets.

@lucifr
Forked from al3xandru/gist:1169583
Created September 11, 2012 06:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lucifr/3696466 to your computer and use it in GitHub Desktop.
Save lucifr/3696466 to your computer and use it in GitHub Desktop.
Things 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, url;
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(/^ +/, '').replace(/ +$/, '')
};
source = 'From: email subject:(' + subject + ')\n';
} else {
source = 'From: '
}
if (selectedTxt != '') selectedTxt += '\n';
url = 'things:add?notes=' + encodeURIComponent(selectedTxt + source + pageUri) + '&title=' + encodeURIComponent(subject);
w.location.href = url
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment