From 3af6bcafa77fe29c6e604cde9535a89f787ab3af Mon Sep 17 00:00:00 2001 From: SillyLossy Date: Mon, 17 Apr 2023 00:20:35 +0300 Subject: [PATCH] Default expressions for groups --- .../scripts/extensions/expressions/index.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js index c9e7b43e1..63043b903 100644 --- a/public/scripts/extensions/expressions/index.js +++ b/public/scripts/extensions/expressions/index.js @@ -247,15 +247,26 @@ async function setExpression(character, expression, force) { const imgUrl = `/characters/${character}/${filename}`; img.attr('src', imgUrl); img.removeClass('default'); + img.off('error'); + img.on('error', function() { + $(this).attr('src', ''); + if (force && extension_settings.expressions.showDefault) { + setDefault(); + } + }); } else { if (extension_settings.expressions.showDefault) { //console.log('no character images, trying default expressions'); - const defImgUrl = `/img/default-expressions/${filename}`; - //console.log(defImgUrl); - img.attr('src', defImgUrl); - img.addClass('default'); + setDefault(); } } + + function setDefault() { + const defImgUrl = `/img/default-expressions/${filename}`; + //console.log(defImgUrl); + img.attr('src', defImgUrl); + img.addClass('default'); + } } function onClickExpressionImage() { @@ -276,9 +287,6 @@ function onClickExpressionImage() { function addExpressionImage() { const html = `
`; $('body').append(html); - $('img.expression').on('error', function () { - $(this).attr('src', ''); - }); } function addSettings() { const html = `