diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/webview/lib/RecipeWebview.ts | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/webview/lib/RecipeWebview.ts b/src/webview/lib/RecipeWebview.ts index 5701ca9c5..a896f1b6e 100644 --- a/src/webview/lib/RecipeWebview.ts +++ b/src/webview/lib/RecipeWebview.ts | |||
@@ -2,7 +2,9 @@ import { ipcRenderer } from 'electron'; | |||
2 | import { BrowserWindow } from '@electron/remote'; | 2 | import { BrowserWindow } from '@electron/remote'; |
3 | import { pathExistsSync, readFileSync, existsSync } from 'fs-extra'; | 3 | import { pathExistsSync, readFileSync, existsSync } from 'fs-extra'; |
4 | 4 | ||
5 | const debug = require('../../preload-safe-debug')('Ferdium:Plugin:RecipeWebview'); | 5 | const debug = require('../../preload-safe-debug')( |
6 | 'Ferdium:Plugin:RecipeWebview', | ||
7 | ); | ||
6 | 8 | ||
7 | class RecipeWebview { | 9 | class RecipeWebview { |
8 | badgeHandler: any; | 10 | badgeHandler: any; |
@@ -93,12 +95,27 @@ class RecipeWebview { | |||
93 | } | 95 | } |
94 | 96 | ||
95 | /** | 97 | /** |
96 | * Find if url contains image | 98 | * Find if link contains image |
97 | * | 99 | * |
98 | * @param {string | number | undefined | null} text to be parsed | 100 | * @param {string | number | undefined | null} text to be parsed |
99 | */ | 101 | */ |
100 | isImage(url): boolean { | 102 | isImage(link): boolean { |
101 | return /\.(jpg|jpeg|png|webp|avif|gif|svg)$/.test(url.split(/[#?]/)[0]); | 103 | if (typeof link === 'undefined') { |
104 | return false; | ||
105 | } | ||
106 | |||
107 | const { role } = link.dataset; | ||
108 | |||
109 | if (typeof role !== 'undefined') { | ||
110 | const roles = ['img']; | ||
111 | return roles.includes(role); | ||
112 | } | ||
113 | |||
114 | const url = link.getAttribute('href'); | ||
115 | |||
116 | const regex = /\.(jpg|jpeg|png|webp|avif|gif|svg)($|\?|:)/; | ||
117 | |||
118 | return regex.test(url.split(/[#?]/)[0]); | ||
102 | } | 119 | } |
103 | 120 | ||
104 | /** | 121 | /** |