Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active September 10, 2020 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rauschma/3bba715b841f240a07cef12d084f702d to your computer and use it in GitHub Desktop.
Save rauschma/3bba715b841f240a07cef12d084f702d to your computer and use it in GitHub Desktop.
// Bookmarklet: display the alt text of images on Twitter
// Instructions: copy the whole text block, starting at `javascript:` and make it the address of a bookmark
// You can test it here: https://twitter.com/rauschma/media
javascript:{
let img;
const match = /\/photo\/([0-9]+)$/.exec(String(location));
if (match) {
const photoNumber = match[1];
img = document.querySelector(`li[role=listitem]:nth-child(${photoNumber}) img[alt]`);
}
if (!img) {
img = document.querySelector('a[href *= "/photo/"] img[alt]');
}
const alt = img ? img.alt : '(No <img alt> found)';
alert(alt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment