Last active
September 10, 2020 20:41
-
-
Save rauschma/3bba715b841f240a07cef12d084f702d to your computer and use it in GitHub Desktop.
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
// 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