Skip to content

Creating a module for a website

Yuuto edited this page Aug 31, 2023 · 1 revision

Creating your module

First, create a new file in the src/websites/ folder. The file name must be the domain name (e.g. "accounts.spotify.com" → "spotify.js"). Now that you created the file, let's create the module!

So first of all, you need to put module.exports = {};. Inside this object you'll need to set a few keys.

Setting up the module

The module needs to be setup inside the module.exports object, with a few keys:

  • webPattern: a regex of the domain(s) name(s) of the website you want to target.

  • urlsMatches: an array of { path: string | RegExp | (string | RegExp)[]; run: () => void } object.

    path is a string, RegExp, or array of strings/RegExps. It must start with a /, as this is used to match paths.

    Note: query string are ignored

    run is a function (which can be async). It is executed every time the user visits the specified path.

  • selectors: an object of keys, which are used to store DOM selectors. Example:

    module.exports = {
      // ...
      selectors: {
        emailInput: 'input.my-input'
      }
    };

    You can use those selectors in your code using this.getSelector('emailInput') (replacing emailInput by your key).

Init your module

Open the src/content-script/index.js, import your module and init it:

const website = require('../websites/website');

// ...
Util.Website.init(website);

Building the extension code

Just run yarn build in a terminal. To automatically rebuild the code every time you make a change use yarn watch.