Last active
July 20, 2023 09:46
-
-
Save loperd/8adde5037cbc6ddcbbd27446bb3eedb2 to your computer and use it in GitHub Desktop.
wiki.vg bedrock protocol js parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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