Польꙃєватєл҄ь:Некто участник/common.js: Difference between revisions
Видъ
Content deleted Content added
No edit summary |
No edit summary мѣтъка: Reverted |
||
глава 1: | глава 1: | ||
⚫ | |||
/********************************************************* |
|||
Old Church Slavic Wikipedia transliterator |
|||
Early Cyrillic to Glagolitic convertion |
|||
* Deals with the following orthographies: gw, ȝƿ, runes * |
|||
Based on Old English Wikipedia transliterator by PiRSquared17 |
|||
* Created by PiRSquared17 * |
|||
(https://ang.wikipedia.org/wiki/User:PiRSquared17/spellingstyle.js GFDL / CC-BY-SA 3.0) |
|||
* Please report bugs on talk page or village pump * |
|||
⚫ | |||
* Currently supports: "gw", "ȝƿ", and "runes" * |
|||
*********************************************************/ |
|||
/** |
/** |
||
глава 174: | глава 173: | ||
* @returns converted version of inputhtml |
* @returns converted version of inputhtml |
||
*/ |
*/ |
||
function convertStyle(inputhtml, inputstyle, outputstyle) { |
|||
var temp = inputhtml; |
|||
if (inputstyle == outputstyle) return inputhtml; |
|||
if (inputstyle != "runes" && outputstyle != "runes") { |
|||
if (outputstyle == "yoghwynn") { |
|||
temp = myReplace(temp, /[Ᵹ]/g, 'Ȝ'); |
|||
temp = myReplace(temp, /[gᵹ]/g, 'ȝ'); |
|||
temp = myReplace(temp, /W/g, 'Ƿ'); |
|||
temp = myReplace(temp, /w/g, 'ƿ'); |
|||
} else if (outputstyle == "gw") { |
|||
temp = myReplace(temp, /[ȜꝽ]/g, "G"); |
|||
temp = myReplace(temp, /[ȝᵹ]/g, "g"); |
|||
temp = myReplace(temp, /Ƿ/g, "W"); |
|||
temp = myReplace(temp, /ƿ/g, "w"); |
|||
} else if (outputstyle == "insularwynn") { |
|||
temp = myReplace(temp, /[Ȝ]/g, "Ᵹ"); |
|||
temp = myReplace(temp, /[gȝ]/g, "ᵹ"); |
|||
temp = myReplace(temp, /W/g, "Ƿ"); |
|||
temp = myReplace(temp, /w/g, "ƿ"); |
|||
} |
|||
} else if (inputstyle == "runes") { |
|||
for (var rune in runes) { |
|||
temp = myReplace(temp, rune, runes[rune]); |
|||
} |
|||
return convertStyle(temp, "gw", outputstyle); |
|||
} else if (outputstyle == "runes") { |
|||
temp = convertStyle(myReplace(temp,"","",1), inputstyle, "gw"); |
|||
for (var i = 0; i < rune2_exceptions.length; i++) { |
|||
temp = myReplace(temp,rune2_exceptions[i][0],rune2_exceptions[i][1]); |
|||
} |
|||
for (var latin in runes2) { |
|||
temp = myReplace(temp, latin, runes2[latin]); |
|||
} |
|||
} |
|||
return temp; |
|||
} |
|||
⚫ | |||
* Remove some accents, in an Anglo-Saxon-centric manner |
|||
* |
|||
* @param r the string |
|||
* @returns normalized version (same case, e.g., É -> E, é -> e) |
|||
⚫ | |||
function normalizeString(r){ |
|||
// from http://stackoverflow.com/questions/8186302/javascript-removing-accents , modified |
|||
// same code is found in another S.O. post |
|||
r = myReplace(r, /ċ/g , "c"); |
|||
r = myReplace(r, /Ċ/g , "C"); |
|||
r = myReplace(r, "Ġ" , "G"); |
|||
r = myReplace(r, "ġ" , "g"); |
|||
r = myReplace(r, /[àáâãäåā]/g, "a"); |
|||
r = myReplace(r, /[ÀÁÂÃÄÅĀ]/g, "A"); |
|||
r = myReplace(r, /ç/g , "s"); |
|||
r = myReplace(r, /Ç/g , "S"); |
|||
r = myReplace(r, /[èéêëē]/g , "e"); |
|||
r = myReplace(r, /[ÈÉÊËĒ]/g , "E"); |
|||
r = myReplace(r, /[ìíîïī]/g , "i"); |
|||
r = myReplace(r, /[ÌÍÎÏĪ]/g , "I"); |
|||
r = myReplace(r, /ñ/g , "n"); |
|||
r = myReplace(r, /Ñ/g , "n"); |
|||
r = myReplace(r, /[òóôõöō]/g , "o"); |
|||
r = myReplace(r, /[ÒÓÔÕÖŌ]/g , "O"); |
|||
r = myReplace(r, /[ùúûüū]/g , "u"); |
|||
r = myReplace(r, /[ÙÚÛÜŪ]/g , "U"); |
|||
r = myReplace(r, /[ýÿȳ]/g , "y"); |
|||
r = myReplace(r, /[ŸȲ]/g , "Y"); |
|||
r = myReplace(r, /ǣ/g , "æ"); |
|||
r = myReplace(r, /Ǣ/g , "Æ"); |
|||
r = myReplace(r, /Ḡ/g , "G"); |
|||
r = myReplace(r, /ḡ/g , "g"); |
|||
return r; |
|||
} |
|||
/* |
/* |
обраꙁъ отъ 18:49, сєптємврїꙗ 20 числа, 2024
/**
Old Church Slavic Wikipedia transliterator
Early Cyrillic to Glagolitic convertion
Based on Old English Wikipedia transliterator by PiRSquared17
(https://ang.wikipedia.org/wiki/User:PiRSquared17/spellingstyle.js GFDL / CC-BY-SA 3.0)
**/
/**
* 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, "gw", targetstyle);
convertStyle(contentClone, "yoghwynn", targetstyle);
convertStyle(contentClone, "insularwynn", targetstyle);
convertStyle(contentClone, "runes", 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": "runes"}, doConv);
}
// any errors? Fix them
var runes = { // rune to latin substitutions
"ⰰ": "а",
"ⰱ": "б",
"ⰲ": "в",
"ⰳ": "г",
"ⰴ": "д",
"ⰵ": "є",
"ⰶ": "ж",
"ⰷ": "ꙃ",
"ⰸ": "ꙁ",
"ⰺ": "ї",
"ⰻ": "и",
"ⰽ": "к",
"ⰾ": "л",
"ⰿ": "м",
"ⱀ": "н",
"ⱁ": "о",
"ⱂ": "п",
"ⱃ": "р",
"ⱄ": "с",
"ⱅ": "т",
"ⱆ": "оу",
"ⱇ": "ф",
"ⱈ": "х",
"ⱉ": "ѡ",
"ⱌ": "ц",
"ⱍ": "ч",
"ⱎ": "ш",
"ⱋ": "щ",
"ⱏ": "ъ",
"ⱐ": "ь",
"ⱑ": "ѣ",
"ⱓ": "ю",
"ⱔ": "ѧ",
"ⱗ": "ѩ",
"ⱘ": "ѫ",
"ⱙ": "ѭ",
"ⱚ": "ѳ",
"ⱛ": "ѵ",
};
// again, please report any errors, please include replacement for this
var runes2 = { // latin -> runes
"а": "ⰰ",
"б": "ⰱ",
"в": "ⰲ",
"г": "ⰳ",
"д": "ⰴ",
"є": "ⰵ",
"ж": "ⰶ",
"ꙃ": "ⰷ",
"ꙁ": "ⰸ",
"ї": "ⰺ",
"и": "ⰻ",
"к": "ⰽ",
"л": "ⰾ",
"м": "ⰿ",
"н": "ⱀ",
"о": "ⱁ",
"п": "ⱂ",
"р": "ⱃ",
"с": "ⱄ",
"т": "ⱅ",
"ф": "ⱇ",
"х": "ⱈ",
"ѡ": "ⱉ",
"ц": "ⱌ",
"ч": "ⱍ",
"ш": "ⱎ",
"щ": "ⱋ",
"ъ": "ⱏ",
"ꙑ": "ⱏⰻ",
"ь": "ⱐ",
"ѣ": "ⱑ",
"ю": "ⱓ",
"ꙗ": "ⱑ",
"ѥ": "ⰵ",
"ѧ": "ⱔ",
"ѩ": "ⱗ",
"ѫ": "ⱘ",
"ѭ": "ⱙ",
"ѯ": "ⰽⱄ",
"ѱ": "ⱂⱄ",
"ѳ": "ⱚ",
"ѵ": "ⱛ",
"ѷ": "ⱛ"
};
/**
* 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.
*/
rune2_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: "gw", "yoghwynn", "runes"
* @param outputstyle possible values:"gw", "yoghwynn", "runes"
* @returns converted version of inputhtml
*/
/*
* This is code to be executed when the document is ready
* Basically, add [ gw ] [ ȝƿ ] [ ᚱᚢᚾ ].
* Clicking each link converts the document to that style.
* (see doConv)
*/
$(function($) {
if ( mw.config.get( 'wgAction' ) !== 'view') {
return;
}
$("#mw-content-text").prepend($("<div class=\"center\"><small>[ <a href=\"javascript:void(0);\" class=\"click-gw\">cyrl</a> ] [ <a href=\"javascript:void(0);\" class=\"click-runes\">glag</a> ]<sup><a href=\"/wiki/Wikipedia:Stylistic_and_font_options\" title=\"Style and font help\">?</a></sup></small></div>"));
$(".click-gw").click({"outputstyle": "gw"}, doConv);
$(".click-runes").click({"outputstyle": "runes"}, doConv);
});