This repository has been archived by the owner on May 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
130 lines (106 loc) · 3.58 KB
/
index.html
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<meta name="Description" content="Put your description here.">
<base href="/">
<title>PWABuilder - Preview component</title>
<script type="module" src="./build/manifest-previewer.js"></script>
<style type="text/css" media="screen, print">
@font-face {
font-family: 'Hind';
src: url('/assets/fonts/Hind-Regular.ttf');
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Hind';
src: url('/assets/fonts/Hind-Bold.ttf');
font-weight: 700;
font-style: bold;
font-display: swap;
}
@font-face {
font-family: 'Segoe';
src: url('/assets/fonts/SegoeUI.ttf');
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'SF-Pro';
src: url('/assets/fonts/SFProDisplay-Light.ttf');
font-weight: 400;
font-style: normal;
}
@font-face {
font-family: 'Roboto';
src: url('/assets/fonts/Roboto-Regular.ttf');
font-weight: 400;
font-style: normal;
}
manifest-previewer {
--font-family: Hind;
--windows-font-family: Segoe;
--ios-font-family: SF-Pro;
--android-font-family: Roboto;
}
manifest-previewer::part(card) {
margin: 70px auto 0;
}
</style>
</head>
<body>
<manifest-previewer>
</manifest-previewer>
<input type="url" id="url-input" placeholder="Type a URL" value="https://www.pwabuilder.com" />
<button onclick="loadPwa()">Go</button>
<p id="error-dump" style="color: darkred;"></p>
<textarea id="manifestCodeEditor" oninput="codeEditorChanged()"
style="overflow: scroll; width: 500px; height: 500px;"></textarea>
<script type="text/javascript">
const errorElement = document.querySelector("#error-dump");
const urlInput = document.querySelector("#url-input");
const manifestPreviewer = document.querySelector("manifest-previewer");
const codeEditor = document.querySelector("#manifestCodeEditor");
loadPwa();
async function loadPwa() {
// Clear any error text
errorElement.innerText = "";
// Fetch the manifest for the URL
const url = urlInput.value;
const fetchResult = await fetch(`https://pwabuilder-manifest-finder.azurewebsites.net/api/findmanifest?url=${encodeURIComponent(url)}`);
if (!fetchResult.ok) {
errorElement.innerText = `Error fetching manifest: ${fetchResult.status} - ${fetchResult.statusText}`;
return;
}
const manifestDetection = await fetchResult.json();
if (!manifestDetection.manifestContents) {
errorElement.innerText = `Error fetching manifest: ${manifestDetection.error}`;
return;
}
// Update the manifest previewer.
manifestPreviewer.siteUrl = url;
manifestPreviewer.manifestUrl = manifestDetection.manifestUrl;
manifestPreviewer.manifest = manifestDetection.manifestContents;
codeEditor.value = JSON.stringify(manifestDetection.manifestContents, undefined, 2);
}
function codeEditorChanged() {
// Is the JSON valid?
let isJsonValid = false;
let newManifest = null;
try {
newManifest = JSON.parse(codeEditor.value);
isJsonValid = true;
errorElement.innerText = "";
} catch (error) {
errorElement.innerText = `Invalid JSON: ${error}`;
return;
}
manifestPreviewer.manifest = newManifest;
}
</script>
</body>
</html>