Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
fix: 修复 markdown bug 只能删除一个的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LIlGG committed Jul 23, 2021
1 parent b2b55c6 commit ef74afe
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 28 deletions.
37 changes: 25 additions & 12 deletions dist/halo-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -15265,22 +15265,35 @@ function renderedEmojiHtml(html) {

function removeNotEmoji(doc) {
let smilies = doc.getElementsByClassName("smilies");
loopSearchEmoji(smilies, "tieba", node => {
let alt = node.getAttribute('alt');
let textNode = document.createTextNode(alt);
node.parentNode.replaceChild(textNode, node);
});
return doc;
}
let skip = true;

function loopSearchEmoji(nodeList, type, callback) {
for (let i = 0; i < nodeList.length; i++) {
var name = nodeList[i].dataset.icon;
for (let i = 0; i < smilies.length; i++) {
let name = smilies[i].dataset.icon;

if (!findEmoji(type, name)) {
callback(nodeList[i]);
if (!findEmoji("tieba", name)) {
skip = false;
break;
}
}

if (skip) {
return doc;
}

var firstNode = smilies[0];
var name = firstNode.dataset.icon;

if (!findEmoji("tieba", name)) {
removeNode(firstNode);
}

return removeNotEmoji(doc);
}

function removeNode(node) {
let alt = node.getAttribute('alt');
let textNode = document.createTextNode(alt);
node.parentNode.replaceChild(textNode, node);
}
/**
* 根据条件查找表情
Expand Down
2 changes: 1 addition & 1 deletion dist/halo-comment.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/halo-comment.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/halo-comment.min.js.map

Large diffs are not rendered by default.

38 changes: 25 additions & 13 deletions src/utils/emojiutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,35 @@ export function renderedEmojiHtml(html) {
*/
function removeNotEmoji(doc) {
let smilies = doc.getElementsByClassName("smilies");
loopSearchEmoji(smilies, "tieba", (node) => {
let alt = node.getAttribute('alt');
let textNode = document.createTextNode(alt);
let skip = true;

node.parentNode.replaceChild(textNode, node);
});
return doc;
}

function loopSearchEmoji(nodeList, type, callback) {
for(let i = 0; i < nodeList.length; i++) {
var name = nodeList[i].dataset.icon;
for (let i = 0; i < smilies.length; i++) {
let name = smilies[i].dataset.icon;

if (!findEmoji(type, name)) {
callback(nodeList[i])
if (!findEmoji("tieba", name)) {
skip = false;
break;
}
}

if (skip) {
return doc;
}

var firstNode = smilies[0];
var name = firstNode.dataset.icon;

if (!findEmoji("tieba", name)) {
removeNode(firstNode)
}

return removeNotEmoji(doc);
}

function removeNode(node) {
let alt = node.getAttribute('alt');
let textNode = document.createTextNode(alt);
node.parentNode.replaceChild(textNode, node);
}

/**
Expand Down

0 comments on commit ef74afe

Please sign in to comment.