From c5cdabaa3a9a5a0c87d5ef5f4c3f26ef35b7e3a2 Mon Sep 17 00:00:00 2001 From: Cutls Date: Mon, 30 Sep 2019 02:23:25 +0900 Subject: [PATCH] Change: move and add poll parser --- app/js/tl/parse.js | 79 +++++++++++++++++++++++++++++----------------- app/js/tl/poll.js | 17 +--------- 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/app/js/tl/parse.js b/app/js/tl/parse.js index 8a328bdb..647308b1 100644 --- a/app/js/tl/parse.js +++ b/app/js/tl/parse.js @@ -533,35 +533,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) { //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 + '' + lang.lang_manager_refresh + '' + - ended + '
'; + var poll = pollParse(toot.poll, acct_id) } var mediack = toot.media_attachments[0]; @@ -1143,4 +1115,53 @@ function client(name) { } }) } +} +//Poll Parser +function pollParse(poll, acct_id) { + var datetype = localStorage.getItem("datetype"); + var choices = poll.options; + if (poll.own_votes) { + var minechoice = poll.own_votes + } else { + var minechoice = [] + } + + if (poll.voted) { + var myvote = lang.lang_parse_voted; + var result_hide = ""; + } else if (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(poll.expires_at, datetype); + var pollHtml = "" + Object.keys(choices).forEach(function (keyc) { + var choice = choices[keyc]; + var voteit = ""; + for (var i = 0; i < minechoice.length; i++) { + var me = minechoice[i] + if (me == keyc) { + var voteit = "✅"; + break + } + } + if (!poll.voted && !poll.expired) { + var votesel = 'voteSelMastodon(\'' + acct_id + '\',\'' + poll.id + '\',' + keyc + ',' + poll.multiple + ')'; + var voteclass = "pointer waves-effect waves-light"; + } else { + var votesel = ""; + var voteclass = ""; + } + pollHtml = pollHtml + '
' + escapeHTML(choice.title) + '(' + choice.votes_count + ')' + voteit + '
'; + }); + pollHtml = '
' + pollHtml + myvote + '' + lang.lang_manager_refresh + '' + + ended + '
'; + return pollHtml } \ No newline at end of file diff --git a/app/js/tl/poll.js b/app/js/tl/poll.js index c3da6d90..ac5bfde5 100644 --- a/app/js/tl/poll.js +++ b/app/js/tl/poll.js @@ -119,22 +119,7 @@ function voteMastodonrefresh(acct_id, id) { if (!json) { return false; } - var poll = ""; - var choices = json.options; - var myvote = lang.lang_parse_voted; - var result_hide = ""; - Object.keys(choices).forEach(function (keyc) { - var choice = choices[keyc]; - if (!json.voted) { - votesel = 'voteSelMastodon(\'' + acct_id + '\',\'' + json.id + '\',' + keyc + ',' + json.multiple + ')'; - }else { - votesel ="" - } - poll = poll + '
' + escapeHTML(choice.title) + '(' + choice.votes_count + ')
'; - }); - poll = poll + myvote + '' + lang.lang_manager_refresh + '' + - date(json.expires_at, datetype) + ''; + var poll = pollParse(json, acct_id) $('.vote_' + acct_id + '_' + json.id).html(poll) } }