//検索
//検索ボックストグル
function searchMenu() {
$("#left-menu div").removeClass("active");
$("#searchMenu").addClass("active");
$(".menu-content").addClass("hide");
$("#src-box").removeClass("hide");
$('ul.tabs').tabs('select_tab', 'src-sta');
$("#src-contents").html("");
}
//検索取得
function src(mode) {
$("#src-contents").html("");
var q = $("#src").val();
var acct_id = $("#src-acct-sel").val();
if (acct_id == "tootsearch") {
tsAdd(q)
return false;
}
localStorage.setItem("last-use", acct_id);
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_" + acct_id + "_at");
var m = q.match(/^#(.+)$/);
if (m) { q = m[1]; }
if (user == "--now") {
var user = $('#his-data').attr("user-id");
}
if (!mode) {
var start = "https://" + domain + "/api/v2/search?q=" + q
} else {
var start = "https://" + domain + "/api/v1/search?q=" + q
}
console.log("Try to search at " + start)
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
},
}).then(function (response) {
return response.json();
}).catch(function (error) {
src("v1")
return false;
}).then(function (json) {
console.log(["Search", json]);
//ハッシュタグ
if (json.hashtags[0]) {
var tags = "";
Object.keys(json.hashtags).forEach(function (key4) {
var tag = json.hashtags[key4];
if (mode) {
tags = tags + '#' + escapeHTML(tag) + '
';
} else {
tags = tags + graphDraw(tag, acct_id);
}
});
$("#src-contents").append("Tags
" + tags);
}
//トゥート
if (json.statuses[0]) {
var templete = parse(json.statuses, '', acct_id);
$("#src-contents").append("
Mentions
" + templete);
}
//アカウント
if (json.accounts[0]) {
var templete = userparse(json.accounts, '', acct_id);
$("#src-contents").append("
Accounts
" + templete);
}
jQuery("time.timeago").timeago();
});
}
function tsAdd(q) {
var add = {
domain: acct_id,
type: "tootsearch",
data: q
};
var multi = localStorage.getItem("column");
var obj = JSON.parse(multi);
localStorage.setItem("card_" + obj.length, "true");
obj.push(add);
var json = JSON.stringify(obj);
localStorage.setItem("column", json);
parseColumn();
}
function tootsearch(tlid, q) {
var start = "https://tootsearch.chotto.moe/api/v1/search?from=0&sort=created_at%3Adesc&q=" + q
console.log("Toot srrach at " + start)
$("#notice_" + tlid).text("tootsearch(" + q + ")");
$("#notice_icon_" + tlid).text("search");
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json'
},
}).then(function (response) {
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (raw) {
var templete = "";
var json = raw.hits.hits;
var max_id = raw["hits"].length;
for (var i = 0; i < json.length; i++) {
var toot = json[i]["_source"];
if (lastid != toot.uri) {
if (toot && toot.account) {
templete = templete + parse([toot], "noauth", null, tlid, 0, [], "tootsearch")
}
}
var lastid = toot.uri;
}
if (!templete) {
templete = lang.lang_details_nodata;
} else {
templete = templete + '