Skip to content

Instantly share code, notes, and snippets.

@danott
Last active September 15, 2022 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danott/e0ff791aa8a2fb98b625037efea8c252 to your computer and use it in GitHub Desktop.
Save danott/e0ff791aa8a2fb98b625037efea8c252 to your computer and use it in GitHub Desktop.
The source code for my bookmarklet
var date = new Date()
date.setHours(date.getHours() - date.getTimezoneOffset() / 60)
date = date.toISOString().split("T").at(0)
var title = window.prompt("What's a good starter title?", document.title)
var slug = window.prompt("what's a good slug?", title.toLowerCase().replace(/\s+/g, "-"))
var filename = "content/posts/" + date + "-" + slug +".md"
var value = "#bookmark\n\n# [" + title + "](" + window.location.toString() + ")\n\n"
var quote = window.getSelection().toString()
if (quote) value += "> " + quote + "\n\n"
var url = new URL("https://github.com/danott/www.danott.co/new/main")
url.searchParams.append("filename", filename)
url.searchParams.append("value", value)
window.open(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment