diff options
author | André Oliveira <37463445+SpecialAro@users.noreply.github.com> | 2022-07-12 23:35:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-12 23:35:31 +0100 |
commit | 2ca3aa7eca6854d61959b92a9270d4fb89613f4c (patch) | |
tree | 346baef9b6ff718209cda49bdc1555517760da4f /src/webview | |
parent | Refactor the 'Welcome' screen and the 'SetupAssistant' for better UX (#472) (diff) | |
download | ferdium-app-2ca3aa7eca6854d61959b92a9270d4fb89613f4c.tar.gz ferdium-app-2ca3aa7eca6854d61959b92a9270d4fb89613f4c.tar.zst ferdium-app-2ca3aa7eca6854d61959b92a9270d4fb89613f4c.zip |
Change isImage function to link instead of URL (#470)
* Change isImage function
* Fix comments
* Fix last comments and lint
Diffstat (limited to 'src/webview')
-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 | /** |