From c2f382aba86aaebb9806ff1b43c1af69992e9a10 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 11 Jul 2022 15:01:02 +0300 Subject: support dark mode for images with alpha channel --- skin/main.skin.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'skin/main.skin.php') diff --git a/skin/main.skin.php b/skin/main.skin.php index 5236bf0..552c61f 100644 --- a/skin/main.skin.php +++ b/skin/main.skin.php @@ -116,12 +116,14 @@ HTML; // -------- function page($ctx, $page_url, $short_name, $unsafe_html) { -return << {$ctx->if_admin($ctx->pageAdminLinks, $page_url, $short_name)}
{$unsafe_html}
HTML; + +return [$html, markdownThemeChangeListener()]; } function pageAdminLinks($ctx, $url, $short_name) { @@ -139,7 +141,7 @@ HTML; // --------- function post($ctx, $id, $title, $unsafe_html, $date, $visible, $url, $tags, $email, $urlencoded_reply_subject) { -return <<

{$title}

@@ -158,6 +160,8 @@ return <<langRaw('blog_comments_text', $email, $urlencoded_reply_subject)}
HTML; + +return [$html, markdownThemeChangeListener()]; } function postAdminLinks($ctx, $url, $id) { @@ -171,7 +175,32 @@ function postTag($ctx, $url, $name) { return <<#{$name} HTML; +} +function markdownThemeChangeListener() { +return << div'); + if (!div) { + console.warn('could not found a>div on this node:', node); + continue; + } + var style = div.getAttribute('style'); + if (isDark) { + style = style.replace(/(a[\d]+x[\d]+)\.jpg/, '$1_dark.jpg'); + } else { + style = style.replace(/(a[\d]+x[\d]+)_dark\.jpg/, '$1.jpg'); + } + div.setAttribute('style', style); + } +}); +JS; } -- cgit v1.2.3