Web/actaddmanual/index.js

74 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-02-23 17:13:23 +01:00
const replacements = new Map();
replacements.set(/<imp>([^<]*)<r>/g, function (content) {
return `<span class="imp">${content}</span>`
});
replacements.set(/<item>([^<]*)<r>/g, function (content) {
return `<span class="item">${content}</span>`
});
replacements.set(/<n>/g, function (_content) {
return "<br>"
});
replacements.set(/<i>([^<]*)<r>/g, function (content) {
return `<em>${content}</em>`
});
replacements.set(/<tifisgrin>([^<]*)<r>/g, function (content) {
return `<span class="tifisgrin">${content}</span>`
});
$.ajax({
url: "https://gitcdn.xyz/repo/Ellpeck/ActuallyAdditions/main/src/main/resources/assets/actuallyadditions/lang/en_US.lang",
2020-02-23 17:13:23 +01:00
cache: false,
success: populateManual
});
function populateManual(lang) {
let startIndex = lang.indexOf("#Booklet Chapters");
let data = lang.substring(startIndex + 18);
let entries = $("#entries");
let sidebar = $("#sidebar");
for (let topic of data.split("\n\n")) {
let lines = topic.split("\n");
let t = '<div class="entry rounded">';
// first line is name
let name = lines[0].substring(lines[0].indexOf("=") + 1);
let id = lines[0].match(/chapter\.([^\.]*)\.name/)[1];
sidebar.append(`<a href=#${id}>${name}</a>`);
t += `<a class="anchor" id="${id}"></a>`;
t += `<h1>${name}</h1>`;
// following lines are content
for (let i = 1; i < lines.length; i++) {
let text = lines[i].substring(lines[i].indexOf("=") + 1);
t += `<p>${replaceFormatting(text)}</p>`;
}
t += "</div>";
entries.append(t);
}
sidebar.append("<hr>");
sidebar.append(`<a href="https://ellpeck.de">Main Site</a>`)
sidebar.append(`<a href="https://ellpeck.de/impressum">Impressum</a>`);
2020-04-02 21:54:20 +02:00
sidebar.append(`<a href="https://ellpeck.de/privacy">Privacy</a>`);
2020-09-06 18:09:25 +02:00
sidebar.append(`<a href="https://git.ellpeck.de/Ellpeck/Web">&copy; Ellpeck</a>`);
sidebar.append("<hr>");
2020-02-23 17:13:23 +01:00
// Move to anchor now that it's loaded
if (window.location.hash.startsWith("#")) {
var anchor = $(window.location.hash);
if (anchor.length) {
$('html, body').animate({
scrollTop: anchor.offset().top
}, 0);
}
}
}
function replaceFormatting(text) {
for (let [k, v] of replacements.entries()) {
text = text.replace(k, function (_substring, group) {
return v(group);
});
}
return text;
}