paulmwatson
10/13/2017 - 8:15 AM

A simple bookmarklet that searches Twitter with the URL you are on.

A simple bookmarklet that searches Twitter with the URL you are on.

// A simple bookmarklet that searches Twitter with the URL you are on.
// Before you Tweet your own hot-take see what others are saying and ReTweet them instead.
// Author: @paulmwatson
// License: MIT
// Notes: It first looks for the "canonical" URL before falling back to the window.location.
//        It strips any URL parameters e.g. UTM and keeps just the protocol, host, and path.
//        This broadens the search as often UTM or other identifiers are unique to your session
//        and Twitter's search will return no results. However it can be inacurate on websites
//        that use URL parameters to identify content to show.
// Usage: Visit an article on a website like Buzzfeed.com and click the bookmarklet. A new tab 
//        opens with the page's URL as the search value.
// Installation: Create a new bookmark in your bookmarks bar and put the following as the URL.
javascript:var u = window.location.protocol + '//' + window.location.host + window.location.pathname; var l = document.getElementsByTagName("link"); for (var i = 0; i < l.length; i ++) { if (l[i].getAttribute('rel') === 'canonical') {u = l[i].getAttribute('href')}}; window.open('https://twitter.com/search?q=' + encodeURIComponent(u) + '&src=paulmwatson');