//オブジェクトパーサー(トゥート)
function parse(obj, mix, acct_id, tlid, popup, mutefilter) {
var templete = '';
var actb = localStorage.getItem("action_btns");
var actb='re,rt,fav,qt,del,pin,red';
if(actb){
var actb = actb.split(',');
var disp={};
for(var k=0;k';
var regExp = new RegExp(":" + shortcode + ":", "g");
dis_name = dis_name.replace(regExp, emoji_url);
});
}
if (mix == "notf") {
if (toot.type == "mention") {
var what = "が返信しました";
var icon = "fa-share teal-text";
} else if (toot.type == "reblog") {
var what = "がブーストしました";
var icon = "fa-retweet light-blue-text";
if(localStorage.getItem("domain_" + acct_id)=="imastodon.net" && !locale){
what = ":「わかるわ」";
}else if(localStorage.getItem("domain_" + acct_id)=="mstdn.osaka" && !locale){
what = "がしばきました";
}
} else if (toot.type == "favourite") {
var what = "がお気に入り登録しました";
var icon = "fa-star yellow-text";
if(localStorage.getItem("domain_" + acct_id)=="imastodon.net" && !locale){
what = "の頭にティンときたようです";
}else if(localStorage.getItem("domain_" + acct_id)=="mstdn.osaka" && !locale){
what = "がええやんと言いました";
}
}
var noticetext = '' + date(toot.created_at,
datetype) +
'' + dis_name +
"(@" + toot.account.acct +
")";
var notice = noticetext;
var memory = localStorage.getItem("notice-mem");
if (popup >= 0 && obj.length < 5 && noticetext != memory) {
var domain = localStorage.getItem("domain_" + acct_id);
if(popup>0){
Materialize.toast("["+domain+"より]"+escapeHTML(toot.account.display_name)+what, popup * 1000);
}
if(native=="yes"){
var electron = require("electron");
var ipc = electron.ipcRenderer;
var os = electron.remote.process.platform;
var options = {
body: toot.account.display_name+"(" + toot.account.acct +")"+what+"\n\n"+$.strip_tags(toot.status.content),
icon: toot.account.avatar
};
if(os=="darwin"){
var n = new Notification('TheDesk:'+domain, options);
}else{
ipc.send('native-notf', ['TheDesk:'+domain,toot.account.display_name+"(" + toot.account.acct +")"+what+"\n\n"+$.strip_tags(toot.status.content),toot.account.avatar]);
}
}
$(".notf-icon_" + acct_id).addClass("red-text");
localStorage.setItem("notice-mem", noticetext);
noticetext = "";
}
var if_notf='data-notfIndv="'+acct_id+"_"+toot.id+'"';
var toot = toot.status;
var dis_name=escapeHTML(toot.account.display_name);
if(toot.account.emojis){
var actemojick = toot.account.emojis[0];
}else{
var actemojick=false;
}
//絵文字があれば
if (actemojick) {
Object.keys(toot.account.emojis).forEach(function(key5) {
var emoji = toot.account.emojis[key5];
var shortcode = emoji.shortcode;
var emoji_url = '';
var regExp = new RegExp(":" + shortcode + ":", "g");
dis_name = dis_name.replace(regExp, emoji_url);
});
}
}else{
var if_notf="";
if (toot.reblog) {
var rebtxt = "がブースト";
var rticon = "fa-retweet light-blue-text";
if(localStorage.getItem("domain_" + acct_id)=="imastodon.net" && !locale){
rebtxt = ":「わかるわ」";
}else if(localStorage.getItem("domain_" + acct_id)=="mstdn.osaka" && !locale){
rebtxt = "がしばいた";
}
var notice = ''+ dis_name + "(@" + toot.account.acct +
")
";
var boostback = "shared";
var uniqueid=toot.id;
var toot = toot.reblog;
var dis_name=escapeHTML(toot.account.display_name);
if(toot.account.emojis){
var actemojick = toot.account.emojis[0];
}else{
var uniqueid=toot.id;
var actemojick=false;
}
//絵文字があれば
if (actemojick) {
Object.keys(toot.account.emojis).forEach(function(key5) {
var emoji = toot.account.emojis[key5];
var shortcode = emoji.shortcode;
var emoji_url = '';
var regExp = new RegExp(":" + shortcode + ":", "g");
dis_name = dis_name.replace(regExp, emoji_url);
});
}
} else {
var uniqueid=toot.id;
var notice = "";
var boostback = "";
//ユーザー強調
if(toot.account.username!=toot.account.acct){
var fullname=toot.account.acct;
}else{
var domain = localStorage.getItem("domain_" + acct_id);
var fullname=toot.account.acct+"@"+domain;
}
if(useremp){
Object.keys(useremp).forEach(function(key10) {
var user = useremp[key10];
if(user==fullname){
boostback = "emphasized";
}
});
}
}
}
var id = toot.id;
if (mix == "home") {
var home = ""
var divider = '';
} else {
var home = "";
var divider = '';
}
if (toot.account.locked) {
var locked = ' ';
} else {
var locked = "";
}
if (!toot.application) {
var via = 'Unknown';
} else {
var via = toot.application.name;
//強調チェック
Object.keys(emp).forEach(function(key6) {
var cli = emp[key6];
if(cli == via){
boostback = "emphasized";
}
});
//ミュートチェック
Object.keys(mute).forEach(function(key7) {
var cli = mute[key7];
if(cli == via){
boostback = "hide";
}
});
}
if (toot.spoiler_text && cw) {
var content = toot.content;
var spoil = escapeHTML(toot.spoiler_text);
var spoiler = "cw cw_hide_" + toot.id;
var api_spoil = "gray";
var spoiler_show = '見る
';
} else {
var ct1 = toot.content.split('
').length + toot.content.split('
').length -2;
var ct2 = toot.content.split('').length + toot.content.split('
').length -2;
if(ct1>ct2){ var ct= ct1; }else{ var ct= ct2; }
if ((sent < ct && $.mb_strlen($.strip_tags(toot.content)) > 5) || ($.strip_tags(toot.content).length > ltr && $.mb_strlen($.strip_tags(toot.content)) > 5)) {
var content = '以下全文
' + toot.content
var spoil = '' + $.mb_substr($.strip_tags(
toot.content), 0, 100) +
'自動折りたたみ';
var spoiler = "cw cw_hide_" + toot.id;
var spoiler_show = '続き…
';
} else {
var content = toot.content;
var spoil = escapeHTML(toot.spoiler_text);
var spoiler = "";
var spoiler_show = "";
}
}
var urls = $.strip_tags(content).replace(/\n/g, " ").match(
/https?:\/\/([-a-zA-Z0-9@.]+)\/?(?!.*((media|tags)|mentions)).*([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)?/
);
if (urls) {
var analyze = 'URL解析
';
} else {
var analyze = '';
}
var viewer = "";
var hasmedia = "";
var youtube = "";
if(toot.emojis){
var emojick = toot.emojis[0];
}else{
var emojick=false;
}
//絵文字があれば
if (emojick) {
Object.keys(toot.emojis).forEach(function(key5) {
var emoji = toot.emojis[key5];
var shortcode = emoji.shortcode;
var emoji_url = '';
var regExp = new RegExp(":" + shortcode + ":", "g");
content = content.replace(regExp, emoji_url);
spoil = spoil.replace(regExp, emoji_url);
});
}
//デフォ絵文字
content=twemoji.parse(content);
if(dis_name){
dis_name=twemoji.parse(dis_name);
}
if(spoil){
spoil=twemoji.parse(spoil);
}
if(noticetext){
noticetext=twemoji.parse(noticetext);
}
if(notice){
notice=twemoji.parse(notice);
}
var mediack = toot.media_attachments[0];
//メディアがあれば
var media_ids="";
if (mediack) {
hasmedia = "hasmedia";
var cwdt = 100 / toot.media_attachments.length;
Object.keys(toot.media_attachments).forEach(function(key2) {
var media = toot.media_attachments[key2];
var purl = media.preview_url;
media_ids=media_ids+media.id+",";
var url = media.url;
if (toot.sensitive && nsfw) {
var sense = "sensitive"
} else {
var sense = ""
}
viewer = viewer + '';
});
media_ids = media_ids.slice(0, -1) ;
} else {
viewer = "";
hasmedia = "nomedia";
}
var menck = toot.mentions[0];
var mentions = "";
//メンションであれば
if (menck) {
mentions = "";
Object.keys(toot.mentions).forEach(function(key3) {
var mention = toot.mentions[key3];
mentions = mentions + '@' + mention.acct + ' ';
});
mentions = '' + mentions + '
';
}
var tagck = toot.tags[0];
var tags = "";
//タグであれば
if (tagck) {
Object.keys(toot.tags).forEach(function(key4) {
var tag = toot.tags[key4];
tags = tags + '#' + tag.name + ':TL Toot '+
'Pin ';
});
tags = '' + tags + '
';
}
//公開範囲を取得
var vis = "";
var visen = toot.visibility;
if (visen == "public") {
var vis =
'public';
var can_rt = "";
} else if (visen == "unlisted") {
var vis =
'lock_open';
var can_rt = "";
} else if (visen == "private") {
var vis =
'lock';
var can_rt = "hide";
} else if (visen == "direct") {
var vis =
'mail';
var can_rt = "hide";
}
if (toot.account.acct == localStorage.getItem("user_" + acct_id)) {
var if_mine = "";
var mine_via="type-b";
} else {
var if_mine = "hide";
var mine_via="";
}
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.pinned) {
var if_pin = "blue-text";
var pin_app = "pinned";
} else {
var if_pin = "";
var pin_app = "";
}
//アニメ再生
if (gif == "yes") {
var avatar = toot.account.avatar;
} else {
var avatar = toot.account.avatar_static;
}
//ワードミュート
if(wordmute){
Object.keys(wordmute).forEach(function(key8) {
var worde = wordmute[key8];
if(worde){
if(worde.tag){
var word=worde.tag;
}else{
var word=worde
}
var regExp = new RegExp( word, "g" ) ;
if($.strip_tags(content).match(regExp)){
boostback = "hide by_filter";
}
}
});
}
//ワード強調
if(wordemp){
Object.keys(wordemp).forEach(function(key9) {
var word = wordemp[key9];
if(word){
var word=word.tag;
var regExp = new RegExp( word, "g" ) ;
content=content.replace(regExp,''+word+"");
}
});
}
//日本語じゃない
if(toot.language!="ja"){
var trans='';
}else{
var trans="";
}
templete = templete + '' +
'';
});
if (mix == "mix") {
return [templete, local, times]
} else {
return templete;
}
}
//オブジェクトパーサー(ユーザーデータ)
function userparse(obj, auth, acct_id, tlid, popup) {
//独自ロケール
var locale = localStorage.getItem("locale");
if(locale=="yes"){
var locale=false;
}
var templete = '';
var datetype = localStorage.getItem("datetype");
Object.keys(obj).forEach(function(key) {
var toot = obj[key];
if (toot.locked) {
var locked = ' ';
} else {
var locked = "";
}
if (auth) {
var auth = 'person_add';
} else {
var auth = "";
}
var ftxt="フォローされました";
if(localStorage.getItem("domain_" + acct_id)=="imastodon.net" && !locale){
ftxt = "名刺をいただきました";
}else if(localStorage.getItem("domain_" + acct_id)=="mstdn.osaka" && !locale){
ftxt = "ツルまれました";
}
if(popup > 0 || popup==-1){
var notftext='' + date(toot.created_at,
datetype) +
''+ftxt+'。
';
}else{
var notftext="";
}
var memory = localStorage.getItem("notice-mem");
if (popup >= 0 && obj.length < 5 && noticetext != memory) {
Materialize.toast(escapeHTML(toot.display_name)+"に"+ftxt, popup * 1000);
$(".notf-icon_" + tlid).addClass("red-text");
localStorage.setItem("notice-mem", noticetext);
noticetext = "";
}
var dis_name=escapeHTML(toot.display_name);
if(toot.emojis){
var actemojick = toot.emojis[0];
}else{
var actemojick=false;
}
//絵文字があれば
if (actemojick) {
Object.keys(toot.emojis).forEach(function(key5) {
var emoji = toot.emojis[key5];
var shortcode = emoji.shortcode;
var emoji_url = '';
var regExp = new RegExp(":" + shortcode + ":", "g");
dis_name = dis_name.replace(regExp, emoji_url);
});
}
dis_name=twemoji.parse(dis_name);
templete = templete +
'' +
notftext +
'
' +
'
' +
'
' +
dis_name + '
' +
'
@' +
toot.acct + locked + '
' +
'
' + auth +
'
Follows:' +
toot.following_count +
'
Followers:' + toot.followers_count +
'
' +
'
' +
'
' +
'
';
});
return templete;
}
//クライアントダイアログ
function client(name) {
if(name!="Unknown"){
//聞く
localStorage.removeItem("client_mute");
var electron = require("electron");
var remote=electron.remote;
var dialog=remote.dialog;
const options = {
type: 'info',
title: 'クライアント処理',
message: name+"に対する処理を選択してください。",
buttons: ['何もしない','強調表示/解除', 'ミュート']
}
dialog.showMessageBox(options, function(arg) {
if(arg==1){
var cli = localStorage.getItem("client_emp");
var obj = JSON.parse(cli);
if(!obj){
var obj=[];
obj.push(name);
Materialize.toast(name+"を強調表示します。", 2000);
}else{
var can;
Object.keys(obj).forEach(function(key) {
var cliT = obj[key];
if(cliT!=name && !can){
can=false;
}else{
can=true;
obj.splice(key, 1);
Materialize.toast(name+"の強調表示を解除しました。", 2000);
}
});
if(!can){
obj.push(name);
Materialize.toast(name+"を強調表示します。", 2000);
}else{
}
}
var json = JSON.stringify(obj);
localStorage.setItem("client_emp", json);
}else if(arg==2){
var cli = localStorage.getItem("client_mute");
var obj = JSON.parse(cli);
if(!obj){
var obj=[];
}
obj.push(name);
var json = JSON.stringify(obj);
localStorage.setItem("client_mute", json);
Materialize.toast(name+"をミュートします。設定から削除できます。", 2000);
}else{
return;
}
parseColumn();
})
}
}