User:Erutuon/scripts/showLanguageData.js

/* jshint esversion: 6, undef: true */ /* globals $, apiWrapper, mw */ //

// In language categories, adds a button to show the language data as // highlighted Lua source code. // Data is retrieved by Module:User:Erutuon/show data. // Button is placed below the "Edit language data" link. // Button is hidden when language data has been retrieved. // The language code is retrieved from the data-code attribute of the table tag.

(function showLanguageDataIIFE {	var first = $(".language-category-data th");	var languageCode = $(".language-category-info").data("code");	if (!(first && languageCode)) {		return;	}	$.getScript("//en.wiktionary.org/w/index.php?title=User:Erutuon/scripts/apiWrapper.js&action=raw&ctype=text/javascript")	.done	(function { var languageDataClassName = "language-data"; var p = $(" "); var button = $(" ").text("Show language data"); button.on("click", function {			if ($("." + languageDataClassName).length > 0) {				return;			}			mw.loader.using("ext.pygments").done(function  { apiWrapper.parse("", function (languageData) {					languageData = $(languageData);					languageData.addClass(languageDataClassName).css("text-align", "left").appendTo(first);					button.hide;				}); });		});		button.appendTo(p); p.appendTo(first); }); });

//