forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.tsx
More file actions
60 lines (50 loc) · 1.87 KB
/
options.tsx
File metadata and controls
60 lines (50 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React from 'dom-chef';
import select from 'select-dom';
import linkifyUrls from 'linkify-urls';
import fitTextarea from 'fit-textarea';
import indentTextarea from 'indent-textarea';
import {applyToLink as shortenLink} from 'shorten-repo-url';
import editTextNodes from './libs/linkify-text-nodes';
import parseBackticks from './libs/parse-backticks';
import optionsStorage from './options-storage';
import {FeatureDetails} from './libs/features';
fitTextarea.watch('textarea');
indentTextarea.watch('textarea');
function parseDescription(description: string): DocumentFragment {
const descriptionFragment = parseBackticks(description);
editTextNodes(linkifyUrls, descriptionFragment);
for (const a of select.all('a', descriptionFragment)) {
shortenLink(a, location.href);
}
return descriptionFragment;
}
function buildFeatureCheckbox([name, {description, screenshot, disabled}]: [string, FeatureDetails]): HTMLElement {
// `undefined` disconnects it from the options
const id = disabled ? undefined : `feature:${name}`;
const parsedDescription = parseDescription(
(disabled ? `Disabled because of ${disabled}; \n` : '') +
description
);
return (
<p>
<input type="checkbox" name={id} id={id} disabled={Boolean(disabled)} />
<label for={id} className="info">
<span className="feature-name">{name}</span>
{' '}
<a href={`https://github.com/sindresorhus/refined-github/blob/master/source/features/${name}.tsx`}>
source
</a>
{screenshot ? <>, <a href={screenshot}>screenshot</a></> : ''}
<br/>
<span className="description">{parsedDescription}</span>
</label>
</p>
);
}
const featureCheckboxes = [...window.collectFeatures.entries()]
.sort(([a], [b]) => a.localeCompare(b)) // Sort by feature name
.map(buildFeatureCheckbox);
document
.querySelector('.js-features')!
.append(...featureCheckboxes);
optionsStorage.syncForm('#options-form');