blob: d59f608d1a418293f14332e68b78114cb1d7afa4 (
plain) (
blame)
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
|
import React from 'dom-chef';
import * as pageDetect from 'github-url-detection';
import features from '../feature-manager.js';
import observe from '../helpers/selector-observer.js';
const isSingleHTMLFile = (): boolean => pageDetect.isSingleFile() && /\.html?$/.test(location.pathname);
function add(rawButton: HTMLAnchorElement): void {
if (!pageDetect.isPublicRepo()) {
return;
}
rawButton
.parentElement! // `BtnGroup`
.prepend(
<a
className="btn btn-sm BtnGroup-item"
// #3305
href={`https://refined-github-html-preview.kidonng.workers.dev${rawButton.pathname}`}
>
Preview
</a>,
);
}
function init(signal: AbortSignal): void {
observe('a:is(#raw-url, [data-testid="raw-button"])', add, {signal});
}
void features.add(import.meta.url, {
include: [
isSingleHTMLFile,
],
exclude: [
pageDetect.isEnterprise,
],
init,
});
|