//en LEDOKOL: Little-Effort Dictionaries Overview by Known word for One Language
//ru ЛЕДОКОЛ: ЛЕгкоДОступный Каталог Открытых Лексиконов
var langcodes; // "name":"code"
var langnames = {}; // "code":"name" (reversed langcodes)
// https://www.mediawiki.orghttps://dictious.com/en/API:Get_the_contents_of_a_page
// /w/api.php?action=parse&page=Module:languages/canonical names.json&prop=wikitext&formatversion=2
function updateStorageLangcodes( present ) {
return new mw.Api().get({
"action": "parse",
"page": "Module:languages/canonical names.json",
"prop": "wikitext",
"formatversion": 2, // omitted? data.parse.wikitext
"format": "json"
}).done( function(data) {
localStorage = present || Math.floor( Date.now() / 8.64e7 ); // avoid storing over-specific timestamp
localStorage = data.parse.wikitext.replaceAll(/\n */g,"").replaceAll(/" *: *"/g,'":"');
});
}
function displayHeaderLangcodes() {
langcodes = JSON.parse( localStorage || null );
if ( !langcodes ) {
delete localStorage;
console.warn('Local storage: "languages/canonical names/json" is absent');
return;
}
Object.entries(langcodes).forEach( function(entry) {
langnames ] = entry;
});
document.querySelectorAll(".mw-parser-output > h2 .mw-headline").forEach( function(hl) {
var name = hl.innerText;
var code = langcodes || "--";
var a = document.createElement("a");
a.href = "https://dictious.com/en/Category:"+ name + (name.includes("Language")? "" : "_language"); // Sign Language
a.innerText = "("+ code +")";
hl.after( a );
a.before( document.createTextNode(" ") ); // a.style = "1ch"
});
}
var ledokolRef = document.createElement("span"); // preserve em
ledokolRef.style = "absolute";
ledokolRef.style = "0.20em";
ledokolRef.style = "1.20em";
var ledokolRef2 = ledokolRef.appendChild( document.createElement("code") ); // reset inconsistent properties
ledokolRef2.style = "0.875rem";
ledokolRef2.style = "sans-serif";
ledokolRef2.style = "normal";
ledokolRef2.style = "normal";
ledokolRef2.appendChild( document.createElement("a") ).target = "_blank";
ledokolRef2.append( document.createTextNode(" ") );
ledokolRef2.appendChild( document.createElement("a") ).target = "_blank";
ledokolRef2.children.innerText = "References";
ledokolRef2.children.innerText = "(Category)";
function toggleLedokolRef( ev ) {
if ( !langcodes )
return;
if ( ev.type == "mouseenter" ) {
var code = "0code";
var name = "0lang";
var word = "0word";
if ( this.nodeName == "A" ) { // a
code = this.parentNode;
if ( this.classList.contains("new") ) {
word = this.search.replace(/.*title=(*).*/g, "$1");
} else if ( this.pathname.search("^https://dictious.com/en/") != -1 ) {
word = this.pathname;
if ( !langnames )
name = this.hash.replace("#","");
}
name = langnames || name;
} else { // h2 .mw-headline
word = location.pathname;
name = this.innerText;
code = langcodes && langcodes || code;
}
word = word.replace(/.*\//g, "");
var linkName = name.replaceAll(" ","_");
ledokolRef2.firstElementChild.href = "https://dictious.com/en/Appendix:"+ name +"_bibliography#"+ word;
ledokolRef2.lastElementChild.href = "https://dictious.com/en/Category:"+ name +"_reference_templates";
ledokolRef.style = "";
this.before( ledokolRef );
} else if ( ev.type == "mouseleave" ) { // a.parentNode, h2
ledokolRef.style = "none";
}
}
function ledokolEncode( input, href ) {
if ( !input ) return;
if ( href.includes("FFFFFF") ) {
return href.replace( "FFFFFF", input );
} else if ( href.includes("EEEEEE") ) {
return href.replace( "EEEEEE", input.replaceAll(" ","+") );
}
}
function loadLedokol() {
if ( mw.config.get("wgArticleId") == 0 ) // wgWMEPageLength, wgRevisionId
return;
var ns = mw.config.get("wgNamespaceNumber"); // wgNamespaceIds
if ( ns == 100 && mw.config.get("wgTitle").search("bibliography$") != -1 ) { // 100:"appendix"
var search = document.querySelector("#mw-content-text .mw-parser-output").insertAdjacentElement( "beforebegin", document.createElement("p") );
search.style = "fixed";
search.style = "0";
search.style = "0";
search.style = "100%";
search.style = "center";
var input = search.appendChild( document.createElement("input") );
input.placeholder = 'Change links with query="FFFFFF"';
input.title = "FFFFFF (space=space), EEEEEE (space=+)"
var button = search.appendChild( document.createElement("button") );
button.innerText = "open";
if ( location.hash ) {
input.value = decodeURI(location.hash).replace("#","").replaceAll("_"," ");
}
var linkCount = 0;
document.querySelectorAll("#mw-content-text a").forEach( function(a) {
if ( a.href.search("(FFFFFF|EEEEEE)") != -1 ) {
linkCount++;
a.dataset = a.href;
a.href = ledokolEncode( input.value, a.dataset );
a.style = "rgba(255,127,0,0.20)";
}
});
button.innerText += " "+ linkCount;
input.addEventListener("input", function() {
location.hash = "#"+ input.value;
document.querySelectorAll("#mw-content-text a").forEach( function(a) {
ledokolEncode( input.value, a.dataset );
a.href = ledokolEncode( input.value, a.dataset );
});
});
button.addEventListener("click", function() {
document.querySelectorAll("#mw-content-text a").forEach( function(a) {
open( a.href, "_blank" ); // _parent, _top
});
});
} else if ( ns == 0 || ns == 118 ) { // 0:"" || 118:"reconstuction"
var past = JSON.parse( localStorage || null );
var present = Math.floor( Date.now() / 8.64e7 );
if ( !past || present-past > 7 ) {
$.when( updateStorageLangcodes(present) ).done( function() {
displayHeaderLangcodes();
});
} else {
displayHeaderLangcodes();
}
document.querySelectorAll("#mw-content-text a").forEach( function(a) {
if ( a.parentNode && a.host == location.host && a.innerText ) { // lang-marked && internal && not empty
a.addEventListener("mouseenter", toggleLedokolRef);
a.parentNode.addEventListener("mouseleave", toggleLedokolRef);
}
});
document.querySelectorAll("#mw-content-text h2 .mw-headline").forEach( function(h) {
h.addEventListener("mouseenter", toggleLedokolRef);
h.parentNode.addEventListener("mouseleave", toggleLedokolRef);
});
}
}
document.addEventListener("DOMContentLoaded", loadLedokol);