Snippets
INFO
If you are creating a highly specific snippet that only benefits a small group of users (e.g. for your school), consider making it a user snippet instead. Please see the user snippets documentation for more information.
First, you will need the following:
| Field | Type | Description | Example |
|---|---|---|---|
name | string | The name of your snippet in Title Case | Scroll Segments |
nameCamelCase | string | The name of your snippet in camelCase | scrollSegments |
description | string | A brief description of what your snippet does | Segments the Schoolbox page into scrollable segments. |
Throughout this guide, you will see these between <angle brackets>. Replace them with the appropriate values.
Creating a Snippet
Boilerplate
Append your snippet to the
snippetConfigrecord insrc/utils/storage/snippets.tstsexport const snippetConfig: Record<string, Types.snippetConfig> = { // ... <nameCamelCase>: { name: "<name>", description: "<description>", default: true, // whether your snippet should be enabled by default }, // ... }Create your snippet function in
src/entrypoints/snippets- If you are planning to include assets alongside your CSS:
- Create a new directory in
src/entrypoints/snippetscalled<nameCamelCase> - Inside this folder, you can create a
index.cssfile for your styles, and any other files you need (e.g.icon.png)
- Create a new directory in
- If you do not need to include any assets:
- Create a new file in
src/entrypoints/snippetscalled<nameCamelCase>.css
- Create a new file in
- If you are planning to include assets alongside your CSS:
Import your snippet in
src/entrypoints/snippets.content.tsts// ... import <nameCamelCase> from "./snippets/<nameCamelCase>.css?inline"; export default defineContentScript({ matches: ["<all_urls>"], runAt: "document_start", excludeMatches: EXCLUDE_MATCHES, async main() { // ... defineSnippet("<nameCamelCase>", <nameCamelCase>); }, });
Code!
Now you can simply modify the CSS file you created with your desired styles. Please see the themes documentation for details of how to use the theme variables in your snippet.
For example:
css
/* e.g. change all headings to accent colour */
h1 {
color: hsl(var(--ctp-accent)) !important;
}