TheDesk modify

This commit is contained in:
cutls
2018-01-28 21:27:11 +09:00
parent 30132ca31d
commit 50e99f6a68
138 changed files with 0 additions and 0 deletions

72
app/js/tl/card.js Normal file
View File

@@ -0,0 +1,72 @@
//カード処理やメンション、ハッシュタグの別途表示
//全てのTL処理で呼び出し
function additional(acct_id, tlid) {
//メンション系
$(".mention").attr("href", "#");
//トゥートサムネ
$("#timeline_" + tlid + " .toot a:not(.parsed)").each(function(i, elem) {
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var card = localStorage.getItem("card_" + tlid);
var text = $(this).attr('href');
var urls = text.match(
/https?:\/\/([-a-zA-Z0-9@.]+)\/media\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/
);
if (urls) {
$(this).remove();
} else if (!card) {
var id = $(this).parents('.cvo').attr("toot-id");
var start = "https://" + domain + "/api/v1/statuses/" + id + "/card";
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
},
//body: JSON.stringify({})
}).then(function(response) {
return response.json();
}).catch(function(error) {
todo(error);
console.error(error);
}).then(function(json) {
console.log(json);
if (json.title) {
$("[toot-id=" + id + "] .additional").html(
"<span class=\"gray\">URLチェック:<br>Title:" + json.title + "<br>" +
json.description + "</span>");
}
if (json.html) {
$("[toot-id=" + id + "] .additional").html(json.html);
}
if (json.title) {
$("[toot-id=" + id + "] a:not(.parsed)").addClass("parsed");
$("[toot-id=" + id + "]").addClass("parsed");
}
});
}
});
}
//各TL上方のLink[On/Off]
function cardToggle(tlid) {
var card = localStorage.getItem("card_" + tlid);
if (!card) {
localStorage.setItem("card_" + tlid, "true");
$("#sta-card-" + tlid).text("Off");
} else {
localStorage.removeItem("card_" + tlid);
$("#sta-card-" + tlid).text("On");
}
}
//各TL上方のLink[On/Off]をチェック
function cardCheck(tlid) {
var card = localStorage.getItem("card_" + tlid);
if (!card) {
$("#sta-card-" + tlid).text("On");
} else {
$("#sta-card-" + tlid).text("Off");
}
}

149
app/js/tl/datails.js Normal file
View File

@@ -0,0 +1,149 @@
//トゥートの詳細
function details(id, acct_id) {
$(".toot-reset").html("トゥートはありません");
var html = $("#pub_" + id).html();
$("#toot-this").html(html);
$('#tootmodal').modal('open');
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/statuses/" + id;
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) {
$("#toot-this .fav_ct").text(json.favourites_count);
$("#toot-this .rt_ct").text(json.reblogs_count);
if (json.in_reply_to_id) {
replyTL(json.in_reply_to_id, acct_id);
}
context(id, acct_id);
faved(id, acct_id);
rted(id, acct_id);
});
}
//返信タイムライン
function replyTL(id, acct_id) {
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/statuses/" + id;
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 templete = parse([json]);
$("#toot-reply").prepend(templete);
jQuery("time.timeago").timeago();
if (json.in_reply_to_id) {
replyTL(json.in_reply_to_id, acct_id);
}
});
}
//コンテクストってなんですか
function context(id, acct_id) {
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/statuses/" + id + "/context";
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 templete = parse(json.descendants);
$("#toot-after").html(templete);
beforeToot(id, acct_id);
jQuery("time.timeago").timeago();
});
}
//前のトゥート(Back TL)
function beforeToot(id, acct_id) {
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain +
"/api/v1/timelines/public?local=true&max_id=" + id;
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 templete = parse(json);
$("#toot-before").html(templete);
jQuery("time.timeago").timeago();
});
}
//ふぁぼ一覧
function faved(id, acct_id) {
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/statuses/" + id + "/favourited_by";
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 templete = userparse(json);
$("#toot-fav").html(templete);
});
}
//ブースト一覧
function rted(id, acct_id) {
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/statuses/" + id + "/reblogged_by";
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 templete = userparse(json);
$("#toot-rt").html(templete);
});
}

69
app/js/tl/date.js Normal file
View File

@@ -0,0 +1,69 @@
//日付パーサー
function date(str, datetype) {
if (datetype == "relative") {
return '<time class="timeago" datetime="' + str + '"></time>';
} else {
var date = new Date(str);
if (datetype == "unix") {
var unixm = date.getTime();
return Math.floor(unixm / 1000);
}
var now = new Date();
var month = date.getMonth() + 1;
if (date.getMinutes() < 10) {
var min = "0" + date.getMinutes();
} else {
var min = date.getMinutes();
}
if (date.getSeconds() < 10) {
var sec = "0" + date.getSeconds();
} else {
var sec = date.getSeconds();
}
if (datetype == "full") {
var ret = date.getFullYear() + "年" + month + "月" + date.getDate() + "日 " +
date.getHours() + ":" + min + ":" + sec;
}
if (date.getFullYear() == now.getFullYear()) {
if (date.getMonth() == now.getMonth()) {
if (date.getDate() == now.getDate()) {
if (datetype == "medium") {
var ret = '<time class="timeago" datetime="' + str + '"></time>';
} else {
var ret = date.getHours() + ":" + min + ":" + sec;
}
} else {
var ret = month + "月" + date.getDate() + "日 " + date.getHours() + ":" +
min + ":" + sec;
}
} else {
var ret = month + "月" + date.getDate() + "日 " + date.getHours() + ":" + min +
":" + sec;
}
} else {
var ret = date.getFullYear() + "年" + month + "月" + date.getDate() + "日 " +
date.getHours() + ":" + min + ":" + sec;
}
if (datetype == "double") {
return '<time class="timeago" datetime="' + str + '"></time>/' + ret;
} else {
return ret;
}
}
}
//特殊フォーマット(インスタンス情報で利用)
function crat(str) {
var date = new Date(str);
format_str = 'YYYY-MM-DD hh:mm:ss';
format_str = format_str.replace(/YYYY/g, date.getFullYear());
format_str = format_str.replace(/MM/g, date.getMonth());
format_str = format_str.replace(/DD/g, date.getDate());
format_str = format_str.replace(/hh/g, date.getHours());
format_str = format_str.replace(/mm/g, date.getMinutes());
format_str = format_str.replace(/ss/g, date.getSeconds());
return format_str;
}

231
app/js/tl/mix.js Normal file
View File

@@ -0,0 +1,231 @@
//Integrated TL
function mixtl(acct_id, tlid) {
var type = "mix";
localStorage.removeItem("morelock")
$("#notice_" + tlid).text("Integrated TL");
localStorage.setItem("now", type);
todo("Integrated TL Loading...(Local)");
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
//まずLocal
var start = "https://" + domain + "/api/v1/timelines/public?local=true";
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 templete = parse(json, 'mix', acct_id);
$("#timeline_" + tlid).html(templete[0]);
jQuery("time.timeago").timeago();
$(window).scrollTop(0);
var locals = templete[1];
todo("Integrated TL Loading...(Home)");
//Home
var start = "https://" + domain + "/api/v1/timelines/home";
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(obj) {
//ホームのオブジェクトをUnix時間で走査
Object.keys(obj).forEach(function(key) {
var skey = obj.length - key - 1;
var toot = obj[skey];
var id = toot.id;
var tarunix = date(toot.created_at, 'unix');
var beforekey2;
var key2;
//ホームのオブジェクトに対してLocalのオブジェクトを時間走査
Object.keys(locals).forEach(function(key2) {
if (!$("#timeline_" + tlid + " [toot-id=" + obj[0].id + "]").length &&
key2 < date(obj[0].created_at, 'unix')) {
$("#timeline_" + tlid + " .cvo").first().prepend(parse([obj[0]],
'home', acct_id));
}
if (!$("#timeline_" + tlid + " [toot-id=" + toot.id + "]").length) {
if (key2 > tarunix) {
var local = locals[key2];
$("#timeline_" + tlid + " [toot-id=" + local + "]").append(parse(
[toot], 'home', acct_id));
tarunix = 0;
}
}
});
});
todc();
mixre(acct_id, tlid);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
});
});
}
//Streamingに接続
function mixre(acct_id, tlid) {
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var type = "mix";
localStorage.setItem("now", type);
var startHome = "wss://" + domain +
"/api/v1/streaming/?stream=user&access_token=" + at;
var startLocal = "wss://" + domain +
"/api/v1/streaming/?stream=public:local&access_token=" + at;
var wshid = websocketHome.length;
var wslid = websocketLocal.length;
websocketHome[wshid] = new WebSocket(startHome);
websocketLocal[wslid] = new WebSocket(startLocal);
websocketHome[wshid].onopen = function(mess) {
console.log("Connect Streaming API(Home)");
}
websocketLocal[wslid].onopen = function(mess) {
console.log("Connect Streaming API(Local)");
}
websocketLocal[wslid].onmessage = function(mess) {
console.log("Receive Streaming API:");
var obj = JSON.parse(JSON.parse(mess.data).payload);
console.log(obj);
var type = JSON.parse(mess.data).event;
if (type == "delete") {
$("[toot-id=" + obj + "]").hide();
} else if (type == "update") {
var templete = parse([obj], '', acct_id);
if (!$("#timeline_" + tlid + " [toot-id=" + obj.id + "]").length) {
var pool = localStorage.getItem("pool_" + tlid);
if (pool) {
pool = templete + pool;
} else {
pool = templete
}
localStorage.setItem("pool_" + tlid, pool);
scrollck();
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
todc();
}
}
}
websocketHome[wshid].onmessage = function(mess) {
console.log("Receive Streaming API:(Home)");
var obj = JSON.parse(JSON.parse(mess.data).payload);
console.log(obj);
var type = JSON.parse(mess.data).event;
if (type == "delete") {
$("[toot-id=" + obj + "]").hide();
} else if (type == "update") {
var templete = parse([obj], '', acct_id);
if (!$("#timeline_" + tlid + " [toot-id=" + obj.id + "]").length) {
if ($(window).scrollTop() > 0) {
var pool = localStorage.getItem("pool");
if (pool) {
pool = templete + pool;
} else {
pool = templete
}
localStorage.setItem("pool", pool);
} else {
$("#timeline_" + tlid).prepend(templete);
}
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
}
}
}
websocketLocal[wslid].onerror = function(error) {
console.error('WebSocket Error ' + error);
};
websocketHome[wshid].onerror = function(error) {
console.error('WebSocket Error ' + error);
};
}
//ある程度のスクロールで発火
function mixmore(tlid) {
var multi = localStorage.getItem("column");
var obj = JSON.parse(multi);
var acct_id = obj[tlid].domain;
todo("Integrated TL MoreLoading...(Local)");
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var sid = $("#timeline_" + tlid + " .cvo").last().attr("toot-id");
var start = "https://" + domain +
"/api/v1/timelines/public?local=true&max_id=" + sid;
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 templete = parse(json, 'mix', acct_id);
$("#timeline_" + tlid).append(templete[0]);
var locals = templete[1];
todo("Integrated TL MoreLoading...(Home)");
console.log(sid);
var start = "https://" + domain + "/api/v1/timelines/home?max_id=" + sid;
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(obj) {
if (!$("[toot-id=" + obj[0].id + "]").length) {
$("#timeline_" + tlid + " .cvo").first().prepend(parse([obj[0]], 'home',
acct_id));
}
Object.keys(obj).forEach(function(key) {
var skey = obj.length - key - 1;
var toot = obj[skey];
var id = toot.id;
var tarunix = date(toot.created_at, 'unix');
var beforekey2;
var key2;
Object.keys(locals).forEach(function(key2) {
if (!$("[toot-id=" + toot.id + "]").length) {
if (key2 > tarunix) {
var local = locals[key2];
$("[toot-id=" + local + "]").append(parse([toot], 'home',
acct_id));
tarunix = 0;
}
}
});
});
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
todc();
});
});
}

293
app/js/tl/notification.js Normal file
View File

@@ -0,0 +1,293 @@
//通知
//取得+Streaming接続
function notf(acct_id, tlid, sys) {
todo("Notifications Loading...");
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/notifications";
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
},
//body: JSON.stringify({})
}).then(function(response) {
return response.json();
}).catch(function(error) {
todo(error);
console.error(error);
}).then(function(json) {
var templete = parseNotf(json, -1, tlid, acct_id);
if (sys == "direct") {
$("#timeline_" + tlid).html(templete[0]);
} else {
$("#notifications_" + tlid).html(templete[0]);
}
jQuery("time.timeago").timeago();
$("#notf-box").addClass("fetched");
todc();
});
var start = "wss://" + domain + "/api/v1/streaming/?stream=user&access_token=" +
at;
console.log(start);
var websocket = new WebSocket(start);
console.log(websocket);
websocket.onopen = function(mess) {
console.log("Connect Streaming API:");
console.log(mess);
}
websocket.onmessage = function(mess) {
console.log("Receive Streaming API:");
var obj = JSON.parse(JSON.parse(mess.data).payload);
console.log(obj);
var type = JSON.parse(mess.data).event;
if (type == "notification") {
var popup = localStorage.getItem("popup");
if (!popup) {
popup = 0;
}
var templete = parseNotf([obj], popup, tlid, acct_id);
var notices = templete[1];
console.log(templete);
if (sys == "direct") {
$("#timeline_" + tlid).prepend(templete[0]);
} else {
$("#notifications_" + tlid).prepend(templete[0]);
}
jQuery("time.timeago").timeago();
}
}
websocket.onerror = function(error) {
console.error('WebSocket Error ' + error);
};
}
//通知トグルボタン
function notfToggle(acct, tlid) {
$("#notf-box_" + tlid).toggleClass("hide");
if (!$("#notf-box_" + tlid).hasClass("fetched")) {
notf(acct, tlid);
}
$(".notf-icon_" + tlid).removeClass("red-text");
}
//通知オブジェクトパーサー
function parseNotf(obj, popup, tlid, acct_id) {
var templete = '';
var datetype = localStorage.getItem("datetype");
var nsfwtype = localStorage.getItem("nsfw");
if (!nsfwtype || nsfwtype == "yes") {
var nsfw = "ok";
} else {
var nsfw;
}
var cwtype = localStorage.getItem("cw");
if (!cwtype || cwtype == "yes") {
var cw = "ok";
} else {
var cw;
}
if (!datetype) {
datetype = "absolute";
}
Object.keys(obj).forEach(function(key) {
var eachobj = obj[key];
var toot = eachobj.status;
//トゥートである
if (toot) {
if (!toot.application) {
var via = "<i>Unknown</i>";
} else {
var via = toot.application.name;
}
if (toot.account.locked) {
var locked = ' <i class="fa fa-lock red-text"></i>';
} else {
var locked = "";
}
var id = toot.id;
if (eachobj.type == "mention") {
var what = "返信しました";
} else if (eachobj.type == "reblog") {
var what = "ブーストしました";
} else if (eachobj.type == "favourite") {
var what = "ふぁぼしました";
}
var noticetext = eachobj.account.display_name + "(" + eachobj.account.acct +
")が" + what;
if (popup >= 0 && obj.length < 5) {
Materialize.toast(noticetext, popup * 1000);
$(".notf-icon_" + tlid).addClass("red-text");
}
if (toot.spoiler_text && cw) {
var spoiler = "cw cw_hide_" + toot.id;
var spoiler_show = '<a onclick="cw_show(\'' + toot.id + '\')">見る</a>';
} else {
var spoiler = "";
var spoiler_show = "";
}
var viewer = "";
var youtube = "";
var mediack = toot.media_attachments[0];
if (mediack) {
Object.keys(toot.media_attachments).forEach(function(key2) {
var media = toot.media_attachments[key2];
var purl = media.preview_url;
var url = media.url;
if (toot.sensitive && nsfw) {
var sense = "sensitive"
} else {
var sense = ""
}
viewer = viewer + '<a onclick="imgv(\'' + url + '\',\'' + toot.account
.acct + '\',\'' + media.type + '\')"><img src="' + purl + '" class="' +
sense +
'" width="250" style="object-fit: cover; width: 100%; height: 200px;"></a></span>';
});
} else {
viewer = "";
}
var menck = toot.mentions[0];
var mentions = "";
if (menck) {
mentions = "Links: ";
Object.keys(toot.mentions).forEach(function(key3) {
var mention = toot.mentions[key3];
mentions = mentions + '<a onclick="udg(\'' + mention.id +
'\')" class="pointer">@' + mention.acct + '</a> ';
});
}
var tagck = toot.tags[0];
var tags = "";
if (tagck) {
if (!menck) {
tags = "Links: ";
}
Object.keys(toot.tags).forEach(function(key4) {
var tag = toot.tags[key4];
tags = tags + '<a onclick="tl(\'tag\',\'' + tag.name +
'\')" class="pointer">#' + tag.name + '</a> ';
});
}
if (toot.favourited) {
var if_fav = " yellow-text";
var fav_app = "faved";
} else {
var if_fav = "";
var fav_app = "";
}
if (toot.reblogged) {
var if_rt = "teal-text";
var rt_app = "rted";
} else {
var if_rt = "";
var rt_app = "";
}
if (toot.account.acct == localStorage.getItem("user_" + acct_id)) {
var if_mine = "";
} else {
var if_mine = "hide";
}
if (toot.favourited) {
var if_fav = " yellow-text";
var fav_app = "faved";
} else {
var if_fav = "";
var fav_app = "";
}
if (toot.reblogged) {
var if_rt = "teal-text";
var rt_app = "rted";
} else {
var if_rt = "";
var rt_app = "";
}
templete = templete + '<div each=' + toot.datab + ' id="pub_' + toot.id +
'" class="cvo ' + fav_app + ' ' + rt_app +
'" style="padding-top:5px;" notf-id="' + eachobj.id + '">' +
'<span class="gray sharesta">' + noticetext +
'<br><span class="cbadge"><i class="fa fa-clock-o"></i>' + date(eachobj.created_at,
datetype) + '</span></span>' +
'<div style="padding:0; margin:0; width:400px; max-width:100%; display:flex; align-items:flex-end;">' +
'<div style="flex-basis:40px;"><a onclick="udg(\'' + toot.account.id +
'\',\'' + acct_id + '\');" user="' + toot.account.acct + '" class="udg">' +
'<img src="' + toot.account.avatar +
'" width="20" class="prof-img" user="' + toot.account.acct +
'"></a></div>' +
'<div style="flex-grow:3; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">' +
toot.account.display_name + '</div>' +
'<div class="sml gray" style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"> @' +
toot.account.acct + locked + '</div>' +
'</div>' +
'<span class="toot ' + spoiler + '">' + toot.content +
'</span><span class="gray cw_text_' + toot.id + '">' + toot.spoiler_text +
spoiler_show + '</span>' +
'' + viewer + '' +
'<div class="additional"></div><span class="cbadge"><i class="fa fa-clock-o"></i>' +
date(toot.created_at, datetype) + '</span>' +
'<span class="cbadge">via ' + via + '</span>' + mentions + tags +
'<div style="padding:0; margin:0; top:-20px; display:flex; justify-content:space-around; width:500px; max-width:100%; ">' +
'<div><a onclick="re(\'' + toot.id + '\',\'' + toot.account.acct + '\',' +
acct_id +
')" class="waves-effect waves-dark btn-flat" style="padding:0"><i class="fa fa-share"></i><help>返信</help></a></div>' +
'<div><a onclick="rt(\'' + toot.id + '\',' + acct_id +
')" class="waves-effect waves-dark btn-flat" style="padding:0"><i class="text-darken-3 fa fa-retweet ' +
if_rt + '" id="rt_' + toot.id + '"></i><span class="rt_ct">' + toot.reblogs_count +
'</span><help>ブースト</help></a></div>' +
'<div><a onclick="fav(\'' + toot.id + '\',' + acct_id +
')" class="waves-effect waves-dark btn-flat" style="padding:0"><i class="fa text-darken-3 fa-star' +
if_fav + '" id="fav_' + toot.id + '"></i><span class="fav_ct">' + toot.favourites_count +
'<help>お気に入り</help></a></span></div>' +
'<div class=' + if_mine + '><a onclick="del(\'' + toot.id + '\',' +
acct_id +
')" class="waves-effect waves-dark btn-flat" style="padding:0"><i class="fa fa-trash-o"></i><help>削除</help></a></div>' +
'<div><a onclick="details(\'' + toot.id + '\',' + acct_id +
')" class="waves-effect waves-dark btn-flat details" style="padding:0"><i class="text-darken-3 material-icons">more_vert</i><help>詳細表示</help></a></div>' +
'</div>' +
'<div class="divider"></div>' +
'</div>' +
'</div>';
} else if (eachobj.type == "follow") {
//フォロー等のユーザーデータである
var tooter = eachobj.account;
if (tooter.locked) {
var locked = ' <i class="fa fa-lock red-text"></i>';
} else {
var locked = "";
}
templete = templete +
'<div class="cvo " style="padding-top:5px;" notf-id=' + eachobj.id + '>' +
'<div style="padding:0; margin:0; width:400px; max-width:100%; display:flex; align-items:flex-end;">' +
'<div style="flex-basis:40px;"><a onclick="udg(\'' + tooter.id + '\',\'' +
acct_id + '\');" user="' + tooter.acct + '" class="udg">' +
'<img src="' + tooter.avatar + '" width="40" class="prof-img" user="' +
tooter.acct + '"></a></div>' +
'<div style="flex-grow:3; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">' +
tooter.display_name + '<div class="gray sharesta">にフォローされました</div></div>' +
'<div class="sml gray" style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"> @' +
tooter.acct + locked + '</div>' +
'</div>' +
'<div style="justify-content:space-around"> <div class="cbadge">Follows:' +
tooter.following_count + '</div><div class="cbadge">Followers:' + tooter.followers_count +
'</div>' +
'<div class="divider"></div>' +
'</div>' +
'</div>';
var noticetext = eachobj.account.display_name + "(" + eachobj.account.acct +
")がフォローしました";
if (popup >= 0 && obj.length < 5) {
Materialize.toast(noticetext, popup * 1000);
$(".notf-icon").addClass("red-text");
}
}
});
if (!noticetext) {
var noticetext = null;
}
return [templete, noticetext];
}

250
app/js/tl/parse.js Normal file
View File

@@ -0,0 +1,250 @@
//オブジェクトパーサー(トゥート)
function parse(obj, mix, acct_id) {
var templete = '';
var datetype = localStorage.getItem("datetype");
var nsfwtype = localStorage.getItem("nsfw");
var sent = localStorage.getItem("sentence");
if (!sent) {
var sent = 500;
}
if (!nsfwtype || nsfwtype == "yes") {
var nsfw = "ok";
} else {
var nsfw;
}
var cwtype = localStorage.getItem("cw");
if (!cwtype || cwtype == "yes") {
var cw = "ok";
} else {
var cw;
}
if (!datetype) {
datetype = "absolute";
}
var local = [];
Object.keys(obj).forEach(function(key) {
var toot = obj[key];
var id = toot.id;
//Integratedである場合はUnix時間をキーに配列を生成しておく
if (mix == "mix") {
local[date(obj[key].created_at, 'unix')] = toot.id;
}
if (mix == "home") {
var home = "Home TLより"
} else {
var home = "";
}
if (toot.reblog) {
var notice = toot.account.display_name + "(" + toot.account.acct +
")がブースト<br>";
var boostback = "shared";
var toot = toot.reblog;
} else {
var notice = "";
var boostback = "";
}
if (toot.account.locked) {
var locked = ' <i class="fa fa-lock red-text"></i>';
} else {
var locked = "";
}
if (!toot.application) {
var via = "<i>Unknown</i>";
} else {
var via = toot.application.name;
}
if (toot.spoiler_text && cw) {
var content = toot.content;
var spoil = toot.spoiler_text;
var spoiler = "cw cw_hide_" + toot.id;
var api_spoil = "gray";
var spoiler_show = '<a href="#" onclick="cw_show(\'' + toot.id +
'\')" class="nex parsed">見る</a>';
} else {
var ct = toot.content.split('</p>').length + toot.content.split('<br />').length -
2;
if (sent < ct && $.mb_strlen(toot.content) > 5) {
var content = '<span class="gray">以下全文</span><br>' + toot.content
var spoil = $.strip_tags($.mb_substr(toot.content, 0, 100)) +
'<span class="gray">自動折りたたみ</span>';
var spoiler = "cw cw_hide_" + toot.id;
var spoiler_show = '<a href="#" onclick="cw_show(\'' + toot.id +
'\')" class="nex parsed">続き…</a>';
} else {
var content = toot.content;
var spoil = toot.spoiler_text;
var spoiler = "";
var spoiler_show = "";
}
}
var viewer = "";
var youtube = "";
var emojick = toot.emojis[0];
//絵文字があれば
if (emojick) {
Object.keys(toot.emojis).forEach(function(key5) {
var emoji = toot.emojis[key5];
var shortcode = emoji.shortcode;
var emoji_url = '<img src="' + emoji.url +
'" style="width:2em" class="emoji-img">';
var regExp = new RegExp(":" + shortcode + ":", "g");
content = content.replace(regExp, emoji_url);
});
}
var mediack = toot.media_attachments[0];
//メディアがあれば
if (mediack) {
Object.keys(toot.media_attachments).forEach(function(key2) {
var media = toot.media_attachments[key2];
var purl = media.preview_url;
var url = media.url;
if (toot.sensitive && nsfw) {
var sense = "sensitive"
} else {
var sense = ""
}
viewer = viewer + '<a onclick="imgv(\''+id+'\',\''+key2+'\')" id="'+id+'-image-'+key2+'" data-url="'+url+'" data-type="'+media.type+'"><img src="' + purl + '" class="' + sense +
' toot-img" style=""></a></span>';
});
} else {
viewer = "";
}
var menck = toot.mentions[0];
var mentions = "";
//メンションであれば
if (menck) {
mentions = "Links: ";
Object.keys(toot.mentions).forEach(function(key3) {
var mention = toot.mentions[key3];
mentions = mentions + '<a onclick="udg(\'' + mention.id + '\',' +
acct_id + ')" class="pointer">@' + mention.acct + '</a> ';
});
}
var tagck = toot.tags[0];
var tags = "";
//タグであれば
if (tagck) {
if (!menck) {
tags = "Links: ";
}
Object.keys(toot.tags).forEach(function(key4) {
var tag = toot.tags[key4];
tags = tags + '<a onclick="tl(\'tag\',\'' + tag.name + '\',' + acct_id +
',\'add\')" class="pointer">#' + tag.name + '</a> ';
});
}
if (toot.account.acct == localStorage.getItem("user_" + acct_id)) {
var if_mine = "";
} else {
var if_mine = "hide";
}
if (toot.favourited) {
var if_fav = " yellow-text";
var fav_app = "faved";
} else {
var if_fav = "";
var fav_app = "";
}
if (toot.reblogged) {
var if_rt = "teal-text";
var rt_app = "rted";
} else {
var if_rt = "";
var rt_app = "";
}
templete = templete + '<div id="pub_' + toot.id + '" class="cvo ' +
boostback + ' ' + fav_app + ' ' + rt_app +
'" style="padding-top:5px;" toot-id="' + id + '" unixtime="' + date(obj[
key].created_at, 'unix') + '">' +
'<span class="gray sharesta">' + notice + home + '</span>' +
'<div style="padding:0; margin:0; width:400px; max-width:100%; display:flex; align-items:flex-end;">' +
'<div style="flex-basis:40px;"><a onclick="udg(\'' + toot.account.id +
'\',' + acct_id + ');" user="' + toot.account.acct + '" class="udg">' +
'<img src="' + toot.account.avatar +
'" width="40" class="prof-img" user="' + toot.account.acct +
'"></a></div>' +
'<div style="flex-grow:3; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"><big>' +
toot.account.display_name + '</big></div>' +
'<div class="sml gray" style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"> @' +
toot.account.acct + locked + '</div>' +
'</div>' +
'<div style="display:none; justify-content:space-around" class="sml gray"> <div>Follows:' +
toot.account.following_count + '</div><div>Followers:' + toot.account.followers_count +
'</div>' +
'<div>Toots:' + toot.account.statuses_count + '</div></div>' +
'<span class="toot ' + spoiler + '">' + content + '</span><span class="' +
api_spoil + ' cw_text_' + toot.id + '">' + spoil + spoiler_show +
'</span>' +
'' + viewer + '' +
'<div class="additional"></div><span class="cbadge"><i class="fa fa-clock-o"></i>' +
date(toot.created_at, datetype) + '</span>' +
'<span class="cbadge">via ' + via +
'<help class="white-text">どこから投稿したか</help></span>' + mentions + tags +
'<div style="padding:0; margin:0; top:-20px; display:flex; justify-content:space-around; width:500px; max-width:100%; ">' +
'<div><a onclick="re(\'' + toot.id + '\',\'' + toot.account.acct + '\',' +
acct_id +
')" class="waves-effect waves-dark btn-flat" style="padding:0"><i class="fa fa-share"></i></a></div>' +
'<div><a onclick="rt(\'' + toot.id + '\',' + acct_id +
')" class="waves-effect waves-dark btn-flat" style="padding:0"><i class="text-darken-3 fa fa-retweet ' +
if_rt + '" id="rt_' + toot.id + '"></i><span class="rt_ct">' + toot.reblogs_count +
'</span></a></div>' +
'<div><a onclick="fav(\'' + toot.id + '\',' + acct_id +
')" class="waves-effect waves-dark btn-flat" style="padding:0"><i class="fa text-darken-3 fa-star' +
if_fav + '" id="fav_' + toot.id + '"></i><span class="fav_ct">' + toot.favourites_count +
'</a></span></div>' +
'<div class=' + if_mine + '><a onclick="del(\'' + toot.id + '\',' +
acct_id +
')" class="waves-effect waves-dark btn-flat" style="padding:0"><i class="fa fa-trash-o"></i></a></div>' +
'<div><a onclick="details(\'' + toot.id + '\',' + acct_id +
')" class="waves-effect waves-dark btn-flat details" style="padding:0"><i class="text-darken-3 material-icons">more_vert</i></a></div>' +
'</div>' +
'<div class="divider"></div>' +
'</div>' +
'</div>';
});
if (mix == "mix") {
return [templete, local]
} else {
return templete;
}
}
//オブジェクトパーサー(ユーザーデータ)
function userparse(obj, auth) {
var templete = '';
Object.keys(obj).forEach(function(key) {
var toot = obj[key];
if (toot.locked) {
var locked = ' <i class="fa fa-lock red-text"></i>';
} else {
var locked = "";
}
if (auth) {
var auth = '<i class="material-icons gray pointer" onclick="request(\'' +
toot.id + '\',\'authorize\',' + acct_id + ')">person_add</i>';
} else {
var auth = "";
}
templete = templete +
'<div class="cvo " style="padding-top:5px;" user-id="' + toot.id + '">' +
'<div style="padding:0; margin:0; width:400px; max-width:100%; display:flex; align-items:flex-end;">' +
'<div style="flex-basis:40px;"><a onclick="udg(\'' + toot.id + '\',' +
acct_id + ');" user="' + toot.acct + '" class="udg">' +
'<img src="' + toot.avatar + '" width="40" class="prof-img" user="' + toot
.acct + '"></a></div>' +
'<div style="flex-grow:3; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"><big>' +
toot.display_name + '</big></div>' +
'<div class="sml gray" style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"> @' +
toot.acct + locked + '</div>' +
'</div>' + auth +
'<div style="justify-content:space-around"> <div class="cbadge">Follows:' +
toot.following_count + '</div><div class="cbadge">Followers:' + toot.followers_count +
'</div>' +
'<div class="divider"></div>' +
'</div>' +
'</div>';
});
return templete;
}

55
app/js/tl/src.js Normal file
View File

@@ -0,0 +1,55 @@
//検索
//検索ボックストグル
function srcToggle() {
$("#src-box").toggleClass("hide");
$('ul.tabs').tabs('select_tab', 'src-sta');
$("#src-contents").html("");
}
//検索取得
function src() {
var q = $("#src").val();
var acct_id = $("#src-acct-sel").val();
localStorage.setItem("last-use", acct_id);
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
if (user == "--now") {
var user = $('#his-data').attr("user-id");
}
var start = "https://" + domain + "/api/v1/search?q=" + q
console.log(start)
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) {
//トゥート
if (json.statuses[0]) {
var templete = parse(json.statuses);
$("#src-contents").append("Mentions<br>" + templete);
}
//アカウント
if (json.accounts[0]) {
var templete = userparse(json.accounts);
$("#src-contents").append("Accounts<br>" + templete);
}
//ハッシュタグ
if (json.hashtags[0]) {
var tags = "";
Object.keys(json.hashtags).forEach(function(key4) {
var tag = json.hashtags[key4];
tags = tags + '<a onclick="tl(\'tag\',\'' + tag + '\',\'' + acct_id +
'\',\'add\')" class="pointer">#' + tag + '</a><br> ';
});
$("#src-contents").append("Tags<br>" + tags);
}
jQuery("time.timeago").timeago();
});
}

240
app/js/tl/tl.js Normal file
View File

@@ -0,0 +1,240 @@
//TL取得
function tl(type, data, acct_id, tlid) {
scrollevent();
localStorage.removeItem("morelock");
localStorage.removeItem("pool");
//タグの場合はカラム追加して描画
if (tlid == "add") {
console.log("add");
var newtab = $(".box").length;
var add = {
domain: acct_id,
type: "tag",
data: data
};
var multi = localStorage.getItem("column");
var obj = JSON.parse(multi);
obj.push(add);
console.log(obj);
var json = JSON.stringify(obj);
localStorage.setItem("column", json);
parseColumn();
return;
}
if (!type) {
var type = localStorage.getItem("now");
if (!type) {
//デフォルト
var type = "local";
}
}
if (type == "mix") {
//Integratedなら飛ばす
mixtl(acct_id, tlid);
return;
} else if (type == "notf") {
//通知なら飛ばす
notf(acct_id, tlid, 'direct');
$("#notice_" + tlid).text(cap(type, data) + " TL(" + localStorage.getItem(
"user_" + acct_id) + "@" + domain + ")");
return;
}
localStorage.setItem("now", type);
todo(cap(type) + " TL Loading...");
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
$("#notice_" + tlid).text(cap(type, data) + " TL(" + localStorage.getItem(
"user_" + acct_id) + "@" + domain + ")");
var start = "https://" + domain + "/api/v1/timelines/" + com(type, data);
console.log(start);
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 templete = parse(json, '', acct_id);
$("#timeline_" + tlid).html(templete);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
todc();
reload(type, '', acct_id, tlid);
$(window).scrollTop(0);
});
}
//Streaming接続
function reload(type, cc, acct_id, tlid) {
if (!type) {
var type = localStorage.getItem("now");
}
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
localStorage.setItem("now", type);
if (type == "home") {
var start = "wss://" + domain +
"/api/v1/streaming/?stream=user&access_token=" + at;
} else if (type == "pub") {
var start = "wss://" + domain +
"/api/v1/streaming/?stream=public&access_token=" + at;
} else if (type == "local") {
var start = "wss://" + domain +
"/api/v1/streaming/?stream=public:local&access_token=" + at;
}
console.log(start);
var wsid = websocket.length;
websocket[wsid] = new WebSocket(start);
websocket[wsid].onopen = function(mess) {
console.log(tlid + ":Connect Streaming API:" + type);
console.log(mess);
}
websocket[wsid].onmessage = function(mess) {
console.log(tlid + ":Receive Streaming API:");
console.log(websocket[wsid]);
var typeA = JSON.parse(mess.data).event;
if (typeA == "delete") {
var obj = JSON.parse(mess.data).payload;
$("[toot-id=" + obj + "]").hide();
} else if (typeA == "update") {
var obj = JSON.parse(JSON.parse(mess.data).payload);
console.log(obj);
var templete = parse([obj], '', acct_id);
var pool = localStorage.getItem("pool_" + tlid);
if (pool) {
pool = templete + pool;
} else {
pool = templete
}
localStorage.setItem("pool_" + tlid, pool);
scrollck();
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
todc();
}
websocket[wsid].onclose = function(mess) {
console.log("Close Streaming API:" + type);
}
}
websocket[wsid].onerror = function(error) {
console.error('WebSocket Error ' + error);
};
}
//一定のスクロールで発火
function moreload(type, tlid) {
var multi = localStorage.getItem("column");
var obj = JSON.parse(multi);
var acct_id = obj[tlid].domain;
if (!type) {
var type = localStorage.getItem("now");
}
var sid = $("#timeline_" + tlid + " .cvo").last().attr("toot-id");
console.log(localStorage.getItem("morelock") + ":" + sid)
if (localStorage.getItem("morelock") != sid) {
localStorage.setItem("morelock", sid);
if (type == "mix") {
mixmore();
return;
}
localStorage.setItem("now", type);
todo(cap(type) + " TL MoreLoading");
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/timelines/" + com(type) +
"max_id=" + sid;
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 templete = parse(json, '', acct_id);
$("#timeline_" + tlid).append(templete);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
todc();
});
}
}
//WebSocket切断
function tlCloser() {
Object.keys(websocket).forEach(function(tlid) {
if (websocketOld[tlid]) {
websocketOld[tlid].close();
console.log("Close Streaming API: Old" + tlid);
}
if (websocket[0]) {
console.log(websocket[0]);
websocket[tlid].close();
console.log("Close Streaming API:" + tlid);
}
});
websocket = [];
Object.keys(websocketHome).forEach(function(tlid) {
if (websocketHome[tlid]) {
websocketHome[tlid].close();
console.log("Close Streaming API:MixHome" + tlid);
}
});
websocketHome = [];
Object.keys(websocketLocal).forEach(function(tlid) {
if (websocketLocal[tlid]) {
websocketLocal[tlid].close();
console.log("Close Streaming API:MixLocal" + tlid);
}
});
websocketLocal = [];
}
//TLのタイトル
function cap(type, data) {
if (type == "home") {
return "Home"
} else if (type == "local") {
return "Local"
} else if (type == "pub") {
return "Public"
} else if (type == "tag") {
return "#" + data
} else if (type == "list") {
return "List(id:" + data + ")"
} else if (type == "notf") {
return "Notification"
}
}
//TLのURL
function com(type, data) {
if (type == "home") {
return "home?"
} else if (type == "local") {
return "public?local=true&"
} else if (type == "pub") {
return "public?"
} else if (type == "tag") {
return "tag/" + data + "?"
}
if (type == "list") {
return "list/" + data + "?"
}
}