User:Nixinova/version-autocorrect.js

(function {

var heading = $('#firstHeading').html;

var javaAlphaVers = { 'a1.0': [ 'v1.0.0', 'v1.0.1', 'v1.0.1_01', 'v1.0.2', 'v1.0.2_01', 'v1.0.2_02', 'v1.0.3', 'v1.0.4', 'v1.0.5', 'v1.0.5_01', 'v1.0.6', 'v1.0.6_01', 'v1.0.6_02', 'v1.0.6_03', 'v1.0.7', 'v1.0.8', 'v1.0.8_01', 'v1.0.9', 'v1.0.10', 'v1.0.11', 'v1.0.12', 'v1.0.13', 'v1.0.13_01', 'v1.0.14', 'v1.0.15', 'v1.0.16', 'v1.0.16_01', 'v1.0.16_02', 'v1.0.17', 'v1.0.17_01', 'v1.0.17_02', 'v1.0.17_03', 'v1.0.17_04' ],       'a1.1': ['v1.1.0', 'v1.1.1', 'v1.1.2', 'v1.1.2 01'], 'a1.2': [ 'v1.2.0', 'v1.2.0-preview', 'v1.2.0_01', 'v1.2.0_02', 'v1.2.1', 'v1.2.1_01', 'v1.2.2', 'v1.2.2a', 'v1.2.2b', 'v1.2.3', 'v1.2.3_01', 'v1.2.3_02', 'v1.2.3_04', 'v1.2.3_05', 'v1.2.4_01', 'v1.2.5', 'v1.2.6' ]   };    var javaVers = { '1.0': ['1.0.0'],       '1.1': ['1.1'],        '1.2': ['1.2', '1.2.1', '1.2.2', '1.2.3', '1.2.4', '1.2.5'],        '1.3': ['1.3', '1.3.1', '1.3.2'],        '1.4': ['1.4', '1.4.1', '1.4.2', '1.4.3', '1.4.4', '1.4.5', '1.4.6', '1.4.7'],        '1.5': ['1.5', '1.5.1', '1.5.2'],        '1.6': ['1.6', '1.6.1', '1.6.2', '1.6.3', '1.6.4'],        '1.7': ['1.7', '1.7.1', '1.7.2', '1.7.3', '1.7.4', '1.7.5', '1.7.6', '1.7.7', '1.7.8', '1.7.9', '1.7.10'],        '1.8': ['1.8', '1.8.1', '1.8.2', '1.8.3', '1.8.4', '1.8.5', '1.8.6', '1.8.7', '1.8.8', '1.8.9'],        '1.9': ['1.9', '1.9.1', '1.9.2', '1.9.3', '1.9.4'],        '1.10': ['1.10', '1.10.1', '1.10.2'],        '1.11': ['1.11', '1.11.1', '1.11.2'],        '1.12': ['1.12', '1.12.1', '1.12.2'],        '1.13': ['1.13', '1.13.1', '1.13.2'],        '1.14': ['1.14', '1.14.1', '1.14.2', '1.14.3']    };    var finalJavaVers = [ '1.0.0', '1.1', '1.2.5', '1.3.2', '1.4.7', '1.5.2', '1.6.4', '1.7.10', '1.8.9', '1.9.4',       '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.3'    ];

var bedrockVers = { '1.0': [           '1.0.0.0', '1.0.0.1', '1.0.0', '1.0.1', '1.0.2', '1.0.3', '1.0.4', '1.0.5', '1.0.6', '1.0.7', '1.0.0', '1.0.9'        ],        '1.1': [            '1.1.0.0', '1.1.0.1', '1.1.0.3', '1.1.0.4', '1.1.0.5', '1.1.0.8', '1.1.0.9', '1.1.1.0', '1.1.1.1', '1.1.3.0', '1.1.3.1',            '1.1.0', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5', '1.1.7'        ],        '1.2': [            '1.2.0.2', '1.2.0.7', '1.2.0.9', '1.2.0.11', '1.2.0.15', '1.2.0.18', '1.2.0.22', '1.2.0.25', '1.2.0.31', // 1.2.0 betas '1.2.10.1', '1.2.13.5', '1.2.13.6', // 1.2.x betas '1.2.0', '1.2.1', '1.2.2', '1.2.3', '1.2.5', '1.2.6', '1.2.6.1', '1.2.7', '1.2.8', '1.2.9', '1.2.10', // 1.2.x           '1.2.11', '1.2.13', '1.2.14', '1.2.15', '1.2.16', // 1.2.x cont '1.2.13.8', '1.2.13.10', '1.2.13.11', '1.2.13.12', '1.2.14.2', '1.2.14.3', '1.2.20.1', '1.2.20.2' // 1.4.0 betas ],       '1.4': ['1.4.0', '1.4.1', '1.4.2', '1.4.3', '1.4.4'],        '1.5': ['1.5.0', '1.5.1', '1.5.2', '1.5.3'],        '1.6': ['1.6.0', '1.6.1', '1.6.2'],        '1.7': ['1.7.0', '1.7.1'],        '1.8': ['1.8.0', '1.8.1'],        '1.9': ['1.9.0'],        '1.10': ['1.10.0', '1.10.1',],        '1.11': ['1.11.0', '1.11.1', '1.11.2', '1.11.3', '1.11.4'],        '1.12': ['1.12.0'],    };    var finalBedrockVers = [ '1.0.9', '1.1.7', '1.2.16', '', '1.4.4', '1.5.3', '1.6.2', '1.7.1', '1.8.1', '1.9.0',       '1.10.1', '1.11.4', '1.12.0', '1.13.0'    ];

var version = heading.split(" ").pop var edition; if (heading.includes('Java')) edition = 'Java'; if (heading.includes('Bedrock')) edition = 'Bedrock';

var javaVersionIndex = Object.values(javaVers).indexOf(version); var bedrockVersionIndex = Object.values(bedrockVers).indexOf(version); var versionParts = version.split('.'); var versionSuffix = (edition === 'Bedrock' ? '.0' : '');

var nextVer = parseInt(versionParts[1]) + 1; var mainVersion = versionParts[0] + '.' + versionParts[1];

var prevParent = `${mainVersion + versionSuffix}`; var prevJava = `${finalJavaVers[versionParts[1]]}`; var prevBedrock = `${finalBedrockVers[versionParts[1]]}`; var next = `${versionParts[0] + '.' + nextVer}`; var javaAlpha = `Alpha ${version}`; var javaBeta = `Beta ${version}`;

var prev = ''; if (edition === 'Java') prev = prevJava; if (edition === 'Bedrock') prev = prevBedrock;

var alphaOutput = edition === 'Java' && Object.values(javaVers).indexOf(version.replace('v', 'a')) ? ", " + javaAlpha : ''; //

var versionsOutput = prevParent + (prev ? `, ${prev}` : '') + `, or ${next}`;

var defaultText = `Otherwise, you can search for this page title in other pages, search the related logs, or create this page</a>.`

if (edition && (javaVersionIndex == -1 || bedrockVersionIndex == -1)) { $('#mw-content-text .noarticletext p').html(`This version does not exist. Did you mean ${versionsOutput}? ${defaultText}`); };

});