User:Surjection/categoryTreeLanguageNames.js

Hello, you have come here looking for the meaning of the word User:Surjection/categoryTreeLanguageNames.js. In DICTIOUS you will not only get to know all the dictionary meanings for the word User:Surjection/categoryTreeLanguageNames.js, but we will also tell you about its etymology, its characteristics and you will know how to say User:Surjection/categoryTreeLanguageNames.js in singular and plural. Everything you need to know about the word User:Surjection/categoryTreeLanguageNames.js you have here. The definition of the word User:Surjection/categoryTreeLanguageNames.js will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofUser:Surjection/categoryTreeLanguageNames.js, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.
"use strict";

// {{documentation}}
// <nowiki>

(function linkLanguageHeadersGadget() {
    var CACHE_DURATION = 24 * 60 * 60; // 24 hours

    var ALLOWED_NAMESPACES = [
        0,      // main
        14,     // Category
        100,    // Appendix
        118     // Reconstruction
    ];

    var CATEGORY_PREFIX = mw.config.get("wgFormattedNamespaces") + ":";

    function getLanguageCodeToCanonicalName(callback, cacheDuration) {
        var KEY = "enwiktLanguageCodeToCanonicalNameJson";
        var timeNow = new Date().getTime() * 1e-3;
        try {
            var cachedData = JSON.parse(localStorage.getItem(KEY));
            if (timeNow - cachedData.timestamp < cacheDuration) {
                callback(cachedData.data);
                return;
            }
        } catch (e) { }

        var request = new mw.Api().get({
            "action": "parse",
            "page": "Module:languages/code to canonical name.json",
            "prop": "wikitext",
            "formatversion": 2,
            "format": "json"
        });
        request.done(function(response) {
            var languageData = JSON.parse(response.parse.wikitext);
            callback(languageData);
            localStorage.setItem(KEY, JSON.stringify({
                timestamp: timeNow,
                data: languageData
            }));
        });
    }

    function addCategoryTreeLanguageName(codeToCanonicalName, element, doNotTagLanguageCode) {
        // not a category link/name
        if (element.href.indexOf(CATEGORY_PREFIX) < 0)
            return;

        var firstTextNode = Array.prototype.find.call(element.childNodes, function(node) {
            return node.nodeType === 3;
        });
        if (!firstTextNode)
            return;

        var categoryName = firstTextNode.textContent;
        var parseCategoryTreeName = categoryName.match(/^(+):(.+)/);
        if (!parseCategoryTreeName)
            return;

        var languageCode = parseCategoryTreeName;
        var subcategoryName = parseCategoryTreeName;
        var canonicalName = codeToCanonicalName;
        if (!canonicalName)
            return;

        if (element.title === categoryName || element.title === CATEGORY_PREFIX + categoryName)
            element.title += " ";

        if (languageCode !== doNotTagLanguageCode)
            element.appendChild($('<span></span>').addClass("wikt-category-tree-language-name").text(" "));
    }

    mw.hook("wikipage.content").add(function() {
        if (mw.config.get("wgAction") === "view" &&
                ALLOWED_NAMESPACES.indexOf(mw.config.get("wgNamespaceNumber")) >= 0) {

            mw.util.addCSS(`
                .wikt-category-tree-language-name {
                    font-size: 85%;
                }
                `);

            var thisLanguageCode = null;
            if (mw.config.get("wgNamespaceNumber") === 14) {
                var categoryName = mw.config.get("wgTitle");
                var parseCategoryTreeName = categoryName.match(/^(+):(.+)/);
                if (parseCategoryTreeName)
                    thisLanguageCode = parseCategoryTreeName;
            }

            getLanguageCodeToCanonicalName(function (codeToCanonicalName) {
                $('#catlinks ul > li a').each(function () {
                    addCategoryTreeLanguageName(codeToCanonicalName, this, thisLanguageCode);
                });
                if (mw.config.get("wgNamespaceNumber") === 14) {
                    $('#mw-subcategories a').each(function () {
                        addCategoryTreeLanguageName(codeToCanonicalName, this, thisLanguageCode);
                    });
                }
            }, CACHE_DURATION);
        }
    });
})();

// </nowiki>