|
| 1 | +# Contributing |
| 2 | +Thanks to everyone who offeres to contribute to AutoMod Regex Generator, contributors help make the tool as useful as possible for everyone. Here are some tips to help for contributing: |
| 3 | + |
| 4 | +## Adding a new regex to `regexes.html` |
| 5 | +When creating a new regex, first you will need to create a HTML div for the regex in `regexes.html`. An example div looks like this: |
| 6 | +```html |
| 7 | +<div class="spam-type" id="links"> |
| 8 | + <a class="spam-name">All Links</a> |
| 9 | + <div class="grid-row"> |
| 10 | + <p>Blocks all links. You should use this with allow keywords.</p> |
| 11 | + <div class="setting"> |
| 12 | + <div class="title-with-setting"> |
| 13 | + <!-- setting ids MUST be unique between all regexes --> |
| 14 | + <input type="checkbox" id="include-nonclickable" checked> |
| 15 | + Include Non-Clickable Links |
| 16 | + </div> |
| 17 | + <p>When enabled, this will block links without the <code>https://</code> but <a class="warning-description">this can cause some false negatives.</a></p> |
| 18 | + </div> <!-- If the regex doesn't have any settings, delete between <div class="setting"> and here --> |
| 19 | + |
| 20 | + <!-- below this line, only the last part of the ids SHOULD be changed (e.g. "copy-regex-links" and "regex-output-links") --> |
| 21 | + <div class="regex-results"> |
| 22 | + <button class="copy-regex" id="copy-regex-links">Copy</button> |
| 23 | + <a class="regex-output" id="regex-output-links">h[e3]ll[o0] w[o0]rld</a> |
| 24 | + </div> |
| 25 | + </div> |
| 26 | +</div> |
| 27 | +``` |
| 28 | +You will need to change the text and give a proper title, description and setting information. Additionally, each ID needs to be changed but only the part which says links SHOULD be changed: |
| 29 | +- `links` |
| 30 | +- `copy-regex-links` |
| 31 | +- `regex-output-links` |
| 32 | +- all setting input elements MUST have a unique id. |
| 33 | + |
| 34 | +The div above should be placed as a direct child of the div with ID `spam-grid` in `regexes.html`. Then, configuration must be created in `static/regexes.js` the following Object should be placed in the list `regex_types`: |
| 35 | + |
| 36 | +```js |
| 37 | +{ |
| 38 | + name: "links", |
| 39 | + copy_btn: document.getElementById("copy-regex-links"), |
| 40 | + output: document.getElementById("regex-output-links"), |
| 41 | + generator: function(settings) { |
| 42 | + if (settings.nonclick.checked) { |
| 43 | + return `(?:https?://)?[a-z0-9_\\-\\.]*[a-z0-9_\\-]+\\.[a-z]{2,}`; |
| 44 | + } else { |
| 45 | + return `(?:https?://)[a-z0-9_\\-\\.]*[a-z0-9_\\-]+\\.[a-z]{2,}`; |
| 46 | + }; |
| 47 | + }, |
| 48 | + setting_elements: { |
| 49 | + nonclick: document.getElementById("include-nonclickable") |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +`name` should be equal to the `id` provided to the parent div in the previous step. and `copy_btn` and `output` should be the element from the div in the previous step. The `generator` function should contain the logic to generate your regex and return the regex as a string. Note that forward slashes (`\`) need to be escaped as `\\`. Elements provided in `settings_elements` is simply passed to the generator as the `settings` argument. |
| 55 | + |
| 56 | +Test that the regex is functional before opening a pull request. |
| 57 | + |
| 58 | +## Modifying a regex |
| 59 | + |
| 60 | +**Modifying the text (name, description, etc) of a regex**: The modification can be made in the html in `regexes.html`, please consider the instruction in the previous instructions. |
| 61 | +**Modifying the regex output**: Find the regex in `static/regexes.html` and modify the generator function. The `generator` function should contain the logic to generate the regex and return the regex as a string. Note that forward slashes (`\`) need to be escaped as `\\`. Elements provided in `settings_elements` is simply passed to the generator as the `settings` argument. |
| 62 | +**Adding new settings**: Consider the previous instructions on creating a new regex |
0 commit comments