Fix: Poll emoji when refreshed, static emoji #193

This commit is contained in:
cutls 2019-12-14 10:29:59 +09:00
parent c318803ecd
commit 32420fecd9
2 changed files with 82 additions and 22 deletions

View File

@ -217,8 +217,13 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) {
Object.keys(toot.account.emojis).forEach(function(key5) { Object.keys(toot.account.emojis).forEach(function(key5) {
var emoji = toot.account.emojis[key5] var emoji = toot.account.emojis[key5]
var shortcode = emoji.shortcode var shortcode = emoji.shortcode
if (gif == 'yes') {
var emoSource = emoji.url
} else {
var emoSource = emoji.static_url
}
var emoji_url = ` var emoji_url = `
<img draggable="false" src="${emoji.url}" class="emoji-img" data-emoji="${shortcode}" <img draggable="false" src="${emoSource}" class="emoji-img" data-emoji="${shortcode}"
alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle('bigemoji');"> alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle('bigemoji');">
` `
var regExp = new RegExp(':' + shortcode + ':', 'g') var regExp = new RegExp(':' + shortcode + ':', 'g')
@ -367,9 +372,15 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) {
Object.keys(toot.account.emojis).forEach(function(key5) { Object.keys(toot.account.emojis).forEach(function(key5) {
var emoji = toot.account.emojis[key5] var emoji = toot.account.emojis[key5]
var shortcode = emoji.shortcode var shortcode = emoji.shortcode
if (gif == 'yes') {
var emoSource = emoji.url
} else {
var emoSource = emoji.static_url
}
var emoji_url = ` var emoji_url = `
<img draggable="false" src="${emoji.url}" class="emoji-img" data-emoji="${shortcode}" <img draggable="false" src="${emoSource}" class="emoji-img" data-emoji="${shortcode}"
alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle(\'bigemoji\');">` alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle('bigemoji');">
`
var regExp = new RegExp(':' + shortcode + ':', 'g') var regExp = new RegExp(':' + shortcode + ':', 'g')
dis_name = dis_name.replace(regExp, emoji_url) dis_name = dis_name.replace(regExp, emoji_url)
}) })
@ -418,9 +429,15 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) {
Object.keys(toot.account.emojis).forEach(function(key5) { Object.keys(toot.account.emojis).forEach(function(key5) {
var emoji = toot.account.emojis[key5] var emoji = toot.account.emojis[key5]
var shortcode = emoji.shortcode var shortcode = emoji.shortcode
if (gif == 'yes') {
var emoSource = emoji.url
} else {
var emoSource = emoji.static_url
}
var emoji_url = ` var emoji_url = `
<img draggable="false" src="${emoji.url}" class="emoji-img" data-emoji="${shortcode}" <img draggable="false" src="${emoSource}" class="emoji-img" data-emoji="${shortcode}"
alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle(\'bigemoji\');">` alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle('bigemoji');">
`
var regExp = new RegExp(':' + shortcode + ':', 'g') var regExp = new RegExp(':' + shortcode + ':', 'g')
dis_name = dis_name.replace(regExp, emoji_url) dis_name = dis_name.replace(regExp, emoji_url)
}) })
@ -571,7 +588,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) {
//Poll //Poll
var poll = '' var poll = ''
if (toot.poll) { if (toot.poll) {
var poll = pollParse(toot.poll, acct_id) var poll = pollParse(toot.poll, acct_id, false)
} }
var mediack = toot.media_attachments[0] var mediack = toot.media_attachments[0]
@ -831,9 +848,15 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) {
Object.keys(toot.emojis).forEach(function(key5) { Object.keys(toot.emojis).forEach(function(key5) {
var emoji = toot.emojis[key5] var emoji = toot.emojis[key5]
var shortcode = emoji.shortcode var shortcode = emoji.shortcode
if (gif == 'yes') {
var emoSource = emoji.url
} else {
var emoSource = emoji.static_url
}
var emoji_url = ` var emoji_url = `
<img draggable="false" src="${emoji.url}" class="emoji-img" data-emoji="${shortcode}" <img draggable="false" src="${emoSource}" class="emoji-img" data-emoji="${shortcode}"
alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle(\'bigemoji\');">` alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle('bigemoji');">
`
var regExp = new RegExp(':' + shortcode + ':', 'g') var regExp = new RegExp(':' + shortcode + ':', 'g')
content = content.replace(regExp, emoji_url) content = content.replace(regExp, emoji_url)
spoil = spoil.replace(regExp, emoji_url) spoil = spoil.replace(regExp, emoji_url)
@ -1098,9 +1121,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) {
</button> </button>
</div> </div>
<div class="${if_mine}"> <div class="${if_mine}">
<button onclick="pin('${ <button onclick="pin('${uniqueid}','${acct_id}')" class="waves-effect waves-dark btn-flat actct" style="padding:0">
uniqueid
}','${acct_id}')" class="waves-effect waves-dark btn-flat actct" style="padding:0">
<i class="fas fa-map-pin pin_${uniqueid} ${if_pin}"></i> <i class="fas fa-map-pin pin_${uniqueid} ${if_pin}"></i>
<span class="pinStr_${uniqueid}">${pinStr}</span> <span class="pinStr_${uniqueid}">${pinStr}</span>
</button> </button>
@ -1138,6 +1159,10 @@ function userparse(obj, auth, acct_id, tlid, popup) {
if (locale == 'yes') { if (locale == 'yes') {
var locale = false var locale = false
} }
var gif = localStorage.getItem('gif')
if (!gif) {
gif = 'yes'
}
var templete = '' var templete = ''
var datetype = localStorage.getItem('datetype') var datetype = localStorage.getItem('datetype')
Object.keys(obj).forEach(function(key) { Object.keys(obj).forEach(function(key) {
@ -1218,9 +1243,15 @@ function userparse(obj, auth, acct_id, tlid, popup) {
Object.keys(toot.emojis).forEach(function(key5) { Object.keys(toot.emojis).forEach(function(key5) {
var emoji = toot.emojis[key5] var emoji = toot.emojis[key5]
var shortcode = emoji.shortcode var shortcode = emoji.shortcode
if (gif == 'yes') {
var emoSource = emoji.url
} else {
var emoSource = emoji.static_url
}
var emoji_url = ` var emoji_url = `
<img draggable="false" src="${emoji.url}" class="emoji-img" data-emoji="${shortcode}" <img draggable="false" src="${emoSource}" class="emoji-img" data-emoji="${shortcode}"
alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle(\'bigemoji\');">` alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle('bigemoji');">
`
var regExp = new RegExp(':' + shortcode + ':', 'g') var regExp = new RegExp(':' + shortcode + ':', 'g')
dis_name = dis_name.replace(regExp, emoji_url) dis_name = dis_name.replace(regExp, emoji_url)
}) })
@ -1229,7 +1260,11 @@ function userparse(obj, auth, acct_id, tlid, popup) {
dis_name = twemoji.parse(dis_name) dis_name = twemoji.parse(dis_name)
} }
if (toot.avatar) { if (toot.avatar) {
if (gif == 'yes') {
var avatar = toot.avatar var avatar = toot.avatar
} else {
var avatar = toot.avatar_static
}
} else { } else {
var avatar = '../../img/missing.svg' var avatar = '../../img/missing.svg'
} }
@ -1352,7 +1387,7 @@ function client(name) {
} }
} }
//Poll Parser //Poll Parser
function pollParse(poll, acct_id) { function pollParse(poll, acct_id, emojis) {
var datetype = localStorage.getItem('datetype') var datetype = localStorage.getItem('datetype')
var anime = localStorage.getItem('animation') var anime = localStorage.getItem('animation')
if (anime == 'yes' || !anime) { if (anime == 'yes' || !anime) {
@ -1360,6 +1395,10 @@ function pollParse(poll, acct_id) {
} else { } else {
var lpAnime = '' var lpAnime = ''
} }
var gif = localStorage.getItem('gif')
if (!gif) {
gif = 'yes'
}
var choices = poll.options var choices = poll.options
if (poll.own_votes) { if (poll.own_votes) {
var minechoice = poll.own_votes var minechoice = poll.own_votes
@ -1405,7 +1444,8 @@ function pollParse(poll, acct_id) {
for (var i = 0; i < minechoice.length; i++) { for (var i = 0; i < minechoice.length; i++) {
var me = minechoice[i] var me = minechoice[i]
if (me == keyc) { if (me == keyc) {
var voteit = '<span class="ownMark"><img class="emoji" draggable="false" src="https://twemoji.maxcdn.com/v/12.1.4/72x72/2705.png"></span>' var voteit =
'<span class="ownMark"><img class="emoji" draggable="false" src="https://twemoji.maxcdn.com/v/12.1.4/72x72/2705.png"></span>'
break break
} }
} }
@ -1430,11 +1470,31 @@ function pollParse(poll, acct_id) {
} else { } else {
openData = `<span style="float: right">?<span class="sml">(-%)</span></span>` openData = `<span style="float: right">?<span class="sml">(-%)</span></span>`
} }
var choiceText = escapeHTML(choice.title)
if (emojis) {
//絵文字があれば
Object.keys(emojis).forEach(function(key5) {
var emoji = emojis[key5]
var shortcode = emoji.shortcode
if (gif == 'yes') {
var emoSource = emoji.url
} else {
var emoSource = emoji.static_url
}
var emoji_url = `
<img draggable="false" src="${emoSource}" class="emoji-img" data-emoji="${shortcode}"
alt=" :${shortcode}: " title="${shortcode}" onclick="this.classList.toggle('bigemoji');">
`
var regExp = new RegExp(':' + shortcode + ':', 'g')
choiceText = choiceText.replace(regExp, emoji_url)
})
choiceText = twemoji.parse(choiceText)
}
pollHtml = pollHtml =
pollHtml + pollHtml +
`<div class="${voteclass} vote vote_${acct_id}_${poll.id}_${keyc}" onclick="${votesel}"> `<div class="${voteclass} vote vote_${acct_id}_${poll.id}_${keyc}" onclick="${votesel}">
<span class="vote_${acct_id}_${poll.id}_result leadPoll ${result_hide} ${addPoll} ${lpAnime}" style="width: ${per}%"></span> <span class="vote_${acct_id}_${poll.id}_result leadPoll ${result_hide} ${addPoll} ${lpAnime}" style="width: ${per}%"></span>
<span class="onPoll">${escapeHTML(choice.title)}${voteit}</span> <span class="onPoll">${choiceText}${voteit}</span>
<span class="vote_${acct_id}_${poll.id}_result ${result_hide} onPoll"> <span class="vote_${acct_id}_${poll.id}_result ${result_hide} onPoll">
${openData} ${openData}
</span> </span>

View File

@ -120,7 +120,7 @@ function voteMastodonrefresh(acct_id, id) {
if (!json) { if (!json) {
return false return false
} }
var poll = pollParse(json, acct_id) var poll = pollParse(json, acct_id, json.emojis)
$('.vote_' + acct_id + '_' + json.id).html(poll) $('.vote_' + acct_id + '_' + json.id).html(poll)
} }
} }