Skip to content

Instantly share code, notes, and snippets.

@loperd
Last active July 20, 2023 09:46
Show Gist options
  • Save loperd/8adde5037cbc6ddcbbd27446bb3eedb2 to your computer and use it in GitHub Desktop.
Save loperd/8adde5037cbc6ddcbbd27446bb3eedb2 to your computer and use it in GitHub Desktop.
wiki.vg bedrock protocol js parser
const table = document.querySelector('.mw-parser-output table');
var protocolToVersionMap = {}
let protocol;
for (const tr of table.querySelectorAll('tr')) {
const elements = tr.getElementsByTagName('td');
const version = elements[0];
if (version === undefined) {
continue
}
if (elements.length > 1) {
protocol = elements[1].innerText
}
if (!(protocol in protocolToVersionMap)) {
protocolToVersionMap[protocol] = new Array()
}
if (protocol !== undefined) {
protocolToVersionMap[protocol].push(version.innerText);
}
}
for (const [key, versions] of Object.entries(protocolToVersionMap).reverse()) {
//console.log(key, value);
const protocolKey = versions[0]
for (const version of versions) {
const line = `
[
self::EXTERNAL => BedrockServerVersion::BEDROCK_${version.replaceAll('.', '_')},
self::INTERNAL => BedrockProtocolVersion::BEDROCK_${protocolKey.replaceAll('.', '_')},
],
`;
const span = document.createElement('span');
span.innerText = line;
document.body.appendChild(span);
}
}
const table = document.querySelector('.mw-parser-output table');
var protocolToVersionMap = {}
let protocol;
for (const tr of table.querySelectorAll('tr')) {
const elements = tr.getElementsByTagName('td');
const version = elements[0];
if (version === undefined) {
continue
}
if (elements.length > 1) {
protocol = elements[1].innerText
}
if (protocol !== undefined && !(protocol in protocolToVersionMap)) {
protocolToVersionMap[protocol] = version.innerText;
}
}
for (const [key, value] of Object.entries(protocolToVersionMap).reverse()) {
//console.log(key, value);
const line = 'case BEDROCK_' + value.replaceAll('.', '_') + ' = ' + key + ';';
const span = document.createElement('span');
span.innerText = line;
document.body.appendChild(span);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment