Skip to content

Instantly share code, notes, and snippets.

@zuphilip
Last active December 24, 2022 10:43
Show Gist options
  • Save zuphilip/075c9adb8ed97dc5666ae8b6d4ce297f to your computer and use it in GitHub Desktop.
Save zuphilip/075c9adb8ed97dc5666ae8b6d4ce297f to your computer and use it in GitHub Desktop.
Bookmarklet to prepare a toot from any website

Usage

This JavaScript bookmarklet will copy the selected text on any website and prepare a toot with that for you. It can be used as it is for the openbiblio.social and some other instances but can be easily adapted. To use it in your browser go through the following steps:

  1. Create a new bookmark in your browser
  2. Choose any name, e.g. Toot this!
  3. Copy the content of *.bookmarklet.js as its adress
  4. Save it

Now, you can go to any website and select some text and then click on the newly created bookmark. If you have not selected any text, the toot will contain the document title instead. For every case the url of the current website is given as the source as well. Other links, hashtags or images should then be added manually afterwards to the toot.

Adaption

For any other mastodon instance just change the first line in the original script and create a different bookmarklet, e.g. using this website.

License

Everything here is public domain / CC0.

javascript:(function()%7Bvar%20instance%20%3D%20%22https%3A%2F%2Fbildung.social%2F%22%3Bvar%20content%20%3D%20window.getSelection().toString()%3Bif%20(content.trim().length%20%3D%3D%200)%20%7Bcontent%20%3D%20document.title%3B%7Dvar%20url%20%3D%20instance%20%2B%20%22share%3Ftext%3D%22%20%2B%20encodeURIComponent(content%20%2B%20%22%5Cn%5CnSource%3A%20%22%20%2B%20window.location.href)%3Bwindow.open(url)%7D)()
javascript:(function()%7Bvar%20instance%20%3D%20%22https%3A%2F%2Fchaos.social%2F%22%3Bvar%20content%20%3D%20window.getSelection().toString()%3Bif%20(content.trim().length%20%3D%3D%200)%20%7Bcontent%20%3D%20document.title%3B%7Dvar%20url%20%3D%20instance%20%2B%20%22share%3Ftext%3D%22%20%2B%20encodeURIComponent(content%20%2B%20%22%5Cn%5CnSource%3A%20%22%20%2B%20window.location.href)%3Bwindow.open(url)%7D)()
javascript:(function()%7Bvar%20instance%20%3D%20%22https%3A%2F%2Fopenbiblio.social%2F%22%3Bvar%20content%20%3D%20window.getSelection().toString()%3Bif%20(content.trim().length%20%3D%3D%200)%20%7Bcontent%20%3D%20document.title%3B%7Dvar%20url%20%3D%20instance%20%2B%20%22share%3Ftext%3D%22%20%2B%20encodeURIComponent(content%20%2B%20%22%5Cn%5CnSource%3A%20%22%20%2B%20window.location.href)%3Bwindow.open(url)%7D)()
var instance = "https://openbiblio.social/";
var content = window.getSelection().toString();
if (content.trim().length == 0) {
content = document.title;
}
var url = instance + "share?text=" + encodeURIComponent(content + "\n\nSource: " + window.location.href);
window.open(url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment