//ユーザーデータ表示
localStorage.removeItem("history");
//コード受信
if (location.search) {
var m = location.search.match(/\?mode=([a-zA-Z-0-9]+)\&code=(.+)/);
var mode = m[1];
var codex = m[2];
if (mode == "user") {
udgEx(codex, "main");
}
}
function udgEx(user, acct_id) {
if (user == "selector") {
user = $("#his-acct").attr("fullname");
}
if (acct_id == "selector") {
acct_id = $("#user-acct-sel").val();
}
if (acct_id == "main") {
acct_id = localStorage.getItem("main");
}
console.log("Get user data of " + user);
var domain = localStorage.getItem("domain_" + acct_id);
if (localStorage.getItem("mode_" + domain) == "misskey") {
return false;
}
var at = localStorage.getItem("acct_" + acct_id + "_at");
var start = "https://" + domain + "/api/v2/search?resolve=true&q=" + encodeURIComponent(user);
fetch(start, {
method: "GET",
headers: {
"content-type": "application/json",
Authorization: "Bearer " + at
}
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
if (json.accounts[0]) {
var id = json.accounts[0].id;
udg(id, acct_id);
} else {
postMessage(["openUrl", user], "*");
}
});
return true;
}
function udg(user, acct_id) {
reset();
if (!user) {
user = localStorage.getItem("user-id_" + acct_id);
}
todo("User Data Loading...");
var domain = localStorage.getItem("domain_" + acct_id);
if (localStorage.getItem("mode_" + domain) == "misskey") {
misskeyUdg(user, acct_id);
return;
}
var at = localStorage.getItem("acct_" + acct_id + "_at");
var start = "https://" + domain + "/api/v1/accounts/" + user;
fetch(start, {
method: "GET",
headers: {
"content-type": "application/json",
Authorization: "Bearer " + at
}
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
//一つ前のユーザーデータ
if (!localStorage.getItem("history")) {
$("#his-history-btn").prop("disabled", true);
} else {
$("#his-history-btn").prop("disabled", false);
$("#his-data").attr("history", localStorage.getItem("history"));
}
//moved設定時
if (json.moved) {
M.toast({
html: lang.lang_showontl_movetxt + '",
displayLength: 4000
});
}
$("#his-data").modal("open");
$("#his-data").attr("user-id", user);
$("#his-data").attr("use-acct", acct_id);
if (json.username != json.acct) {
//Remote
$("#his-data").attr("remote", "true");
var fullname = json.acct;
} else {
$("#his-data").attr("remote", "false");
var fullname = json.acct + "@" + domain;
}
utlShow(json.id, "", acct_id);
flw(json.id, "", acct_id);
fer(json.id, "", acct_id);
var dis_name = escapeHTML(json.display_name);
dis_name = twemoji.parse(dis_name);
var note = json.note;
if (json.emojis) {
var actemojick = json.emojis[0];
} else {
var actemojick = false;
}
//絵文字があれば
if (actemojick) {
Object.keys(json.emojis).forEach(function(key5) {
var emoji = json.emojis[key5];
var shortcode = emoji.shortcode;
var emoji_url = '';
var regExp = new RegExp(":" + shortcode + ":", "g");
dis_name = dis_name.replace(regExp, emoji_url);
note = note.replace(regExp, emoji_url);
});
}
//noteの解析
//var tags = '#$1';
//var mens = '@$1';
//note=note.replace(/#(\S+)/gi, tags)
//note=note.replace(/\s@([a-zA-Z_0-9@.-]+)/gi, mens)
$("#his-name").html(dis_name);
$("#his-acct").text(json.acct);
$("#his-acct").attr("fullname", fullname);
$("#his-prof").attr("src", json.avatar);
$("#his-data").css("background-image", "url(" + json.header + ")");
$("#his-sta").text(json.statuses_count);
$("#his-follow").text(json.following_count);
var flerc = json.followers_count;
if (flerc < 0) {
flerc = "-";
}
$("#his-follower").text(flerc);
$("#his-since").text(crat(json.created_at));
$("#his-openin").attr("data-href", json.url);
if (json.fields) {
var table = "";
if (json.fields.length > 0) {
$("#his-des").css("max-height", "250px");
table = '
';
for (var i = 0; i < json.fields.length; i++) {
var fname = json.fields[i].name;
var fval = json.fields[i].value;
if (json.fields[i].verified_at) {
var when = lang.lang_showontl_verified + ":" + crat(json.fields[i].verified_at);
var color = "rgba(121,189,154,.25);";
} else {
var when = "";
var color = "inherit";
}
table = table + '