Manifest.json for content script

Web extensions use a manifest.json file for configuration.

First we need to set up the site to load the script for.

"content_scripts": [
  {
    "matches": ["*://*.drupal.org/*"],
    "js": ["content.js"],
    "css": ["styles.css"]
  }
],

This will load content.js and styles.css for all pages at drupal.org.

// Load the composer.json parser script.
import extensions from "./lib/composerDrupalExtensions.js";

// Loop through links and check if they go to a module page for a module that already exists in composer.json
const links = document.querySelectorAll('a');

links.forEach(link => {
    const hrefParts = link.href.split('/');
    const extension = hrefParts[hrefParts.length -1];
    if (
        extensions.require.has(extension)
        || extensions["require-dev"].has(extension)
    ) {
        link.classList.add('drupalarchitectextension--module-exists')
    }
})

With the extension running in web-ext, I can see which modules I already have in my site's composer.json.

Drupal.org web extension highlight installed modules