<![CDATA[// <![CDATA[(function () { const $DEBUG = console && console.log; var warn = function () {console.log.apply(this, arguments);}; var toSortkey = function (__toSortkey__) {return function (str) {var sortkeyText = "";Array.prototype.forEach.call(str, function (c) {sortkeyText += __toSortkey__[c] || c;});return sortkeyText;};}(function (object) {var __toSortkey__ = {};for (var i in object) {Array.prototype.forEach.call(object[i], function (c) {__toSortkey__[c] = String.fromCharCode(c.charCodeAt(0) + i * 1);});}return __toSortkey__;}({'-2': "\u3071\u3074\u3077\u307A\u307D", '-1': "\u304C\u304E\u3050\u3052\u3054\u3056\u3058\u305A\u305C\u305E\u3060\u3062\u3065\u3067\u3069\u3070\u3073\u3076\u3079\u307C", '1': "\u3041\u3043\u3045\u3047\u3049\u3063\u3083\u3085\u3087\u308E"})); var getJSON = function (url, data, callback) {var flag = true;for (var key in data) {var value = data[key];if (flag) {url += "?";flag = false;} else {url += "&";}if (value == "?") {value = "jsonp" + Math.floor(Math.random() * 10000000000000);this[value] = callback;}url += encodeURIComponent(key);if (value == null) {continue;}url += "=" + encodeURIComponent(value).replace(/%20/g, "+");}var script = document.createElement("script");script.type = "application/javascript";script.src = url;document.body.appendChild(script);}; var Konno = {}; Konno.Kana = {}; Konno.Kana.Kanji = {}; Konno.Kana.Kanji.Conversion = function () {this.sources = [{hostname: "ja.wiktionary.org", cmtitle: "Category:\u65E5\u672C\u8A9E"}, {hostname: "ja.wikipedia.org", cmtitle: "Category:\u5B58\u547D\u4EBA\u7269"}, ];this.convert = function (query, callback) {var sources = this.sources;var candidates = [query];var i = 0;var l = sources.length;(function () {var BLOCK = arguments.callee;var src = sources[i];getJSON("http://" + src.hostname + "/w/api.php", {action: "query", list: "categorymembers", cmtitle: src.cmtitle, cmprop: "title|sortkey", cmnamespace: 0, cmcontinue: toSortkey(query) + "|", cmlimit: 500, format: "json", callback: "?"}, function (json) {try {json.query.categorymembers.forEach(function (cm) {var sortkey = cm.sortkey.split(/[\s_]/)[0];if (sortkey != query && toSortkey(sortkey) != toSortkey(query)) {throw null;}var title = cm.title;if (title == query || toSortkey(title) == toSortkey(query)) {return;}candidates.push(title);});} catch (e) {}i++;if (i >= l) {getJSON("http://ja.wikipedia.org/w/api.php", {action: "query", list: "search", srsearch: query, srnamespace: 0, srwhat: "text", srinfo: "", srprop: "", srlimit: 50, format: "json", callback: "?"}, function (json) {json.query.search.forEach(function (sr) {var title = sr.title;if (title == query || toSortkey(title) == toSortkey(query)) {return;}candidates.push(sr.title);});callback(candidates);});return;}BLOCK();});}());};return this;}; var $$ = function (elementList) {return function (selectors) {return elementList[selectors] || (elementList[selectors] = document.querySelectorAll(selectors));};}({}); Array.prototype.forEach.call($$("input, textarea"), function (element) {var oldText = element.value;var listener;window.setInterval(function () {var text = element.value;if (text == oldText) {return;}if (listener) {element.removeEventListener("keyup", listener, false);listener = null;}oldText = text;if (!text.trim()) {return;}var i = 0;var candidatesList = [];var tmpList = [text];tmpList.selectedIndex = 0;candidatesList.unshift(tmpList);var tmp = "";(function (query) {var BLOCK = arguments.callee;$DEBUG && warn(query);(new (Konno.Kana.Kanji.Conversion)).convert(query, function (candidates) {if (element.value != text) {return;}if (candidates.length < 2 && query.length > 1) {tmp += query[0];BLOCK(query.slice(1, query.length));return;}candidates.selectedIndex = 0;candidatesList.shift();candidatesList.unshift(candidates);if (tmp == "") {i = candidatesList.length - 1;$DEBUG && warn(JSON.stringify(candidatesList));return;}var tmpList = [tmp];tmpList.selectedIndex = 0;candidatesList.unshift(tmpList);i = candidatesList.length - 1;$DEBUG && warn(JSON.stringify(candidatesList));BLOCK(tmp);tmp = "";});}(text));listener = function (event) {if (!candidatesList[i]) {return;}switch (event.keyCode) {case 37:i--;if (i < 0) {i += candidatesList.length;}break;case 38:candidatesList[i].selectedIndex--;if (candidatesList[i].selectedIndex < 0) {candidatesList[i].selectedIndex += candidatesList[i].length;}element.value = oldText = text = candidatesList.map(function (candidates) {return candidates[candidates.selectedIndex];}).join("");break;case 39:i++;if (i >= candidatesList.length) {i -= candidatesList.length;}break;case 40:candidatesList[i].selectedIndex++;if (candidatesList[i].selectedIndex >= candidatesList[i].length) {candidatesList[i].selectedIndex -= candidatesList[i].length;}element.value = oldText = text = candidatesList.map(function (candidates) {return candidates[candidates.selectedIndex];}).join("");break;default:;}};element.addEventListener("keyup", listener, false);}, 1);}); })()]]]]><![CDATA[>]]>