Last active
December 15, 2021 20:56
-
-
Save paulmwatson/6281e9f021b393a26b8794f27d8ccf59 to your computer and use it in GitHub Desktop.
A simple bookmarklet that searches Twitter with the URL you are on.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment