User:Anterdc99/global.js

// Content of Global JS on Fandom // HydraRevived mw.loader.load('https://dev.fandom.com/wiki/MediaWiki:HydraRevived.js?action=raw&ctype=text/javascript'); // InPageEdit mw.loader.load('https://cdn.jsdelivr.net/npm/mediawiki-inpageedit'); // Wikiplus // mw.loader.load('https://wikiplus-app.com/Main.min.js');

'use strict'; const i18n = { pageName: 'Minecraft_Wiki:Java_Edition_version_list',
 * (function(mw) {

version: '版本号', type: '类型', time: '时间', released: '首次发布', modified: '最后修改', url: 'JSON', info: '文件', load: '加载', assets: '资源索引', client: '客户端jar', server: '服务端jar', client_mappings: '客户端混淆映射表', server_mappings: '服务端混淆映射表', loading: '加载中……', loadingFailed: '加载版本信息失败. ',		loadingError: '加载版本信息时发生错误. ',		copy: '复制哈希值' },	config = mw.config.get(['wgPageName', 'wgArticlePath']), versionTable = document.createElement('table');

if ( config.wgPageName !== i18n.pageName ) return;

function initTable { versionTable.classList.add('article-table'); versionTable.innerHTML = ' ' +				' ' + i18n.version + ' ' + ' ' + i18n.type + ' ' + ' ' + i18n.time + ' ' + ' ' + i18n.url + ' ' + ' ' + i18n.info + ' ' + ' ' +			' ';		return versionTable.tBodies[0]; }

function copyBtn(text) { const button = document.createElement('span'); button.style.cursor = 'pointer'; button.title = i18n.copy; button.classList.add('icon-link'); button.addEventListener('click', function {			navigator.clipboard.writeText(text);		}); return button; }

function addInfo(srcElement, data) { srcElement.innerHTML = ' ' + i18n.assets + ' '; srcElement.firstChild.appendChild(copyBtn(data.assetIndex.sha1));

const downloads = data.downloads, keys = Object.keys(downloads);

for (var i=0; i<keys.length; i++) { srcElement.appendChild(document.createElement('br'));

const ele = document.createElement('a'); ele.href = downloads[keys[i]].url; ele.textContent = i18n[keys[i]];

const entry = document.createElement('span'); entry.appendChild(ele); entry.appendChild(copyBtn(downloads[keys[i]].sha1));

srcElement.appendChild(entry); }	}

function loadInfo(element) { const srcElement = element.srcElement; srcElement.classList = ''; srcElement.textContent = i18n.loading;

fetch(srcElement.dataset.versionurl).then(function(response) {			return response.json;		}).then(function(data) {			addInfo(srcElement.parentElement, data);		}).catch(function(error) {			srcElement.innerHTML = i18n.loadingFailed;			console.error('[Versionlist]', error);		}); }

function addRow(data) { const row = document.createElement('tr'); row.innerHTML = ' ' + data.id + ' ' + ' ' + data.type + ' ' + ' ' + i18n.released + '：' + data.releaseTime + ' ' + i18n.modified + '：' + data.time + ' ' + ' ' + data.id + '.json ' + ' ' + i18n.load + ' '; row.children[3].append(copyBtn(data.url.substr(43, 40))); row.children[4].firstChild.addEventListener('click', loadInfo); return row; }

document.getElementsByClassName('list_versions_form')[0].style.display = ''; document.getElementsByClassName('list_versions_disabled')[0].style.display = 'none';

fetch('https://piston-meta.mojang.com/mc/game/version_manifest.json').then(function(response) {		return response.json;	}).then(function(data) {		const versions = data.versions,		tbody = initTable;

for (var i=0; i<versions.length; i++) { tbody.append(addRow(versions[i])); }

document.getElementsByClassName('list_versions_loading')[0].style.display = 'none'; document.getElementsByClassName('list_versions_list')[0].appendChild(versionTable); }).catch(function(error) { document.getElementsByClassName('list_versions_loading')[0].style.display = 'none'; document.getElementsByClassName('list_versions_list')[0].innerHTML = i18n.loadingError; console.error('[Versionlist]', error); }); })(window.mediaWiki);