diff --git a/public/script.js b/public/script.js index ee3768f4c..02efe65f5 100644 --- a/public/script.js +++ b/public/script.js @@ -123,6 +123,7 @@ import { sortMoments, timestampToMoment, download, + isDataURL, } from "./scripts/utils.js"; import { extension_settings, loadExtensionSettings, runGenerationInterceptors } from "./scripts/extensions.js"; @@ -7024,14 +7025,11 @@ $(document).ready(function () { }); $(document).on('click', '.mes .avatar', function () { - - //if (window.innerWidth > 1000 || $('body').hasClass('waifuMode')) { - let thumbURL = $(this).children('img').attr('src'); let charsPath = '/characters/' let targetAvatarImg = thumbURL.substring(thumbURL.lastIndexOf("=") + 1); - let avatarSrc = charsPath + targetAvatarImg; + let avatarSrc = isDataURL(thumbURL) ? thumbURL : charsPath + targetAvatarImg; console.log(avatarSrc); if ($(this).parent().parent().attr('is_user') == 'true') { //handle user avatars $("#zoomed_avatar").attr('src', thumbURL); diff --git a/public/scripts/utils.js b/public/scripts/utils.js index 2ab7956d0..35d770d61 100644 --- a/public/scripts/utils.js +++ b/public/scripts/utils.js @@ -404,3 +404,8 @@ export class IndexedDBStore { }); } } + +export function isDataURL(str) { + const regex = /^data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)*;?)?(base64)?,([a-z0-9!$&',()*+;=\-_%.~:@\/?#]+)?$/i; + return regex.test(str); +}