# <img src="public/icons/128.png" width="45" align="left"> Replayable Chrome Extension Implementation Details

## Handling Button Injection

```
[{
	"github":{
		"urls":[
			'issues/new',
			"pull/"
		],
		"elements":[{
			"type":"button",
			"text":"Submit new issue",
			"response":{
				"dom_element":{
					"dom":"#issue_body",
					"type":"value"
				}
			}
		},{
			"type":"button",
			"text":"Close pull request",
			"parent":"#partial-new-comment-form-actions",
			"response":{
				"dom_element":{
					"dom":"#new_comment_field",
					"type":"value"
				}
			}
		}],
		"html":`
			<button type="button" id="createReplay" class="replayable-button-wrapper github">
				${this.buttonHTML}
			</button>
		`
	}
}, {
	"bitbucket":{
		"urls":[
			"pull-requests/"
		],
		"elements":[{
			"type":"#portal-parent-pr-global-conversation-null",
			"response":{
				"focus_element":"#portal-parent-pr-global-conversation-null input",
				"dom_element":{
					"dom":"#portal-parent-pr-global-conversation-null .ProseMirror",
					"type":"innerHTML"
				}
			}
		}],
		"html":`
			<button type="button" id="createReplay" class="replayable-button-wrapper">
			  ${this.buttonHTML}
			</button>
		`
	}
}]

```

Each provider object must start with it's name from the url:
For example:
github.com --> github
bitbucket.org --> bitbucket

In the "urls" array, only add the end url that is unique to where you want the chrome extension to populate.
For example:
https://github.com/replayableio/chrome-extension/pull/3
The common denominator between all urls that is fixed is pull/. This helps the extension understand on what page should "public/replayable/index.js" be injected.

In the "elements" array, the extension needs to understand where it needs to add the "Attach Replay" button.
It takes the following object:

```
{
	"type": a dom element like "button", or an dom ID if "text" is not available,
	"text": text inside the dom element ,
	"parent": This is an ID of the parent of where you want the "Attach replay" button to be injected,
	"response": an object that tells the extension where to find the comment section to inject the output after they click "Attach replay",
		{
			"dom_element": {
				"dom": the dom ID of where the comment section,
				"type": "innerHTML" or "value"
			},
			"focus_element": Sometimes, we need to focus on the input to be allowed to enter the markdown response,
				This is generally an Dom ID to find the input
		}
}
```

The focus_element works before the dom_element does. focus_element find the element and focuses on it then the dom_element inserts the markdown into where you specified "dom_element.dom"

The "html" field can sometimes have a different class added to it depending on the provider but must ALWAYS include the id="createReplay" so it can work

## Install

[**Chrome** extension]() <!-- TODO: Add chrome extension link inside parenthesis -->

## Contribution

Suggestions and pull requests are welcomed!

---

This project was bootstrapped with [Chrome Extension CLI](https://github.com/dutiyesh/chrome-extension-cli)
