User:Mike Dillon/Scripts/ancientGreekSortKey.js

function createAncientGreekSortKey(input, maintainCase) { if (!input) return input;

var map = { 'α': /[ἀἁἂἃἄἅἆἇὰάᾰᾱᾶ]/g, 'Α': /[ἈἉἊἋἌἍἎἏᾸᾹᾺΆ]/g, 'ε': /[ἐἑἒἓἔἕὲέ]/g, 'Ε': /[ἘἙἚἛἜἝῈΈ]/g, 'η': /[ἠἡἢἣἤἥἦἧὴήῆ]/g, 'Η': /[ἨἩἪἫἬἭἮἯῊΉ]/g, 'ι': /[ἰἱἲἳἴἵἶἷὶίῐῑῒΐῖῗι]/g, 'Ι': /[ἸἹἺἻἼἽἾἿῘῙῚΊΪ]/g, 'ο': /[ὀὁὂὃὄὅὸό]/g, 'Ο': /[ὈὉὊὋὌὍῸΌ]/g, 'υ': /[ὐὑὒὓὔὕὖὗὺύῠῡῢΰῦῧ]/g, 'Υ': /[ὙὛὝὟῨῩῪΎΫ]/g, 'ω': /[ὠὡὢὣὤὥὦὧὼώῶ]/g, 'Ω': /[ὨὩὪὫὬὭὮὯῺΏ]/g, 'ρ': /[ῥῤ]/g, 'Ρ': /[Ῥ]/g, /* 'σ': /ς/g, */ 'αι': /[ᾀᾁᾂᾃᾄᾅᾆᾇᾲᾳᾴᾷ]/g, 'Αι': /[ᾈᾉᾊᾋᾌᾍᾎᾏᾼ]/g, 'ηι': /[ᾐᾑᾒᾓᾔᾕᾖᾗῂῃῄῇ]/g, 'Ηι': /[ᾘᾙᾚᾛᾜᾝᾞᾟῌ]/g, 'ωι': /[ᾠᾡᾢᾣᾤᾥᾦᾧῲῳῴῷ]/g, 'Ωι': /[ᾨᾩᾪᾫᾬᾭᾮᾯῼ]/g, '': /´῾`΅῭῟῞῝῏῎῍῁῀᾿᾽/g };

var output = input; if (!maintainCase) output = output.toLowerCase; for (var k in map) { output = output.replace(map[k], k); }   return output; }

// Only add onload hook if the page name contains at least one Greek character if ((wgAction == "edit" || wgAction == "submit")   && wgPageName.match(/[\u0370-\u03E1\u03F0-\u03FF\u1F00-\u1FFF]/)) {

addOnloadHook(function {        // Case sensitive        var li = mw.util.addPortletLink('p-tb', '#', 'Greek sort key', 't-grc-sort', 'Create Ancient Greek sort key from page title');       li.getElementsByTagName("a")[0].onclick = function  {            insertTags(createAncientGreekSortKey(wgPageName), , );            return false;        };

// Case sensitive var li = mw.util.addPortletLink('p-tb', '#',           'Greek sort key (case-sensitive)',            't-grc-sort-nofold',            'Create Ancient Greek sort key from page title (maintain case)'); li.getElementsByTagName("a")[0].onclick = function { insertTags(createAncientGreekSortKey(wgPageName, true), , ); return false; };   }); }