From b0a4fb77be4c9ac23332d05c28a4be17c70bee90 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Sat, 4 Feb 2023 15:44:51 +0100 Subject: [PATCH] Bugfix for whitelist to show images directly #201 --- dev/Model/Message.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/dev/Model/Message.js b/dev/Model/Message.js index 038ffb45d..13878a5f6 100644 --- a/dev/Model/Message.js +++ b/dev/Model/Message.js @@ -384,23 +384,32 @@ export class MessageModel extends AbstractModel { showExternalImages(regex) { const body = this.body; if (body && this.hasImages()) { - this.hasImages(false); - body.rlHasImages = false; - - let attr = 'data-x-src', + let hasImages = false, + isValid = src => { + if (!regex || src.match(regex)) { + return true; + } + hasImages = true; + }, + attr = 'data-x-src', src, useProxy = !!SettingsGet('UseLocalProxyForExternalImages'); body.querySelectorAll('img[' + attr + ']').forEach(node => { src = node.getAttribute(attr); - if (!regex || src.match(regex)) { + if (isValid(src)) { node.src = useProxy ? proxy(src) : src; } }); body.querySelectorAll('[data-x-style-url]').forEach(node => { - JSON.parse(node.dataset.xStyleUrl).forEach(data => - node.style[data[0]] = "url('" + (useProxy ? proxy(data[1]) : data[1]) + "')" - ); + JSON.parse(node.dataset.xStyleUrl).forEach(data => { + if (isValid(data[1])) { + node.style[data[0]] = "url('" + (useProxy ? proxy(data[1]) : data[1]) + "')" + } + }); }); + + this.hasImages(hasImages); + body.rlHasImages = hasImages; } }