From 532aa18e0ca4a13ea47ab9e9b347541f4cde4728 Mon Sep 17 00:00:00 2001 From: xiezheng-XD <141627292+xiezheng-XD@users.noreply.github.com> Date: Tue, 26 Dec 2023 22:17:21 +0800 Subject: [PATCH] chore: update eslintrc.js and config.ts (#2307) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update .eslintrc.js * Update config.ts 优化了查询逻辑 * chore: fix insert version * style: format * style: format --------- Co-authored-by: liuyib <1656081615@qq.com> --- .eslintrc.js | 1 - config/config.ts | 27 +++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index fe75bf1c08..0940038f38 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,7 +12,6 @@ module.exports = { '@typescript-eslint/ban-ts-ignore': 'off', '@typescript-eslint/no-object-literal-type-assertion': 'off', '@typescript-eslint/no-parameter-properties': 'off', - 'consistent-return': 'off', 'import/no-useless-path-segments': 'off', 'no-unused-expressions': 'off', 'react-hooks/rules-of-hooks': 'error', diff --git a/config/config.ts b/config/config.ts index b2cf6c1405..281a9c782d 100644 --- a/config/config.ts +++ b/config/config.ts @@ -180,20 +180,27 @@ export default { scripts: [ 'https://s4.cnzz.com/z_stat.php?id=1278992092&web_id=1278992092', ` - const insertVersion = function(){ + const insertVersion = function() { + const logo = document.querySelector('.__dumi-default-navbar-logo'); + if (!logo) return; const dom = document.createElement('span'); dom.id = 'logo-version'; dom.innerHTML = '${packages.version}'; - const logo = document.querySelector('.__dumi-default-navbar-logo'); - if(logo){ - logo.parentNode.insertBefore(dom, logo.nextSibling); - }else{ - setTimeout(()=>{ - insertVersion(); - }, 1000) + logo.parentNode.insertBefore(dom, logo.nextSibling); + }; + const observer = new MutationObserver((mutationsList, observer) => { + for (const mutation of mutationsList) { + if (mutation.type === 'childList') { + const logoVersion = document.querySelector('#logo-version'); + if (logoVersion) { + observer.disconnect(); + } else { + insertVersion(); + } + } } - } - insertVersion(); + }); + observer.observe(document.body, { childList: true, subtree: true }); `, ], };