I often want to copy the link to a page I'm viewing in the browser to the clipboard to paste it in a note or document that I'm editing. These are bookmarklets and user scripts to help with this task.
copy_markdown_link_bookmarklet.js
: A bookmarklet that copies the the title and URL of the current page to the clipboard as a Markdown-formatted link. This works in Chrome, but not in Firefox, I think because "Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the "clipboardWrite" permission can write to the clipboard at any time." (See https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API)copy_markdown_link_userscript.js
: A user script that copies the the title and URL of the current page to the clipboard as a Markdown-formatted link. I wrote this because Firefox didn't seem to support providing clipboard access to a bookmarklet. I've successfully run this using the Tampermonkey user script manager.copy_rendered_link_userscript.js
: A user script that copies the title and URL of the current page to the clipboard as an HTML link. This script sets the mime type so if you paste the link into a Google doc or Evernote note, it will be pasted as a rendered link. I've successfully run this using the Tampermonkey user script manager.
The copy markdown link user script doesn't seem to work correctly on Google Docs when running under Tampermonkey on Firefox 116.0.2 (64-bit) on macOS. I haven't tested this on Firefox on other platforms. It has been working fine on Chrome. The user script also seems to work fine on pages that are not Google Docs.
Initially, the title would not be copied.
I noticed that the script was triggered multiple times when visiting a Google Docs URL. Adding the
@noframes
directive caused it only to be triggered on the main page, and the title is able to be accessed in the script viadocument.title
, but then copying to the clipboard doesn't work.I tried the script under Violentmonkey as well and it had the same issue.