Skip to content

Commit

Permalink
webext: Documentation - refs #292
Browse files Browse the repository at this point in the history
  • Loading branch information
notabene committed Jan 17, 2018
1 parent cd165df commit 668e2dd
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions webextension/scripts/documentation.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Scripts documentation

## File organisation

The scripts are in webextension/scripts and are organised as follows:

````
```
scripts Main folder for scripts
|
|-* constants.js Constants for browsers
Expand All @@ -11,12 +13,30 @@ scripts Main folder for scripts
|-* utils.js What it says on the cover: utilities
|-* [all other JS] One script per functionality
|
|-- injected Scripts that must be injected in the page to add behaviour in the page
|-- injected Content scripts
```

So, for instance:

1. Once the popup is shown, we click on “Check alts”
2. `checkalts.js` is triggered
3. `injected/checkalts.js` is injected into the page
## API between the extension and the pages

Each script that needs to execute a content script has to call it that way:

```javascript
browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
browser.tabs.sendMessage(tabs[0].id, {
a11ycss_action: "checkalts",
// [… other parameters …]
});

});
```

For instance this will be listened to by the injected content script checkalts.js, which will react accordingly:

```javascript
browser.runtime.onMessage.addListener((message) => {
if (message.a11ycss_action && message.a11ycss_action === "checkalts") {
// this is where the actions are going to be called
}
});
```

0 comments on commit 668e2dd

Please sign in to comment.