User:BanningBotru-chi/langconvorv-glag.js

/********************************************************* * Old Russian Wikipedia transliterator                 * * Deals with the following orthographies: cyr, glag    * * Created by NR deblocked                              * * Please report bugs on talk page or village pump      * * Currently supports: "cyr" and "glag"                 * *********************************************************/

/** * Actually clone content, and transliterate * * @param event The event: event.data.outputstyle (see convertStyle args 2,3) * @returns nothing (undefined) */ function doConv(event) { if ($("#mw-content-text-clone").length) $("#mw-content-text-clone").remove; //console.log("Entered doConv, (possibly removed old clone)"); // get target style var targetstyle = event.data.outputstyle; var contentClone; $("#mw-content-text").show; contentClone = $("#mw-content-text").clone; contentClone.attr("id", "mw-content-text-clone"); convertStyle(contentClone, "glag", targetstyle); convertStyle(contentClone, "yoghwynn", targetstyle); convertStyle(contentClone, "insularwynn", targetstyle); convertStyle(contentClone, "glag", targetstyle); $("#mw-content-text").hide; contentClone.addClass("content-" + targetstyle); contentClone.insertAfter("#mw-content-text"); $(".click-gw").click({"outputstyle": "gw"}, doConv); $(".click-yoghwynn").click({"outputstyle": "yoghwynn"}, doConv); $(".click-insularwynn").click({"outputstyle": "insularwynn"}, doConv); $(".click-runes").click({"outputstyle": "glag"}, doConv); } var glag = { "Ⰰ": "А", "Ⰱ": "Б", "Ⰲ": "В" "Ⰳ": "Г", "Ⰴ": "Д", "Є": "Є", "Ⰶ": "Ж", "Ⰴⰸ": "Ѕ", "Ⰸ": "З", "Ꙁ": "Ꙁ", "Ⰹ": "И", "І": "І", "Ⰽ": "К", "Ⰾ": "Л", "Ⰿ": "М", "Ⱀ": "Н", "Ⱁ": "О", "Ⱂ": "П", "Ⱃ": "Р", "Ⱄ": "С", "Ⱅ": "Т", "ⱆ": " ꙋ", "Ⱇ": "Ф", "Ⱈ": "Х", "Ѡ": "Ѡ", "Ⱌ": "Ц", "Ⱍ": "Ч", "Ⱎ": "Ш", "Ⱋ": "Щ", "Ⱏ": "Ъ", "Ꙑ": "Ꙑ", "Ⱐ": "Ь", "Ⰵ": "Ѣ", "Ⱓ": "Ю", "Ⱝ": "Ꙗ", "Ⱝ": "Ѧ", "Ѯ": "Ѯ", "Ѱ": "Ѱ", "Ⱇ": "Ѳ", "Ⰹ": "Ѵ", };

// again, please report any errors, please include replacement for this var glag2 = { "А": "Ⰰ", "Б": "Ⰱ", "В": "Ⰲ", "Г": "Ⰳ", "Д": "Ⰴ", "Є": "Є", "Ж": "Ⰶ", "З": "Ⰸ", "Ꙁ": "Ꙁ", "И": "Ⰹ", "І": "І", "К": "Ⰽ", "Л": "Ⰾ", "М": "Ⰿ", "Н": "Ⱀ", "О": "Ⱁ", "П": "Ⱂ", "Р": "Ⱃ", "С": "Ⱄ", "Т": "Ⱅ", "ꙋ": "ⱆ", "Ф": "Ⱇ", "Х": "Ⱈ", "Ѡ": "Ѡ", "Ц": "Ⱌ", "Ч": "Ⱍ", "Ш": "Ⱎ", "Щ": "Ⱋ", "Ъ": "Ⱏ", "Ꙑ": "Ꙑ", "Ь": "Ⱐ", "Ѣ": "Ⰵ", "Ю": "Ⱓ", "Ꙗ": "Ⱝ", "Ѧ": "Ⱝ", "Ѯ": "Ѯ", "Ѱ": "Ѱ", "Ѳ": "Ⱇ" "Ѵ": "Ⰹ" };

/** * Two or more characters -> a single rune or a pattern of runes * Put here anything that should be converted from two or more gw characters to one or more rune. */ glag2_exceptions = [ [Ѕ": "Ⰴⰸ",]

];

/** * Replace occurrences of regex, possibly normalize * * For nodes (not text) input, modifies object * @param input the input text or jQuery object * @param regex the regular expression * @param replacement replacement * @param norm Normalize input? (also converts to lowercase) * @returns the converted version of input (as text/DOM node) */ var myReplace = function(input, regex, replacement, norm) { if (typeof regex == "string") regex = new RegExp(regex, "g"); if (typeof input == "string") return norm?normalizeString(input).toLowerCase:input.replace(regex,replacement); if (typeof input == "undefined") return; var node = input[0]; if (typeof node == "undefined") node = input; if (!("nodeType" in node)) return node; if (node.nodeType == 3) { if (norm) node.nodeValue = normalizeString(node.nodeValue).toLowerCase; node.nodeValue = node.nodeValue.replace(regex, replacement); } else { if ($(node).hasClass("nochange")) return node; if (!("childNodes" in node)) return node; for (var i = 0, len = node.childNodes.length; i < len; i++) myReplace($(node.childNodes[i]), regex, replacement, norm); }   return node; }

/** * Convert style of text/jQuery node from one spelling style to another * * @param inputhtml input text or jQuery node * @param inputstyle possible values: "cyr", "glag" * @param outputstyle possible values:"cyr", "glag" * @returns converted version of inputhtml */ function convertStyle(inputhtml, inputstyle, outputstyle) { var temp = inputhtml; if (inputstyle == outputstyle) return inputhtml; if (inputstyle != "glag" && outputstyle != "glag") { if (outputstyle == "cyr") { temp = myReplace(temp, /[Ᵹ]/g, 'Ȝ'); temp = myReplace(temp, /[gᵹ]/g, 'ȝ'); temp = myReplace(temp, /W/g, 'Ƿ'); temp = myReplace(temp, /w/g, 'ƿ'); } else if (outputstyle == "glag") { temp = myReplace(temp, /[ȜꝽ]/g, "G"); temp = myReplace(temp, /[ȝᵹ]/g, "g"); temp = myReplace(temp, /Ƿ/g, "W"); temp = myReplace(temp, /ƿ/g, "w"); }   } else if (inputstyle == "glag") { for (var rune in runes) { temp = myReplace(temp, glag, glag[glag]); }       return convertStyle(temp, "cyr", outputstyle); } else if (outputstyle == "glag") { temp = convertStyle(myReplace(temp,"","",1), inputstyle, "cyr"); for (var i = 0; i < glag2_exceptions.length; i++) { temp = myReplace(temp,rune2_exceptions[i][0],rune2_exceptions[i][1]); }       for (var latin in runes2) { temp = myReplace(temp, cyrillic, glag2[cyrillic]); }   }

return temp; }

}

/* * This is code to be executed when the document is ready * Basically, add [ cyr ] [ glag ]. * Clicking each link converts the document to that style. * (see doConv) */ $(function($) {   if ( mw.config.get( 'wgAction' ) !== 'view') {        return;    }

$("#mw-content-text").prepend($(" [ cyr ] [ ᚱᚢᚾ ]? ")); $(".click-gw").click({"outputstyle": "cyr"}, doConv); $(".click-runes").click({"outputstyle": "glag"}, doConv); });