diff --git a/mindspace-page-tag.mjs b/mindspace-page-tag.mjs index e3cc082..721772a 100644 --- a/mindspace-page-tag.mjs +++ b/mindspace-page-tag.mjs @@ -1,6 +1,20 @@ export const MINDSPACE_PAGE_TAG_ATTR = 'data-mindspace-page-tag'; export const MINDSPACE_PAGE_TAG_PLATFORM_BRAND = 'platform-brand'; export const PLATFORM_BRAND_TEXT = 'TKMind · 智趣'; +export const PLATFORM_BRAND_STYLE_ID = 'mindspace-platform-brand-style'; + +const PLATFORM_BRAND_VISIBILITY_STYLE = ``; const PLATFORM_BRAND_INNER_RE = /(?:TKMind\s*·\s*智趣|contact@tkmind\.(?:ai|cn)|📧[^<]*tkmind)/i; const SIMPLE_BRAND_ELEMENT_RE = @@ -49,6 +63,20 @@ export function ensurePlatformBrandFooter(html) { return `${normalized}\n${footer}`; } +/** Override author CSS that hides the platform brand line (e.g. opacity 0.25). */ +export function injectPlatformBrandVisibilityStyle(html) { + const source = String(html ?? ''); + if (!hasPlatformBrandMarker(source) || source.includes(PLATFORM_BRAND_STYLE_ID)) return source; + if (/<\/head>/i.test(source)) { + return source.replace(/<\/head>/i, `${PLATFORM_BRAND_VISIBILITY_STYLE}\n`); + } + return `${PLATFORM_BRAND_VISIBILITY_STYLE}${source}`; +} + +export function preparePublishedPlatformBrand(html) { + return injectPlatformBrandVisibilityStyle(ensurePlatformBrandFooter(html)); +} + export function prepareHtmlPageBrandMarkers(html) { return ensurePlatformBrandPageTags(html); } diff --git a/mindspace-page-tag.test.mjs b/mindspace-page-tag.test.mjs index c45461e..d69cbe8 100644 --- a/mindspace-page-tag.test.mjs +++ b/mindspace-page-tag.test.mjs @@ -5,7 +5,9 @@ import { MINDSPACE_PAGE_TAG_PLATFORM_BRAND, ensurePlatformBrandFooter, ensurePlatformBrandPageTags, + injectPlatformBrandVisibilityStyle, normalizePlatformBrandHtml, + PLATFORM_BRAND_STYLE_ID, prepareHtmlPageBrandMarkers, } from './mindspace-page-tag.mjs'; @@ -30,6 +32,15 @@ test('prepareHtmlPageBrandMarkers keeps existing marker', () => { assert.equal(result.match(new RegExp(MINDSPACE_PAGE_TAG_ATTR, 'g'))?.length, 1); }); +test('injectPlatformBrandVisibilityStyle adds readable brand css', () => { + const html = + '
' + + `TKMind · 智趣
`; + const result = injectPlatformBrandVisibilityStyle(html); + assert.match(result, new RegExp(`id="${PLATFORM_BRAND_STYLE_ID}"`)); + assert.match(result, /opacity:\s*1 !important/); +}); + test('ensurePlatformBrandFooter appends brand line when marker is missing', () => { const html = '