修复夜间模式切换Code重复

This commit is contained in:
tlyong1992
2022-06-06 14:04:04 +08:00
parent 96a13170fd
commit 49c9e8e6cb

View File

@@ -101,7 +101,12 @@ function addWatch4Dom(element) {
switch (type) {
case 'childList':
if (mutation.target.className === 'notion-code-copy') {
fixCopy(mutation)
fixCopy(mutation.target)
} else if (mutation.target.className?.indexOf('language-') > -1) {
const copyCode = mutation.target.parentElement?.firstElementChild
if (copyCode) {
fixCopy(copyCode)
}
}
// console.log('A child node has been added or removed.')
break
@@ -128,12 +133,11 @@ function addWatch4Dom(element) {
}
/**
* 复制代码后,会重复 @see https://github.com/tangly1024/NotionNext/issues/165
* @param {*} e
*/
function fixCopy(e) {
const codeE = e.target.parentElement.lastElementChild
// console.log('2', codeE)
* 复制代码后,会重复 @see https://github.com/tangly1024/NotionNext/issues/165
* @param {*} e
*/
function fixCopy(codeCopy) {
const codeE = codeCopy.parentElement.lastElementChild
const codeEnd = codeE.lastChild
if (codeEnd.nodeName === '#text' && codeE.childNodes.length > 1) {
codeEnd.nodeValue = null