forked from MapComplete/MapComplete
Fix wiki downloading
This commit is contained in:
parent
41582ec6a2
commit
bac8823bda
1 changed files with 11 additions and 9 deletions
20
index.ts
20
index.ts
|
@ -74,18 +74,20 @@ if (layoutFromBase64.startsWith("wiki:")) {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
dataType: 'xml',
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
const layoutJson = data.querySelector('[id="bodyContent"]')
|
// Hacky McHackFace has been working here. This probably break in the future
|
||||||
.querySelector('[class="mw-parser-output"]')
|
const startTrigger = "<div class=\"mw-parser-output\">";
|
||||||
.children[0]
|
const start = data.indexOf(startTrigger);
|
||||||
.firstChild.textContent;
|
data = data.substr(start,
|
||||||
|
data.indexOf("<div class=\"printfooter\">") - start)
|
||||||
|
data = data.substr(0, data.lastIndexOf("</p>"))
|
||||||
|
data = data.substr(startTrigger.length + 3);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log("DOWNLOADED:",layoutJson);
|
const parsed = JSON.parse(data);
|
||||||
const parsed = JSON.parse(layoutJson);
|
|
||||||
parsed["id"] = layoutFromBase64
|
parsed["id"] = layoutFromBase64
|
||||||
const layout =new LayoutConfig(parsed);
|
const layout = new LayoutConfig(parsed);
|
||||||
InitUiElements.InitAll(layout, layoutFromBase64, testing, layoutFromBase64, btoa(layoutJson));
|
InitUiElements.InitAll(layout, layoutFromBase64, testing, layoutFromBase64, btoa(data));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
new FixedUiElement(`<a href="${cleanUrl}">${themeName}</a> is invalid:<br/>${e}`)
|
new FixedUiElement(`<a href="${cleanUrl}">${themeName}</a> is invalid:<br/>${e}`)
|
||||||
.SetClass("clickable")
|
.SetClass("clickable")
|
||||||
|
|
Loading…
Add table
Reference in a new issue