-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
256 lines (238 loc) · 8.81 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Page Parser</title>
<meta
name="description"
content="A simple service that can parse any article into Reading Mode."
/>
<meta name="author" content="ml4den.com" />
<meta name="theme-color" content="#0d6efd" />
<meta property="og:title" content="Page Parser" />
<meta property="og:type" content="website" />
<meta property="og:url" content="" />
<meta property="og:description" content="A simple service that can parse any article into Reading Mode." />
<meta property="og:image" content="" />
<link rel="manifest" href="/manifest.json" />
<link rel="icon" href="favicon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="/favicon-opaque-192px.png" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" />
<style>
.content img {
max-width: 100%;
}
</style>
</head>
<body>
<div class="container text-center pt-3" id="statusMessage">
<div class="spinner-border" role="status"></div>
</div>
<div class="content container border-bottom">
<h1>
<span id="title"></span>
<a class="share-button" style="cursor: pointer;">
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
class="bi bi-share"
viewBox="0 0 16 16"
>
<path
d="M13.5 1a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zM11 2.5a2.5 2.5 0 1 1 .603 1.628l-6.718 3.12a2.499 2.499 0 0 1 0 1.504l6.718 3.12a2.5 2.5 0 1 1-.488.876l-6.718-3.12a2.5 2.5 0 1 1 0-3.256l6.718-3.12A2.5 2.5 0 0 1 11 2.5zm-8.5 4a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm11 5.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z"
></path>
</svg>
</a>
</h1>
<p><span id="datee"></span></p>
<p class="content">
Published <span id="date"></span>
<span class="domain"
>on <a id="source" href="#"><span id="domain"></span></a
></span>
</p>
<blockquote class="lead" id="excerpt"></blockquote>
<img id="image" src="" />
<article id="content"></article>
</div>
<div class="container">
<section class="py-4 py-xl-5 container">
<div class="row mb-2">
<div class="col-md-8 col-xl-6 text-center mx-auto">
<h2 class="display-6 fw-bold">Page Parser</h2>
<p class="text-muted">
Paste a link to an article that you would like to convert to
reading mode below or drag this bookmarklet to your browser
favourites:
<a
href="javascript:(function()%7Bwindow.open('https%3A%2F%2Fread.ml4den.com%3Furl%3D'%20%2B%20document.URL%2C%20'_blank')%3B%7D)()%3B"
>Read</a
>
</p>
</div>
</div>
<form class="d-flex justify-content-center flex-wrap">
<div class="mb-3">
<input
class="form-control"
type="search"
name="url"
placeholder="URL"
id="url"
/>
</div>
<div class="mb-3">
<button
class="btn btn-primary ms-2"
onclick="location.href='?url=' + document.getElementById('url').value"
type="button"
>
Read
</button>
</div>
<div class="mb-3">
<button class="btn btn-info ms-2 install">Install</button>
</div>
</form>
</section>
</div>
<script>
document.getElementsByClassName("content")[0].style.display = "none";
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const url = (function () {
if (
urlParams.has("url") &&
urlParams.get("url") !== "" &&
location.protocol === "file:"
)
return (
"https://mercury-express.ml4den.repl.co/parse?url=" +
urlParams.get("url")
);
else if (urlParams.has("url") && urlParams.get("url") !== "")
return "/api?url=" + urlParams.get("url");
else if (urlParams.has("text") && urlParams.get("text") !== "")
return "/api?url=" + urlParams.get("text");
return null;
})();
function handleErrors(response) {
if (!response.ok) {
document.getElementById("statusMessage").innerHTML =
response.statusText;
throw Error(response.statusText);
}
return response;
}
if (url !== null) {
fetch(url)
.then(handleErrors)
.then(function (response) {
return response.json();
})
.then(function (jsonResponse) {
// do something with jsonResponse
document.getElementById("statusMessage").style.display = "none";
if (!jsonResponse.error) {
document.getElementsByClassName("content")[0].style.display =
"block";
}
if (jsonResponse.title) {
document.getElementById("title").innerHTML = jsonResponse.title;
}
if (jsonResponse.date_published) {
document.getElementById("date").innerHTML = new Date(
jsonResponse.date_published
).toDateString();
}
if (jsonResponse.url) {
document.getElementById("source").href = jsonResponse.url;
}
if (jsonResponse.domain) {
document.getElementById("domain").innerHTML = jsonResponse.domain;
}
if (jsonResponse.excerpt) {
document.getElementById("excerpt").innerHTML =
jsonResponse.excerpt;
}
if (jsonResponse.lead_image_url) {
document.getElementById("image").src =
jsonResponse.lead_image_url;
}
if (jsonResponse.content) {
document.getElementById("content").innerHTML =
jsonResponse.content;
}
document
.querySelector(".share-button")
.addEventListener("click", (event) => {
if (navigator.share) {
navigator
.share({
//title: jsonResponse.title,
url: window.location.href,
text: jsonResponse.title
})
.then(() => {
console.log("Thanks for sharing!");
})
.catch(console.error);
} else {
// fallback
}
});
})
.catch(function (error) {
console.log(error);
document.getElementById("statusMessage").innerHTML = error;
});
} else {
document.getElementById("statusMessage").style.display = "none";
}
// PWA
//
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("/service-worker.js")
.then(function (reg) {
console.log("Service worker registered.");
})
.catch(function (err) {
console.log("Service worker not registered. This happened:", err);
});
}
let deferredPrompt;
const addBtn = document.querySelector(".install");
addBtn.style.display = "none";
window.addEventListener("beforeinstallprompt", (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
// Update UI to notify the user they can add to home screen
addBtn.style.display = "block";
addBtn.addEventListener("click", (e) => {
// hide our user interface that shows our A2HS button
addBtn.style.display = "none";
// Show the prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === "accepted") {
console.log("User accepted the A2HS prompt");
} else {
console.log("User dismissed the A2HS prompt");
}
deferredPrompt = null;
});
});
});
</script>
</body>
</html>