Add: tag suggest with v2

This commit is contained in:
Cutls 2019-07-29 00:16:49 +09:00
parent f081154804
commit fd9c97a126

View File

@ -66,7 +66,7 @@ input.addEventListener("focus", function () {
} }
var domain = localStorage.getItem("domain_" + acct_id); var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_" + acct_id + "_at"); var at = localStorage.getItem("acct_" + acct_id + "_at");
suggest = "https://" + domain + "/api/v1/search?q=" + q suggest = "https://" + domain + "/api/v2/search?q=" + q
if (suggest != oldSuggest) { if (suggest != oldSuggest) {
console.log("Try to get suggest at " + suggest) console.log("Try to get suggest at " + suggest)
fetch(suggest, { fetch(suggest, {
@ -81,18 +81,20 @@ input.addEventListener("focus", function () {
todo(error); todo(error);
console.error(error); console.error(error);
}).then(function (json) { }).then(function (json) {
console.log(["Search", json]);
//ハッシュタグ
if (json.hashtags[0] && tag) { if (json.hashtags[0] && tag) {
if (tag[1]) { if (tag[1]) {
var tags = ""; var tags = "";
Object.keys(json.hashtags).forEach(function (key4) { Object.keys(json.hashtags).forEach(function (key4) {
var tag = json.hashtags[key4]; var tag = json.hashtags[key4];
if (tag != q) { var his = tag.history;
tags = tags + '<a onclick="tagInsert(\'#' + tag + '\',\'#' + q + var uses = his[0].uses*1+ his[1].uses*1+ his[2].uses*1+ his[3].uses*1+ his[4].uses*1+ his[5].uses*1+ his[6].uses*1;
'\')" class="pointer">#' + tag + '</a><br>'; tags = tags + '<br><a onclick="tagInsert(\'#' + escapeHTML(tag.name) + '\',\'#' + q + '\')" class="pointer">#' +
} escapeHTML(tag.name) + '</a>&nbsp;' + uses + 'toots'
}); });
$("#right-side").show() $("#right-side").show()
$("#suggest").html("Tags:<br>" + tags); $("#suggest").html(tags);
$("#poll").addClass("hide") $("#poll").addClass("hide")
$("#emoji").addClass("hide") $("#emoji").addClass("hide")
} }