Skip to content

Instantly share code, notes, and snippets.

@porglezomp
Created June 19, 2020 17:41
Show Gist options
  • Save porglezomp/81e39043258296769db8cf7bcea3aaf2 to your computer and use it in GitHub Desktop.
Save porglezomp/81e39043258296769db8cf7bcea3aaf2 to your computer and use it in GitHub Desktop.
Twitter Alt-Text to Title-Text
// ==UserScript==
// @name Twitter Alt-Text to Title-Text
// @description Copy the alt attribute of twitter images into the title attribute, so that I can see the alt text on hover.
// @version 1
// @grant none
// @include https://twitter.com/*
// ==/UserScript==
const SELECTORS =
` .tweet .AdaptiveMedia-photoContainer img
, .Gallery-media img
, img:not([src*="/profile_images/"])
`;
function copyAltToTitle(elt) {
if (elt.alt && !elt.title && elt.alt != 'Image') {
console.log(`Copying alt text to title text ${elt.alt}`);
elt.title = elt.alt;
}
}
function copyAll() {
document
.querySelectorAll(SELECTORS)
.forEach(copyAltToTitle);
}
copyAll();
setInterval(copyAll, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment