Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@imborge/twitter-dom

imborge6MIT0.1.0TypeScript support: included

A content script utility for browser extension developers

chrome, firefox, twitter, contentscript, browser-extensions, extension

readme

twitter-dom

This package provides a simple way for content scripts to get the nodes containing tweets on Twitter.com.

It provides a single class StatusObserver that you instantiate with a callback function that gets called when new tweet statuses are added to the DOM.

StatusObserver has only 2 methods:

observe() and disconnect which starts and stops listening to the DOM respectively.

Installation (via NPM)

npm install @imborge/twitter-dom --save

Sample usage

Make promoted tweets have a gray background:

import { StatusObserver } from "@imborge/twitter-dom";

const observer = new StatusObserver((statusNode, statusID, username) => {
  // statusID and username is extracted from links inside
  // status wrapper elements.

  // Promoted tweets don't have links containing
  // the status id of the tweet.
  if (!statusID) {
    statusNode.style.background = "rgba(0, 0, 0, .1)";
  }
});

observer.observe();