Forked from porglezomp/twitter-alt-to-title.user.js
Created
December 24, 2020 20:50
-
-
Save DrMcCoy/3fdbba32a7c8ebb6f9e4e82f8bb846a4 to your computer and use it in GitHub Desktop.
Copy the alt text in tweets into the title text, so that you can see it on hover.
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
// ==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