aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/lib/RecipeWebview.ts
diff options
context:
space:
mode:
authorLibravatar André Oliveira <37463445+SpecialAro@users.noreply.github.com>2022-07-12 23:35:31 +0100
committerLibravatar GitHub <noreply@github.com>2022-07-12 23:35:31 +0100
commit2ca3aa7eca6854d61959b92a9270d4fb89613f4c (patch)
tree346baef9b6ff718209cda49bdc1555517760da4f /src/webview/lib/RecipeWebview.ts
parentRefactor the 'Welcome' screen and the 'SetupAssistant' for better UX (#472) (diff)
downloadferdium-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/lib/RecipeWebview.ts')
-rw-r--r--src/webview/lib/RecipeWebview.ts25
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';
2import { BrowserWindow } from '@electron/remote'; 2import { BrowserWindow } from '@electron/remote';
3import { pathExistsSync, readFileSync, existsSync } from 'fs-extra'; 3import { pathExistsSync, readFileSync, existsSync } from 'fs-extra';
4 4
5const debug = require('../../preload-safe-debug')('Ferdium:Plugin:RecipeWebview'); 5const debug = require('../../preload-safe-debug')(
6 'Ferdium:Plugin:RecipeWebview',
7);
6 8
7class RecipeWebview { 9class 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 /**