-
-
Save stringertheory/cbe7a3a927789ecfe1fcb92fed943902 to your computer and use it in GitHub Desktop.
(function() { | |
function getSelectionText() { | |
var text = ""; | |
if (window.getSelection) { | |
text = window.getSelection().toString(); | |
} else if (document.selection && document.selection.type != "Control") { | |
text = document.selection.createRange().text; | |
} | |
return text; | |
} | |
function format_body() { | |
var body = ""; | |
body += "URL: " + document.location + "\n\n"; | |
body += "TITLE: " + document.title + "\n\n"; | |
body += "LAST MODIFIED: " + document.lastModified + "\n\n"; | |
var quote = getSelectionText(); | |
if (quote !== "") { | |
body += "------------------------------------------\n"; | |
body += "SELECTED TEXT:\n\n" + quote + "\n\n"; | |
body += "------------------------------------------\n\n"; | |
} | |
body += "NOTES:\n\n\n"; | |
return body; | |
} | |
function format_subject() { | |
return "[email to self]: " + document.title; | |
} | |
function make_url() { | |
var to_email = "[email protected]"; | |
return `mailto:${to_email}?subject=${encodeURIComponent(format_subject())}&body=${encodeURIComponent(format_body())}`; | |
} | |
console.log(make_url()); | |
window.open(make_url()); | |
})() |
Like this (remember to change the to_email
):
javascript:(function() { function getSelectionText() { var text = ""; if (window.getSelection) { text = window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { text = document.selection.createRange().text; } return text; } function format_body() { var body = ""; body += "URL: " + document.location + "\n\n"; body += "TITLE: " + document.title + "\n\n"; body += "LAST MODIFIED: " + document.lastModified + "\n\n"; var quote = getSelectionText(); if (quote !== "") { body += "------------------------------------------\n"; body += "SELECTED TEXT:\n\n" + quote + "\n\n"; body += "------------------------------------------\n\n"; } body += "NOTES:\n\n\n"; return body; } function format_subject() { return "[email to self]: " + document.title; } function make_url() { var to_email = "[email protected]"; return mailto:${to_email}?subject=${encodeURIComponent(format_subject())}&body=${encodeURIComponent(format_body())}
; } console.log(make_url()); window.open(make_url());})()
then put in bookmarklet by copying, removing newlines with
pbpaste | tr -d '\n' | pbcopy
, and then pasting into the bookmarket, prepended by "javascript:"