alt_expand for Old TweetDeck

旧TweetDeckでTL上にALTテキストを展開するやつ

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         alt_expand for Old TweetDeck
// @namespace    https://twitter.com/@7vU6jrZRuX2ffkY
// @version      0.1
// @description  旧TweetDeckでTL上にALTテキストを展開するやつ
// @author       @7vU6jrZRuX2ffkY
// @match        https://twitter.com/i/tweetdeck
// @grant        none
// @license      MIT
// ==/UserScript==
 
(() => {
  const observer = new MutationObserver(m => {
    m.forEach(mm => {
      mm.addedNodes.forEach(e => {
        if (e.classList && e.classList.contains("js-stream-item")) {
          addAltText1(e.querySelector("div.js-media.media-preview:has(a.js-media-image-link[title]:not([title='']))"));
          addAltText2(e.querySelector("div.js-media.media-preview:has(a.js-media-image-link img[alt]:not([alt=''])"));
        }
      });
    });
  });
 
  const addAltText1 = ele => {
    ele && ele.insertAdjacentHTML("afterend", "<p style='white-space:pre-wrap;padding-top:1em'>" + ele.querySelector("a[title]").title + "</p>")
  };
 
  const addAltText2 = ele => {
    ele && ele.insertAdjacentHTML("afterend", "<p style='white-space:pre-wrap;padding-top:1em'>" + ele.querySelector("img[alt]").alt + "</p>")
  };
 
  const waitForLoadCompletion = () => {
    const t1 = document.querySelector("div.js-app-columns");
    const t2 = document.querySelector("div#open-modal");
    if (t1 && t2) {
      observer.observe(t1, {
        childList: true,
        subtree: true,
        characterData: true
      });
      observer.observe(t2, {
        childList: true,
        subtree: true,
        characterData: true
      });
    } else {
      setTimeout(waitForLoadCompletion, 500);
    }
  };
 
  waitForLoadCompletion();
})();