thedesk/app/js/userdata/showOnTL.js

285 lines
8.5 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
//ユーザーデータ表示
2018-02-05 01:56:31 +11:00
localStorage.removeItem("history");
2018-02-18 16:43:11 +11:00
//コード受信
if(location.search){
2018-02-26 02:32:10 +11:00
var m = location.search.match(/\?mode=([a-zA-Z-0-9]+)\&code=(.+)/);
2018-02-18 16:43:11 +11:00
var mode=m[1];
var codex=m[2];
if(mode=="user"){
2018-05-20 16:17:10 +10:00
udgEx(codex,'main');
2018-02-18 16:43:11 +11:00
}
}
2018-03-21 16:36:02 +11:00
function udgEx(user,acct_id){
2018-03-31 13:39:06 +11:00
if(user=="selector"){
user = $("#his-acct").attr('fullname');
}
if(acct_id=="selector"){
acct_id = $("#user-acct-sel").val();
}
2018-05-20 16:17:10 +10:00
if(acct_id=="main"){
acct_id = localStorage.getItem("main");
}
2018-03-31 13:39:06 +11:00
console.log(user);
2018-03-21 16:36:02 +11:00
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/search?resolve=true&q="+user
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
}
}).then(function(response) {
return response.json();
}).catch(function(error) {
todo(error);
console.error(error);
}).then(function(json) {
var id=json.accounts[0].id;
2018-03-31 13:39:06 +11:00
udg(id,acct_id);
2018-03-21 16:36:02 +11:00
});
return;
}
2018-01-28 23:22:43 +11:00
function udg(user, acct_id) {
2018-02-25 18:21:13 +11:00
reset();
2018-01-28 23:22:43 +11:00
if (!user) {
2018-02-17 00:08:43 +11:00
user = localStorage.getItem("user-id_"+acct_id);
console.log(user);
2018-01-28 23:22:43 +11:00
}
todo("User Data Loading...");
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/accounts/" + user;
2018-02-25 18:21:13 +11:00
console.log(start);
2018-01-28 23:22:43 +11:00
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
},
}).then(function(response) {
return response.json();
}).catch(function(error) {
todo(error);
console.error(error);
}).then(function(json) {
2018-02-05 01:56:31 +11:00
//一つ前のユーザーデータ
if (!localStorage.getItem("history")){
$("#his-history-btn").prop("disabled",true);
}else{
$("#his-history-btn").prop("disabled",false);
$('#his-data').attr("history", localStorage.getItem("history"));
}
2018-01-28 23:22:43 +11:00
//moved設定時
if (json.moved) {
Materialize.toast(
'このアカウントは移行します<button class="btn-flat toast-action" onclick="udg(\"' +
2018-02-25 18:21:13 +11:00
json.moved + ','+acct_id+'\")">移行先を見る</button>', 4000)
2018-01-28 23:22:43 +11:00
} else {
2018-02-25 18:21:13 +11:00
$('#his-data').modal('open');
2018-01-28 23:22:43 +11:00
$('#his-data').attr("user-id", user);
$('#his-data').attr("use-acct", acct_id);
2018-01-31 03:43:01 +11:00
if(json.username!=json.acct){
//Remote
$('#his-data').attr("remote", "true");
2018-03-11 01:22:59 +11:00
var fullname=json.acct;
2018-01-31 03:43:01 +11:00
}else{
$('#his-data').attr("remote", "false");
2018-03-11 01:22:59 +11:00
var fullname=json.acct+"@"+domain;
2018-01-31 03:43:01 +11:00
}
2018-02-25 18:21:13 +11:00
utl(json.id, '', acct_id);
flw(json.id, '', acct_id);
fer(json.id, '', acct_id);
2018-05-10 01:33:08 +10:00
var dis_name=escapeHTML(json.display_name);
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 = '<img src="' + emoji.url +
'" class="emoji-img" data-emoji="'+shortcode+'">';
var regExp = new RegExp(":" + shortcode + ":", "g");
dis_name = dis_name.replace(regExp, emoji_url);
});
}
$("#his-name").html(dis_name);
2018-01-28 23:22:43 +11:00
$("#his-acct").text(json.acct);
2018-03-11 01:22:59 +11:00
$("#his-acct").attr("fullname",fullname);
2018-01-28 23:22:43 +11:00
$("#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);
$("#his-follower").text(json.followers_count);
2018-02-25 18:21:13 +11:00
$("#his-since").text(crat(json.created_at));
2018-04-17 03:10:35 +10:00
if(json.fields){
2018-05-02 14:14:03 +10:00
if(json.fields.length>0){
var note=json.note+'My Fields<br><table style="vertical-align: baseline; text-align:center; padding:0;">'
for(var i=0;i<json.fields.length;i++){
var fname=json.fields[i].name;
var fval=json.fields[i].value;
note=note+'<tr style="height:1.5rem; padding:0;"><td style="height:1.5rem; padding:0; background-color:#757575; text-align:center; ">'+fname+'</td><td style="height:1.5rem; padding:0; padding-left:5px;">'+fval+'</td></tr>';
}
note=note+'</table>'
$("#his-des").html(note);
}else{
$("#his-des").html(json.note);
2018-04-17 03:10:35 +10:00
}
}else{
$("#his-des").html(json.note);
}
2018-01-28 23:22:43 +11:00
$('#his-data').css('background-size', 'cover');
2018-02-05 01:56:31 +11:00
localStorage.setItem("history" , user);
2018-02-25 18:21:13 +11:00
//自分の時
if (json.acct == localStorage.getItem("user_"+acct_id)) {
showFav('', acct_id);
showBlo('', acct_id);
showMut('', acct_id);
showDom('', acct_id);
showReq('', acct_id);
$("#his-name-val").val(json.display_name);
var des = json.note;
des = des.replace(/<br \/>/g, "\n")
des = $.strip_tags(des);
$("#his-des-val").val(des);
$("#his-follow-btn").hide();
$("#his-block-btn").hide();
$("#his-mute-btn").hide();
$("#his-notf-btn").hide();
$("#his-domain-btn").hide();
2018-03-11 01:22:59 +11:00
$("#his-emp-btn").hide();
2018-03-14 05:31:31 +11:00
$(".only-my-data").show();
2018-03-21 16:36:02 +11:00
$(".only-his-data").hide();
2018-02-25 18:21:13 +11:00
} else {
relations(user, acct_id);
2018-04-01 07:00:27 +10:00
hisList(user,acct_id);
2018-03-14 05:31:31 +11:00
$(".only-my-data").hide();
2018-03-21 16:36:02 +11:00
$(".only-his-data").show();
2018-02-25 18:21:13 +11:00
}
2018-01-28 23:22:43 +11:00
}
todc();
});
}
2018-02-05 01:56:31 +11:00
//一つ前のユーザーデータ表示
function historyShow(){
var acct_id=$('#his-data').attr("use-acct");
var user=$('#his-data').attr("history");
udg(user, acct_id, "true")
}
2018-02-17 00:08:43 +11:00
//選択アカウントのプロフ
function profShow(){
var acct_id = $("#post-acct-sel").val();
var user = localStorage.getItem("user-id_"+acct_id);
console.log("user-id_"+acct_id+":"+user);
udg(user, acct_id)
}
2018-01-28 23:22:43 +11:00
//FF関係取得
function relations(user, acct_id) {
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/accounts/relationships?id=" + user;
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
},
}).then(function(response) {
return response.json();
}).catch(function(error) {
todo(error);
console.error(error);
}).then(function(json) {
var json = json[0];
console.log(json);
if (json.following) {
//自分がフォローしている
$("#his-data").addClass("following");
$("#his-follow-btn").text("フォロー解除");
2018-01-31 03:43:01 +11:00
}else{
$("#his-follow-btn").text("フォロー");
2018-01-28 23:22:43 +11:00
}
if (json.followed_by) {
//フォローされてる
$("#his-relation").text("フォローされています");
}
if (json.blocking) {
$("#his-data").addClass("blocking");
$("#his-block-btn").text("ブロック解除");
2018-01-31 03:43:01 +11:00
}else{
$("#his-block-btn").text("ブロック");
2018-01-28 23:22:43 +11:00
}
if (json.muting) {
$("#his-data").addClass("muting");
$("#his-mute-btn").text("ミュート解除");
2018-01-31 03:43:01 +11:00
}else{
$("#his-mute-btn").text("ミュート");
2018-01-28 23:22:43 +11:00
}
if (json.muting_notifications) {
$("#his-data").addClass("mutingNotf");
$("#his-notf-btn").text("通知ミュート解除");
2018-01-31 03:43:01 +11:00
}else{
$("#his-notf-btn").text("通知ミュート");
2018-01-28 23:22:43 +11:00
}
if (json.domain_blocking) {
$("#his-data").addClass("blockingDom");
$("#his-domain-btn").text("ドメインブロック解除");
2018-01-31 03:43:01 +11:00
}else{
$("#his-domain-btn").text("ドメインブロック");
2018-01-28 23:22:43 +11:00
}
});
}
//オールリセット
function hisclose() {
$('#his-data').modal('close');
2018-02-25 18:21:13 +11:00
reset();
$('#his-data').attr("history", "");
localStorage.removeItem("history");
}
function reset(){
2018-03-14 05:31:31 +11:00
$(".tab-content:eq(0)").show();
$(".tab-content:gt(0)").hide();
2018-01-28 23:22:43 +11:00
$("#his-name").text("Loading");
$("#his-acct").text("");
$("#his-prof").attr("src", "./img/loading.svg");
$('#his-data').css('background-image', 'url(./img/loading.svg)');
$("#his-sta").text("");
$("#his-follow").text("");
$("#his-follower").text("");
$("#his-des").html("");
$('#his-data').css('background-size', 'cover');
$("#his-since").text("");
$("#his-data").removeClass("following");
$("#his-data").removeClass("muting");
$("#his-data").removeClass("blocking");
$("#his-data").removeClass("mutingNotf");
$("#his-data").removeClass("blockingDom");
$("#his-follow-btn").show();
$("#his-block-btn").show();
$("#his-mute-btn").show();
$("#his-notf-btn").show();
$("#his-domain-btn").show();
2018-03-11 01:22:59 +11:00
$("#his-emp-btn").show();
2018-01-28 23:22:43 +11:00
$("#his-follow-btn").text("フォロー");
$("#his-mute-btn").text("ミュート");
$("#his-block-btn").text("ブロック");
$("#his-notf-btn").text("通知ミュート");
$("#his-domain-btn").text("ドメインブロック");
$("#his-relation").text("");
$(".cont-series").html("");
$("#domainblock").val("");
2018-03-14 05:31:31 +11:00
}
$('#my-data-nav .custom-tab').on('click',function(){
var target=$(this).find("a").attr("go");
$("#my-data-nav .custom-tab").removeClass("active-back");
$(this).addClass("active-back");
$(target).show();
$(".tab-content:not("+target+")").hide();
});