Skip to content

Commit ed428c6

Browse files
committed
fix csp for images
1 parent 117eb38 commit ed428c6

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

scripts/index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,11 @@ function gameLostDaily() {
512512
});
513513
}
514514

515+
let imgSrc = 'https://storage.ko-fi.com/cdn/cup-border.png';
516+
if (window.isDiscord) {
517+
imgSrc = getDiscordProxiedUrl(imgSrc);
518+
};
519+
515520
window.dailyModal = $.confirm({
516521
title: "<span class=\"modalTitle\">Totally Lost</span>",
517522
content: getCardHtml() + '<div id="dailyTimerDisplay"></div>',
@@ -526,7 +531,7 @@ function gameLostDaily() {
526531
closeIcon: true,
527532
buttons: {
528533
kofi: {
529-
text: '<img src="https://storage.ko-fi.com/cdn/cup-border.png" alt="Ko-Fi">',
534+
text: `<img src="${imgSrc}" alt="Ko-Fi">`,
530535
btnClass: 'btn-blue kofi-btn',
531536
action: function () {
532537
buyDrink();
@@ -799,11 +804,21 @@ function clipboardError(str) {
799804
function getCardHtml() {
800805
let html;
801806
if (window.mtgCard['layout'] == 'transform' || window.mtgCard['layout'] == 'modal_dfc') {
807+
let imgSrc0 = window.mtgCard['card_faces'][window.mtgCard.cf]['image_uris']['normal'];
808+
let imgSrc1 = window.mtgCard['card_faces'][1 - window.mtgCard.cf]['image_uris']['normal'];
809+
if (window.isDiscord) {
810+
imgSrc0 = getDiscordProxiedUrl(imgSrc0);
811+
imgSrc1 = getDiscordProxiedUrl(imgSrc1);
812+
}
802813
html = '<div class="flip-card"><div class="flip-card-inner"><div class="flip-card-front">' +
803-
'<img src=\"' + window.mtgCard['card_faces'][window.mtgCard.cf]['image_uris']['normal'] + '\" style=\"border-radius:8% / 6%;\"><span class="material-symbols-outlined flip-symbol-front"> chevron_right </span></div> <div class="flip-card-back">' +
804-
'<img src=\"' + window.mtgCard['card_faces'][1 - window.mtgCard.cf]['image_uris']['normal'] + '\" style=\"border-radius:8% / 6%;\"><span class="material-symbols-outlined flip-symbol-back"> chevron_left </span></div></div></div>';
814+
'<img src=\"' + imgSrc0 + '\" style=\"border-radius:8% / 6%;\"><span class="material-symbols-outlined flip-symbol-front"> chevron_right </span></div> <div class="flip-card-back">' +
815+
'<img src=\"' + imgSrc1 + '\" style=\"border-radius:8% / 6%;\"><span class="material-symbols-outlined flip-symbol-back"> chevron_left </span></div></div></div>';
805816
} else {
806-
html = "<img src=\"" + window.mtgCard.image_uris.normal + "\" style=\"border-radius:8% / 6%;\">";
817+
let imgSrc = window.mtgCard.image_uris.normal;
818+
if (window.isDiscord) {
819+
imgSrc = getDiscordProxiedUrl(imgSrc);
820+
}
821+
html = "<img src=\"" + imgSrc + "\" style=\"border-radius:8% / 6%;\">";
807822
}
808823
return html;
809824
}
@@ -2140,7 +2155,8 @@ function getDiscordProxiedUrl(originalUrl) {
21402155
.replace("https://cards.scryfall.io", "/scry-io/cards")
21412156
.replace("https://svgs.scryfall.io", "/scry-io/svg")
21422157
.replace("https://docs.google.com/forms", "/google/forms")
2143-
.replace("https://ko-fi.com", "/kofi");
2158+
.replace("https://ko-fi.com", "/kofi")
2159+
.replace("https://storage.ko-fi.com", "/kofi-storage");
21442160
}
21452161

21462162

0 commit comments

Comments
 (0)