-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
29 lines (29 loc) · 950 Bytes
/
main.js
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
const params = new URLSearchParams(document.location.search);
if (params.has("path")) {
let path = params.get("path");
let lang;
if (params.has("lang")) {
lang = params.get("lang");
} else {
lang = "en";
}
// Get HTML and metadata for article on English Wikipedia
let base = "https://api.wikimedia.org/core/v1/wikipedia/";
let url = base + lang + "/page/" + path + "/with_html";
fetch(url)
.then((res) => {
return res.json();
})
.then((res) => {
html = res.html
.replaceAll("/n", "<br>")
.replaceAll("wikipedia.org", "credipedia.org");
document.getElementById("content").innerHTML = res.html;
document.getElementById("title").innerText = res.title;
console.log(res);
document.querySelectorAll('[href*="wikipedia.org"]').forEach((link) => {
link.href = link.href.replace("wikipedia.org", "credipedia.org");
});
})
.catch(console.error);
}