MediaWiki:Common.js: Difference between revisions

From ZAMN Hacking
Content added Content deleted
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */

function runUntilSuccess(f) {
(function run() {
if (!f()) {
setTimeout(run, 10);
}
})();
}


// Extra functionality for RAM/ROM maps
// Extra functionality for RAM/ROM maps


// Sort table by the first column
// Sort table by the first column
function trySort() {
runUntilSuccess(function() {
var rerun = false;
var tables = document.getElementsByClassName("ram_rom_map");
var tables = document.getElementsByClassName("ram_rom_map");
for (var i = 0; i < tables.length; i++) {
for (var i = 0; i < tables.length; i++) {
Line 17: Line 23:
}
}
} else {
} else {
rerun = true;
return false;
}
}
}
}
return true;
});
if (rerun) {
setTimeout(trySort, 10);
}
}
setTimeout(trySort, 10);


// Add the ending address to the length column
// Add the ending address to the length column

Revision as of 22:27, 11 April 2024

/* Any JavaScript here will be loaded for all users on every page load. */

function runUntilSuccess(f) {
	(function run() {
		if (!f()) {
			setTimeout(run, 10);
		}
	})();
}

// Extra functionality for RAM/ROM maps

// Sort table by the first column
runUntilSuccess(function() {
	var tables = document.getElementsByClassName("ram_rom_map");
	for (var i = 0; i < tables.length; i++) {
		var table = tables[i];
		
		var header = table.getElementsByTagName("th")[0];
		if (header.classList.contains("headerSort")) {
			if (!header.classList.contains("headerSortUp")) {
				header.click();
			}
		} else {
			return false;
		}
	}
	return true;
});

// Add the ending address to the length column
$(function() {
	var tables = document.getElementsByClassName("ram_rom_map");
	for (var i = 0; i < tables.length; i++) {
		var table = tables[i];
		
		var rows = table.getElementsByTagName("tbody")[0].children;
		for (var j = 0; j < rows.length; j++) {
			var row = rows[j];
			var address = row.children[0].innerText;
			var length = parseInt(row.children[1].innerText);
			var endAddress = address.substr(0, 4) + (parseInt(address.substr(4, 4), 16) + length).toString(16).padStart(4, "0").toUpperCase();
			row.children[1].title = "[" + address + ", " + endAddress + ")";
		}
	}
});