User:Erutuon/scripts/epigraphicLatin.js

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

$(() => {
	const forEachTextNode = (func) => {
		const key = Symbol();
		const apply = node => {
			if (!(node instanceof Node)) {
				throw new TypeError("Expected Node");
			}
			for (const child of node.childNodes) {
				if (child[key])
					continue;
				switch (child.nodeType) {
					case Node.ELEMENT_NODE: apply(child); break;
					case Node.TEXT_NODE: func(child);
				}
				child[key] = true;
			}
		};
		return apply;
	};
	
	const epigraphifyLatin = forEachTextNode(textNode => {
		textNode.originalLatin = textNode.nodeValue; // a method to restore original value
		textNode.nodeValue = textNode.nodeValue
			.normalize("NFD")
			.toUpperCase()
			.replace(/I\u0304/g, "ꟾ")
			.replace(/\u0304/g, "\u0301") // macron → acute
			.normalize("NFC");
	});
	
	$(":lang(la)").get().forEach(epigraphifyLatin);
});