Fix emoji in HTML attribute value

This commit is contained in:
cutls 2022-12-10 12:27:46 +09:00
parent 29d6146e02
commit e4a9eca514

View File

@ -3,7 +3,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
var splitter = new GraphemeSplitter()
var templete = ''
if (obj[0]) {
if (tlid === 1) {}
if (tlid === 1) { }
localStorage.setItem('lastunix_' + tlid, date(obj[0].created_at, 'unix'))
}
@ -214,7 +214,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
}
//絵文字があれば
if (actemojick) {
Object.keys(toot.account.emojis).forEach(function(key5) {
Object.keys(toot.account.emojis).forEach(function (key5) {
var emoji = toot.account.emojis[key5]
var shortcode = emoji.shortcode
if (gif == 'yes') {
@ -370,7 +370,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
}
//絵文字があれば
if (actemojick) {
Object.keys(toot.account.emojis).forEach(function(key5) {
Object.keys(toot.account.emojis).forEach(function (key5) {
var emoji = toot.account.emojis[key5]
var shortcode = emoji.shortcode
if (gif == 'yes') {
@ -427,7 +427,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
}
//絵文字があれば
if (actemojick) {
Object.keys(toot.account.emojis).forEach(function(key5) {
Object.keys(toot.account.emojis).forEach(function (key5) {
var emoji = toot.account.emojis[key5]
var shortcode = emoji.shortcode
if (gif == 'yes') {
@ -455,7 +455,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
var fullname = toot.account.acct + '@' + domain
}
if (useremp) {
Object.keys(useremp).forEach(function(key10) {
Object.keys(useremp).forEach(function (key10) {
var user = useremp[key10]
if (user == fullname) {
boostback = 'emphasized'
@ -498,7 +498,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
var via = escapeHTML(toot.application.name)
if (empCli) {
//強調チェック
Object.keys(empCli).forEach(function(key6) {
Object.keys(empCli).forEach(function (key6) {
var empCliList = empCli[key6]
if (empCliList == via) {
boostback = 'emphasized'
@ -507,7 +507,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
}
if (muteCli) {
//ミュートチェック
Object.keys(muteCli).forEach(function(key7) {
Object.keys(muteCli).forEach(function (key7) {
var muteCliList = muteCli[key7]
if (muteCliList == via) {
boostback = 'hide'
@ -601,7 +601,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
if (mediack) {
hasmedia = 'hasmedia'
var cwdt = 100 / toot.media_attachments.length
Object.keys(toot.media_attachments).forEach(function(key2) {
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 + ','
@ -845,7 +845,11 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
})
}
//デフォ絵文字
content = twemoji.parse(content)
const contentElement = document.createElement('div')
contentElement.innerHTML = content
const emojified = twemoji.parse(contentElement)
content = emojified.innerHTML
if (dis_name) {
dis_name = twemoji.parse(dis_name)
}
@ -1522,7 +1526,7 @@ function customEmojiReplace(content, toot, gif) {
contentDiv.style.display = 'none';
contentDiv.innerHTML = content;
var replace = false;
Object.keys(toot.emojis).forEach(function(key5) {
Object.keys(toot.emojis).forEach(function (key5) {
var emoji = toot.emojis[key5]
var shortcode = emoji.shortcode
if (gif == 'yes') {
@ -1530,8 +1534,8 @@ function customEmojiReplace(content, toot, gif) {
} else {
var emoSource = emoji.static_url
}
var nodes = document.evaluate('//text()', contentDiv, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
if ( nodes.snapshotLength == 0 ) return;
var nodes = document.evaluate('//text()', contentDiv, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (nodes.snapshotLength == 0) return;
var shortcodeBracket = (':' + shortcode + ':');
var img = document.createElement('img');
@ -1543,7 +1547,7 @@ function customEmojiReplace(content, toot, gif) {
img.setAttribute('title', shortcodeBracket);
img.setAttribute('onclick', "this.classList.toggle('bigemoji');");
for ( var i=0; i < nodes.snapshotLength; i++ ) {
for (var i = 0; i < nodes.snapshotLength; i++) {
var node = nodes.snapshotItem(i);
var txt = node.textContent;
var spos = txt.indexOf(shortcodeBracket);