Created
November 24, 2021 17:31
-
-
Save stringertheory/cbe7a3a927789ecfe1fcb92fed943902 to your computer and use it in GitHub Desktop.
code for a bookmarklet to email stuff to myself
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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()); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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());})()