Schalk Burger

A simple bookmarklet to tweet the current page

Tuesday, 1 February 2022
Share

Christian Heilmann posted a great little tweet the current page bookmarklet on DEV Community back in 2019 that allows you to easily Tweet the current page you are viewing.

Unfortunately the original bookmarklet code stopped working since Twitter updated the compose Tweet path from twitter.com/intent/tweet? to twitter.com/compose/tweet.

I’ve updated Christian’s original code with the new compose Tweet path, making the bookmarklet functional again. You can find the updated bookmarklet code on this GitHub Gist and below:

javascript:(function(){n=getSelection().anchorNode;if(!n){t=document.title;}else{t=n.nodeType===3?n.data:n.innerText;}t=%27“%27+t.trim()+%27”\n\n%27;window.open(`https://twitter.com/compose/tweet?text=${encodeURIComponent(t)}${document.location.href}`)})();