//オブジェクトパーサー(トゥート) function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) { var templete = ''; if (obj[0]) { if (tlid === 1) { } localStorage.setItem("lastunix_" + tlid, date(obj[0].created_at, 'unix')); } var actb = 're,rt,fav,qt,del,pin,red'; if (actb) { var actb = actb.split(','); var disp = {}; for (var k = 0; k < actb.length; k++) { if (k < 4) { var tp = "type-a"; } else { var tp = "type-b"; } disp[actb[k]] = tp; } } var qt = localStorage.getItem("quote"); if (qt == "nothing" || !qt) { var qtClass = "hide"; } else { var qtClass = ""; } var datetype = localStorage.getItem("datetype"); var nsfwtype = localStorage.getItem("nsfw"); var sent = localStorage.getItem("sentence"); var ltr = localStorage.getItem("letters"); var gif = localStorage.getItem("gif"); var imh = localStorage.getItem("img-height"); if (!imh) { imh = 200; } if (imh == "full") { imh = "auto"; } else { imh = imh + "px"; } //独自ロケール var locale = localStorage.getItem("locale"); if (locale == "yes") { var locale = false; } //ネイティブ通知 var native = localStorage.getItem("nativenotf"); if (!native) { native = "yes"; } //クライアント強調 var emp = localStorage.getItem("client_emp"); if (emp) { var emp = JSON.parse(emp); } //クライアントミュート var mute = localStorage.getItem("client_mute"); if (mute) { var mute = JSON.parse(mute); } //ユーザー強調 var useremp = localStorage.getItem("user_emp"); if (useremp) { var useremp = JSON.parse(useremp); } //ワード強調 var wordemp = localStorage.getItem("word_emp"); if (wordemp) { var wordemp = JSON.parse(wordemp); } //ワードミュート var wordmute = localStorage.getItem("word_mute"); if (wordmute) { var wordmute = JSON.parse(wordmute); wordmute = wordmute.concat(mutefilter); } else { wordmute = mutefilter; } //Ticker var tickerck = localStorage.getItem("ticker_ok"); if (tickerck) { var ticker = true; } else { var ticker = false; } //Animation var anime = localStorage.getItem("animation"); if (anime == "yes" || !anime) { var animecss = "cvo-anime"; } else { var animecss = ""; } //Cards var card = localStorage.getItem("card_" + tlid); if (!sent) { sent = 500; } if (!ltr) { var ltr = 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"; } if (!gif) { var gif = "yes"; } if (!imh) { var imh = "200"; } if (!emp) { var emp = []; } if (!mute) { var mute = []; } if (!useremp) { var useremp = []; } if (!wordemp) { var wordemp = []; } if (!wordmute) { var wordmute = []; } //via通知 var viashow = localStorage.getItem("viashow"); if (!viashow) { viashow = "via-hide"; } if (viashow == "hide") { viashow = "via-hide"; } //認証なしTL if (mix == "noauth") { var noauth = "hide"; var antinoauth = ""; } else { var noauth = ""; var antinoauth = "hide"; } //DMTL if (type == "dm") { var dmHide = "hide"; var antidmHide = ""; } else { var dmHide = ""; var antidmHide = "hide"; } //マウスオーバーのみ var mouseover = localStorage.getItem("mouseover"); if (!mouseover) { mouseover = ""; } else if (mouseover == "yes" || mouseover == "click") { mouseover = "hide"; } else if (mouseover == "no") { mouseover = ""; } //リプカウント var replyct_view = localStorage.getItem("replyct"); if (!replyct_view) { replyct_view = "hidden"; } var local = []; var times = []; Object.keys(obj).forEach(function (key) { var toot = obj[key]; if (type == "dm") { var dmid = toot.id; toot = toot.last_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 = ' :' + shortcode + ': '; var regExp = new RegExp(":" + shortcode + ":", "g"); dis_name = dis_name.replace(regExp, emoji_url); }); } var noticeavatar = ""; if (mix == "notf") { if (gif == "yes") { noticeavatar = toot.account.avatar; } else { noticeavatar = toot.account.avatar_static; } noticeavatar = '' + ''; if (toot.type == "mention") { var what = lang.lang_parse_mentioned; var icon = "fa-share teal-text"; noticeavatar = ""; } else if (toot.type == "reblog") { var what = lang.lang_parse_bted; var icon = "fa-retweet light-blue-text"; if (!locale && localStorage.getItem("bt_" + acct_id)) { what = localStorage.getItem("bt_" + acct_id); } } else if (toot.type == "favourite") { var what = lang.lang_parse_faved; var icon = "fa-star yellow-text"; if (!locale && localStorage.getItem("fav_" + acct_id)) { what = localStorage.getItem("fav_" + acct_id); } } else if (toot.type == "poll") { var what = lang.lang_parse_polled; var icon = "fa-tasks purple-text"; } if (tlid == "notf") { var notfFilHide = "hide" } else { var notfFilHide = "" } 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) { if (localStorage.getItem("hasNotfC_" + acct_id) != "true") { if (toot.type == "mention") { var replyct = localStorage.getItem("notf-reply_" + acct_id) $(".notf-reply_" + acct_id).text(replyct * 1 - (-1)); localStorage.setItem("notf-reply_" + acct_id, replyct * 1 - (-1)) $(".notf-reply_" + acct_id).removeClass("hide") var sound = localStorage.getItem("replySound"); if (sound == "default") { var file = "../../source/notif3.wav" } } else if (toot.type == "reblog") { var btct = localStorage.getItem("notf-bt_" + acct_id) $(".notf-bt_" + acct_id).text(btct * 1 - (-1)); localStorage.setItem("notf-bt_" + acct_id, btct * 1 - (-1)) $(".notf-bt_" + acct_id).removeClass("hide") var sound = localStorage.getItem("btSound"); if (sound == "default") { var file = "../../source/notif2.wav" } } else if (toot.type == "favourite") { var favct = localStorage.getItem("notf-fav_" + acct_id) $(".notf-fav_" + acct_id).text(favct * 1 - (-1)); localStorage.setItem("notf-fav_" + acct_id, favct * 1 - (-1)) $(".notf-fav_" + acct_id).removeClass("hide") var sound = localStorage.getItem("favSound"); if (sound == "default") { var file = "../../source/notif.wav" } } } var domain = localStorage.getItem("domain_" + acct_id); if (popup > 0) { M.toast({ html: "[" + domain + "]" + escapeHTML(toot.account.display_name) + what, displayLength: popup * 1000 }) } //通知音 if (sound == "c1") { var file = localStorage.getItem("custom1"); } else if (sound == "c2") { var file = localStorage.getItem("custom2"); } else if (sound == "c3") { var file = localStorage.getItem("custom3"); } else if (sound == "c4") { var file = localStorage.getItem("custom4"); } if (file) { request = new XMLHttpRequest(); request.open("GET", file, true); request.responseType = "arraybuffer"; request.onload = playSound; request.send(); } if (native == "yes") { var os = localStorage.getItem("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 { var nativeNotfOpt = [ 'TheDesk:' + domain, toot.account.display_name + "(" + toot.account.acct + ")" + what + "\n\n" + $.strip_tags(toot.status.content), toot.account.avatar, "toot", acct_id, toot.status.id ] postMessage(["nativeNotf", nativeNotfOpt], "*") } } if (localStorage.getItem("hasNotfC_" + acct_id) != "true") { $(".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 = ' :' + shortcode + ': '; var regExp = new RegExp(":" + shortcode + ":", "g"); dis_name = dis_name.replace(regExp, emoji_url); }); } } else { var if_notf = ""; if (toot.reblog) { if (gif == "yes") { noticeavatar = toot.account.avatar; } else { noticeavatar = toot.account.avatar_static; } noticeavatar = '' + ''; var rebtxt = lang.lang_parse_btedsimple; 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 = ' :' + shortcode + ': '; var regExp = new RegExp(":" + shortcode + ":", "g"); dis_name = dis_name.replace(regExp, emoji_url); }); } } else { var uniqueid = toot.id; var notice = ""; var boostback = "unshared"; //ユーザー強調 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 = ''; viashow = "hide"; } else { var via = escapeHTML(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 (mix == "pinned") { boostback = "emphasized"; } 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 = '' + lang.lang_parse_cwshow + '
'; } 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 = '' + lang.lang_parse_fulltext + '
' + toot.content var spoil = '' + $.mb_substr($.strip_tags( toot.content), 0, 100) + '' + lang.lang_parse_autofold + ''; var spoiler = "cw cw_hide_" + toot.id; var spoiler_show = '' + lang.lang_parse_more + '
'; } 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 = '' + lang.lang_parse_url + '
'; } else { var analyze = ''; } var viewer = ""; var hasmedia = ""; var youtube = ""; //Poll var poll = ""; if (toot.poll) { var choices = toot.poll.options; if (toot.poll.voted) { var myvote = lang.lang_parse_voted; var result_hide = ""; } else if (toot.poll.expired) { var myvote = lang.lang_parse_endedvote; var result_hide = ""; } else { var myvote = '' + lang.lang_parse_vote + '
'; if (choices[0].votes_count === 0 || choices[0].votes_count > 0) { myvote = myvote + '' + lang.lang_parse_unvoted + ""; } var result_hide = "hide"; } var ended = date(toot.poll.expires_at, datetype); Object.keys(choices).forEach(function (keyc) { var choice = choices[keyc]; if (!toot.poll.voted && !toot.poll.expired) { var votesel = 'voteSelMastodon(\'' + acct_id + '\',\'' + toot.poll.id + '\',' + keyc + ',' + toot.poll.multiple + ')'; var voteclass = "pointer waves-effect waves-light"; } else { var votesel = ""; var voteclass = ""; } poll = poll + '
' + escapeHTML(choice.title) + '(' + choice.votes_count + ')
'; }); poll = '
' + poll + myvote + '' + ended + '
'; } 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 = ' :' + shortcode + ': '; var regExp = new RegExp(":" + shortcode + ":", "g"); content = content.replace(regExp, emoji_url); spoil = spoil.replace(regExp, emoji_url); poll = poll.replace(regExp, emoji_url); }); } //ニコフレ絵文字 if (toot.profile_emojis) { var nicoemojick = toot.profile_emojis[0]; } else { var nicoemojick = false; } //絵文字があれば(nico) if (nicoemojick) { Object.keys(toot.profile_emojis).forEach(function (keynico) { var emoji = toot.profile_emojis[keynico]; var shortcode = emoji.shortcode; var emoji_url = ' :' + shortcode + ': '; var regExp = new RegExp(":" + shortcode + ":", "g"); content = content.replace(regExp, emoji_url); spoil = spoil.replace(regExp, emoji_url); poll = poll.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); } if (poll) { poll = twemoji.parse(poll); } 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; var nsfwmes = "" if (toot.sensitive && nsfw) { var sense = "sensitive" var blur = media.blurhash if (blur) { nsfwmes = '
' + lang.lang_parse_nsfw + '
' purl = parseBlur(blur) var sense = "" } } else { var sense = "" var blur = null } if (media.pleroma && media.pleroma.mime_type.indexOf("video") !== -1) { viewer = viewer + ''; } else { if (media.type == "unknown") { viewer = viewer + '[' + lang.lang_parse_unknown + '] ' } else { viewer = viewer + '' + nsfwmes + ''; } } }); media_ids = media_ids.slice(0, -1); } else { viewer = ""; hasmedia = "nomedia"; } var menck = toot.mentions[0]; var mentions = ""; //メンションであれば if (menck) { mentions = ""; var to_mention = []; Object.keys(toot.mentions).forEach(function (key3) { var mention = toot.mentions[key3]; mentions = mentions + '@' + mention.acct + ' '; //自分は除外 //自インスタンスかどうかを確認し、IDの一致 if (mention.acct == mention.username && mention.id == localStorage.getItem("user-id_" + acct_id)) { //自分 } else { //そのトゥの人NG if (toot.account.acct != mention.acct) { to_mention.push(mention.acct); } } }); to_mention.push(toot.account.acct); mentions = '
' + mentions + '
'; } else { var to_mention = [toot.account.acct]; } 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 + '
'; } //リプ数 if (toot.replies_count || toot.replies_count === 0) { var replyct = toot.replies_count; if (replyct_view == "hidden" && replyct > 1) { replyct = "1+"; } } else { var replyct = ""; } //公開範囲を取得 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 = "pinnedToot"; } 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 != lang.language && toot.language) { var trans = '
g_translate
'; } else { var trans = ""; } //Cards if (!card && toot.card) { var cards = toot.card; if (cards.provider_name == "Twitter") { if (cards.image) { var twiImg = '
'; } else { var twiImg = ''; } analyze = '
' + escapeHTML(cards.author_name) + '
' + escapeHTML(cards.description) + twiImg + '
'; } if (cards.title) { analyze = "URL" + lang.lang_cards_check + ":
Title:" + escapeHTML(cards.title) + "
" + escapeHTML(cards.description) + "
"; } if (cards.html) { analyze = cards.html + 'picture_in_picture_alt'; } } //Ticker var tickerdom = ""; if (ticker) { var tickerdata = localStorage.getItem("ticker") if (tickerdata) { var tickerdata = JSON.parse(tickerdata); var thisdomain = toot.account.acct.split("@"); if (thisdomain.length > 1) { thisdomain = thisdomain[1]; } for (var i = 0; i < tickerdata.length; i++) { var value = tickerdata[i]; if (value.domain == thisdomain) { var tickerdom = '
' + escapeHTML(value.name) + '
'; break; } } } } //Quote if (toot.quote) { poll = poll + '
' + escapeHTML(toot.quote.account.display_name) + '
' + toot.quote.content + '
' } templete = templete + '
' + '
' + notice + home + '
' + '
' + '' + noticeavatar + '
' + '
' + dis_name + ' @' + toot.account.acct + locked + '
' + '
' + date(toot.created_at, datetype) + '' + '
' + '
' + tickerdom + '' + spoil + "" + spoiler_show + '' + content + '' + poll + '' + viewer + '' + '
' + analyze + '' + '' + mentions + tags + '
' + '
' + '
' + '
' + vis + '
' + '' + '' + '' + '' + '
' + '' + '
' + '
' + '' + trans + 'via ' + via + '' + '
' + '' + '
' + ''; }); 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]; console.log(["Parsing", toot]) if (!toot.username) { var raw = toot; toot = toot.account; var notf = true; } else { var notf = false; } if (toot.locked) { var locked = ' '; } else { var locked = ""; } if (auth == "request") { var authhtml = 'person_add person_add_disabled'; } else { var authhtml = ""; } var ftxt = lang.lang_parse_followed; if (!locale && localStorage.getItem("followlocale_" + acct_id)) { ftxt = localStorage.getItem("followlocale_" + acct_id); } if (popup > 0 || popup == -1 || notf) { var notftext = ftxt + '
'; } else { var notftext = ""; } var memory = localStorage.getItem("notice-mem"); if (popup >= 0 && obj.length < 5 && notftext != memory) { M.toast({ html: escapeHTML(toot.display_name) + ":" + ftxt, displayLength: popup * 1000 }) $(".notf-icon_" + tlid).addClass("red-text"); localStorage.setItem("notice-mem", notftext); notftext = ""; var native = localStorage.getItem("nativenotf"); if (!native) { native = "yes"; } if (native == "yes") { var os = localStorage.getItem("platform"); var options = { body: toot.display_name + "(" + toot.acct + ")" + ftxt, icon: toot.avatar }; var domain = localStorage.getItem("domain_" + acct_id); if (os == "darwin") { var n = new Notification('TheDesk:' + domain, options); } else { var nativeNotfOpt = [ 'TheDesk:' + domain, toot.display_name + "(" + toot.acct + ")" + ftxt, toot.avatar, "userdata", acct_id, toot.id ] postMessage(["nativeNotf", nativeNotfOpt], "*") } } } if (toot.display_name) { var dis_name = escapeHTML(toot.display_name); } else { var dis_name = toot.username; } //ネイティブ通知 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 = ' :' + shortcode + ': '; var regExp = new RegExp(":" + shortcode + ":", "g"); dis_name = dis_name.replace(regExp, emoji_url); }); } if (dis_name) { dis_name = twemoji.parse(dis_name); } if (toot.avatar) { var avatar = toot.avatar; } else { var avatar = "../../img/missing.svg"; } templete = templete + '
' + notftext + '
' + '
' + '
' + dis_name + '' + ' @' + toot.acct + locked + '' + '
' + '
' + '
Follows:' + toot.following_count + '
Followers:' + toot.followers_count + '
' + authhtml + '
' + '
' + ''; }); return templete; } //クライアントダイアログ function client(name) { if (name != "Unknown") { //聞く const options = { type: 'info', title: lang.lang_parse_clientop, message: name + lang.lang_parse_clienttxt, buttons: [lang.lang_parse_clientno, lang.lang_parse_clientemp, lang.lang_parse_clientmute] } postMessage(["dialogClient", options], "*") } }