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