thedesk/app/js/tl/card.js

285 lines
8.6 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
//カード処理やメンション、ハッシュタグの別途表示
//全てのTL処理で呼び出し
function additional(acct_id, tlid) {
//メンション系
2018-05-12 04:12:25 +10:00
//$(".mention").attr("href", "");
2018-02-05 02:09:20 +11:00
$(".mention").addClass("parsed");
2018-05-12 04:12:25 +10:00
$(".hashtag").each(function(i, elem) {
var tags = $(this).attr("href").match(
/https?:\/\/([-a-zA-Z0-9@.]+)\/tags\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/
);
$(this).attr("href","#");
if(tags){
if(tags[2]){
$(this).attr("onclick",'tagShow(\'' + tags[2] + '\')');
}
}
});
2018-01-28 23:22:43 +11:00
//トゥートサムネ
$("#timeline_" + tlid + " .toot a:not(.parsed)").each(function(i, elem) {
var domain = localStorage.getItem("domain_" + acct_id);
2018-07-07 03:51:48 +10:00
var at = localStorage.getItem("acct_"+ acct_id + "_at");
2018-01-28 23:22:43 +11:00
var card = localStorage.getItem("card_" + tlid);
var text = $(this).attr('href');
2018-08-17 03:21:40 +10:00
if(text){
2018-08-21 04:26:14 +10:00
if(text.indexOf("twimg.com")=== -1){
var urls = text.match(
/https?:\/\/([-a-zA-Z0-9@.]+)\/media\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/
);
}
2018-08-17 03:21:40 +10:00
}else{
var urls =[]
}
2018-04-09 00:17:33 +10:00
//トゥートのURLぽかったら
toot = text.match(/https:\/\/([a-zA-Z0-9.-]+)\/@([a-zA-Z0-9_]+)\/([0-9]+)/);
if(toot){
if(toot[1]){
$(this).attr("data-acct",acct_id);
}
}
2018-01-28 23:22:43 +11:00
if (urls) {
$(this).remove();
} else if (!card) {
var id = $(this).parents('.cvo').attr("toot-id");
2018-08-23 03:29:39 +10:00
if(localStorage.getItem("mode_" + domain)=="misskey"){
2018-08-17 03:21:40 +10:00
var start = "https://" + domain + "/url?url="+text;
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json'
},
//body: JSON.stringify({})
}).then(function(response) {
return response.json();
}).catch(function(error) {
todo(error);
console.error(error);
}).then(function(json) {
if (json.title) {
$("[toot-id=" + id + "] .additional").html(
2019-01-26 14:24:26 +11:00
"<span class=\"gray\">URL"+lang.lang_cards_check+":<br>Title:" + json.title + "<br>" +
2018-08-17 03:21:40 +10:00
json.description + "</span>");
$("[toot-id=" + id + "] a:not(.parsed)").addClass("parsed");
$("[toot-id=" + id + "]").addClass("parsed");
}
});
}
2018-02-05 01:56:31 +11:00
}else{
$(this).attr("title",text);
2018-01-28 23:22:43 +11:00
}
});
2018-03-18 02:00:53 +11:00
$("i.unparsed").each(function(i, elem) {
var dem=$(this).text();
var dom=$(this);
var start = "./js/emoji/emoji-map.json";
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.onreadystatechange = function()
{
2019-03-08 05:19:26 +11:00
if( this.readyState === 4 && this.status === 200 ) {
2018-03-18 02:00:53 +11:00
if( this.response){
var json=this.response;
var emojis=json.emojis;
for (i = 0; i < emojis.length; i++) {
var emojie = emojis[i];
var regExp = new RegExp(dem, "g");
if (emojie.emoji.match(regExp)) {
var sc=emojie.name;
var sc="twa-"+sc.replace(/_/g,"-");
dom.addClass(sc);
dom.text("");
dom.removeClass("unparsed");
break;
}
}
}
}
}
xmlHttpRequest.open( 'GET', start, true );
xmlHttpRequest.responseType = 'json';
xmlHttpRequest.send( null );
});
2018-02-05 02:09:20 +11:00
$("#timeline_" + tlid + " .toot:not(:has(a:not(.add-show,.parsed)))").each(function(i, elem) {
2018-02-05 01:56:31 +11:00
$(this).parent().find(".add-show").hide();
});
2018-01-31 03:43:01 +11:00
//Markdownイメージビューワー
$("#timeline_" + tlid + " .toot a:not(.img-parsed):has(img)").each(function(i, elem) {
var ilink=$(this).attr("href");
var id = $(this).parents('.cvo').attr("toot-id");
$(this).attr("href","#");
$(this).attr("onclick","imgv('"+id+"','"+i+"')");
$(this).attr("data-type","image");
$(this).attr("id",id+"-image-"+i);
$(this).attr("data-url",ilink);
$(this).addClass("img-parsed");
});
2018-01-28 23:22:43 +11:00
}
2018-02-05 01:56:31 +11:00
function additionalIndv(tlid, acct_id, id) {
var domain = localStorage.getItem("domain_" + acct_id);
2018-07-07 03:51:48 +10:00
var at = localStorage.getItem("acct_"+ acct_id + "_at");
2018-02-05 01:56:31 +11:00
var text = $("[toot-id="+id+"] .toot a").attr('href');
var urls = text.match(
/https?:\/\/([-a-zA-Z0-9@.]+)\/media\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/
);
if (urls) {
$("[toot-id="+id+"] .toot a").remove();
} else {
2018-08-23 03:29:39 +10:00
if(localStorage.getItem("mode_" + domain)=="misskey"){
2018-08-17 03:21:40 +10:00
var start = "https://" + domain + "/url?url="+text;
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json'
},
//body: JSON.stringify({})
}).then(function(response) {
return response.json();
}).catch(function(error) {
todo(error);
console.error(error);
}).then(function(json) {
2018-07-22 23:03:46 +10:00
if (json.title) {
$("[toot-id=" + id + "] .additional").html(
2019-01-26 14:24:26 +11:00
"<span class=\"gray\">URL"+lang.lang_cards_check+":<br>Title:" + json.title + "<br>" +
2018-07-22 23:03:46 +10:00
json.description + "</span>");
2018-08-17 03:21:40 +10:00
$("[toot-id=" + id + "] a:not(.parsed)").addClass("parsed");
$("[toot-id=" + id + "]").addClass("parsed");
2018-07-22 23:03:46 +10:00
}
2018-08-17 03:21:40 +10:00
});
}else{
var id = $("[toot-id="+id+"] .toot a").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);
//このリンク鳥やんけ、ってとき
console.log(json.provider_name);
if (json.provider_name=="Twitter"){
if(json.image){
var twiImg='<br><img src="'+json.image+'" style="max-width:100%" onclick="imgv(\'twi_'+id+'\', 0, \'twitter\');" id="twi_'+id+'-image-0" data-url="'+json.image+'" data-type="image">';
}else{
var twiImg='';
}
$("[toot-id=" + id + "] .additional").html(
2018-08-29 20:17:34 +10:00
'<div class="twitter-tweet"><b>'+escapeHTML(json.author_name)+'</b><br>'+escapeHTML(json.description)+twiImg+'</div>');
2018-08-17 03:21:40 +10:00
}else if (json.provider_name=="pixiv"){
if(json.image){
var pxvImg='<br><img src="'+json.image+'" style="max-width:100%" onclick="imgv(\'pixiv_'+id+'\', 0, \'pixiv\');" id="pixiv_'+id+'-image-0" data-url="'+json.embed_url+'" data-type="image">';
}else{
var pxvImg='';
}
$("[toot-id=" + id + "] .additional").html(
2018-08-29 20:17:34 +10:00
'<div class="pixiv-post"><b><a href="'+json.author_url+'" target="_blank">'+escapeHTML(json.author_name)+'</a></b><br>'+escapeHTML(json.title)+pxvImg+'</div>');
2018-08-17 03:21:40 +10:00
}else{
if (json.title) {
$("[toot-id=" + id + "] .additional").html(
2019-01-26 14:24:26 +11:00
"<span class=\"gray\">URL"+lang.lang_cards_check+":<br>Title:" + escapeHTML(json.title) + "<br>" +
2018-08-29 20:17:34 +10:00
escapeHTML(json.description) + "</span>");
2018-08-17 03:21:40 +10:00
}
if (json.html) {
2019-01-26 14:24:26 +11:00
$("[toot-id=" + id + "] .additional").html(json.html+'<i class="material-icons sml pointer" onclick="pip(\''+id+'\')" title="'+lang.lang_cards_pip+'">picture_in_picture_alt</i>');
2018-08-17 03:21:40 +10:00
}
}
if (json.title) {
$("[toot-id=" + id + "] a:not(.parsed)").addClass("parsed");
$("[toot-id=" + id + "]").addClass("parsed");
2018-07-22 23:03:46 +10:00
}
2018-08-17 03:21:40 +10:00
});
}
2018-02-05 01:56:31 +11:00
}
}
2018-01-28 23:22:43 +11:00
//各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");
2018-02-13 06:16:46 +11:00
$("#sta-card-" + tlid).css("color",'red');
2018-01-28 23:22:43 +11:00
} else {
localStorage.removeItem("card_" + tlid);
$("#sta-card-" + tlid).text("On");
2018-02-13 06:16:46 +11:00
$("#sta-card-" + tlid).css("color",'#009688');
2018-01-28 23:22:43 +11:00
}
}
//各TL上方のLink[On/Off]をチェック
function cardCheck(tlid) {
var card = localStorage.getItem("card_" + tlid);
if (!card) {
$("#sta-card-" + tlid).text("On");
2018-02-13 06:16:46 +11:00
$("#sta-card-" + tlid).css("color",'#009688');
2018-01-28 23:22:43 +11:00
} else {
$("#sta-card-" + tlid).text("Off");
2018-02-13 06:16:46 +11:00
$("#sta-card-" + tlid).css("color",'red');
2018-01-28 23:22:43 +11:00
}
}
2018-05-02 14:14:03 +10:00
2018-08-17 03:21:40 +10:00
function mov(id,tlid,type){
2018-05-02 14:14:03 +10:00
if(tlid=="notf"){
var tlide="[data-notf="+acct_id+"]";
2018-09-11 04:59:44 +10:00
}else if(tlid=="user"){
var tlide="#his-data";
2018-05-02 14:14:03 +10:00
}else{
var tlide="[tlid="+tlid+"]";
}
2018-09-11 04:59:44 +10:00
console.log(tlid)
2018-05-02 14:14:03 +10:00
var mouseover=localStorage.getItem("mouseover");
if(!mouseover){
mouseover="";
2018-08-17 03:21:40 +10:00
}
if(mouseover=="yes"){
2018-05-02 14:14:03 +10:00
mouseover="hide";
2018-08-17 03:21:40 +10:00
}else if(mouseover=="click"){
if(type=="mv"){
mouseover="";
}else{
mouseover="hide";
}
2018-05-02 14:14:03 +10:00
}else if(mouseover=="no"){
mouseover="";
}
if(mouseover=="hide"){
2018-08-17 03:21:40 +10:00
$(tlide+" [toot-id="+id+"] .area-actions").toggleClass("hide")
2018-08-21 04:26:14 +10:00
$(tlide+" [toot-id="+id+"] .area-side").toggleClass("hide")
2018-05-02 14:14:03 +10:00
}
}
2018-08-17 03:21:40 +10:00
function resetmv(type){
2018-05-02 14:14:03 +10:00
var mouseover=localStorage.getItem("mouseover");
if(!mouseover){
mouseover="";
}else if(mouseover=="yes"){
mouseover="hide";
}else if(mouseover=="no"){
mouseover="";
2018-08-17 03:21:40 +10:00
}else if(mouseover=="click" && type!="mv"){
mouseover="hide";
2018-05-02 14:14:03 +10:00
}
if(mouseover=="hide"){
$(".area-actions").addClass("hide");
2018-08-21 04:26:14 +10:00
$(".area-side").addClass("hide");
2018-05-02 14:14:03 +10:00
}
}