From c69cf9327b85106fdf376e74a6f0a080df6f5eac Mon Sep 17 00:00:00 2001 From: AmeroHan <72120616+AmeroHan@users.noreply.github.com> Date: Sat, 2 Nov 2024 22:13:04 +0800 Subject: [PATCH] perf: infobox screenshot robustness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 隐藏所有不属于infobox的元素,而非隐藏预定义的一部分 --- src/plugins/mediawiki/infoboxDefinition.ts | 44 +++++++++++----------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/plugins/mediawiki/infoboxDefinition.ts b/src/plugins/mediawiki/infoboxDefinition.ts index 1ac2755..a17514d 100644 --- a/src/plugins/mediawiki/infoboxDefinition.ts +++ b/src/plugins/mediawiki/infoboxDefinition.ts @@ -13,9 +13,8 @@ export const INFOBOX_DEFINITION: { injectStyles?: string }[] = [ // 萌娘百科 - { - match: (url) => url.host.endsWith('moegirl.org.cn'), - selector: [ + (() => { + const selectors = [ // 标准信息框 '.mw-parser-output .infotemplatebox', '.mw-parser-output table.infobox2', @@ -23,27 +22,26 @@ export const INFOBOX_DEFINITION: { '.mw-parser-output table.infoboxSpecial', // 旧版兼容 '.mw-parser-output table.infobox', - ], - injectStyles: ` - /* 隐藏部分妨碍截图的元素 */ - /* 顶部导航栏和悬浮工具栏 */ - body #moe-full-container > header#moe-global-header, body #moe-full-container > #moe-global-toolbar, - /* 右下角悬浮的功能按钮 */ - #bottomRightCorner, - /* 全站公告弹窗 */ - body > .n-modal-container, - /* [[WAF]] */ - .mw-parser-output [data-id="lr-overlay"] - { - display: none !important; - } + ] + return { + match: (url) => url.host.endsWith('moegirl.org.cn'), + selector: selectors, + injectStyles: ` + /* 隐藏妨碍截图的元素 */ + ${selectors.join(', ')} { + visibility: visible; + :not(&, & *) { + visibility: hidden; + } + } - /* 调整信息框外观 */ - .mw-parser-output .infotemplatebox { - margin: 1rem !important; - } - `, - }, + /* 调整信息框外观 */ + .mw-parser-output .infotemplatebox { + margin: 1rem !important; + } + `, + } + })(), // Minecraft Wiki { match: (url) => url.host === 'minecraft.fandom.com',