TechLifeWeb

Bookmarklet - Copy IMDB details to clipboard


Published by 
Scott Kingery
 on 

I wanted a quick way to copy movie details and a link to the page from IMDB. This way I can easily paste them to a Mastodon post or simply into a list of movies watched. Here's the result of the copied text:

🎬 Swingers: Directed by Doug Liman. With Jon Favreau, Vince Vaughn, Ron Livingston, Patrick Van Horn. A wannabe actor has a hard time moving on from a break-up, but he is lucky to have supportive friends. 🔗

To use this yourself, click and drag this link up to your browser favorites bar: IMDB copy details to clipboard
Note: You can right click on it in your browser bar and rename it.

The code:

javascript:(function() {
  try {
    const title = document.querySelector('h1')?.innerText.trim();
    const descriptionMeta = document.querySelector('meta[name="description"]');
    const description = descriptionMeta?.content.trim();
    const url = window.location.href;
	const link = `<a href="${url}" target="_blank">🔗</a>`;
    const text = `🎬 ${description} ${link}`;
    
    navigator.clipboard.writeText(text).then(() => {
      alert("IMDb info copied to clipboard:\n\n" + text);
    }, () => {
      alert("Failed to copy to clipboard.");
    });
  } catch (e) {
    alert("Something went wrong: " + e.message);
  }
})();