From 634ebf94a83559cd49c2b6c19a8ed6c5f01d2cf4 Mon Sep 17 00:00:00 2001 From: Nils Enevoldsen Date: Thu, 26 Apr 2018 23:47:07 -0400 Subject: [PATCH] Improve caching behavior by avoiding 302 redirects --- modules/ext.scryfallLinks.tooltip.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ext.scryfallLinks.tooltip.js b/modules/ext.scryfallLinks.tooltip.js index 5d564ee..c48c6a8 100644 --- a/modules/ext.scryfallLinks.tooltip.js +++ b/modules/ext.scryfallLinks.tooltip.js @@ -27,21 +27,21 @@ $( function () { cardNameParam = 'exact=' + target.dataset.cardName, cardSet = target.dataset.cardSet, cardSetParam = cardSet ? '&set=' + cardSet : '', - formatParam = '&format=image', - versionParam = '&version=normal', - imageSrc = 'https://api.scryfall.com/cards/named?' + cardNameParam + cardSetParam + formatParam + versionParam; + cardJSON = 'https://api.scryfall.com/cards/named?' + cardNameParam + cardSetParam; if ( tip.loading || content.innerHTML !== '' ) { return; } tip.loading = true; // Hide the tooltip until we've finished loaded the image thisPopper.style.display = 'none'; // fetch() only works on modern browsers - fetch( imageSrc ) + fetch( cardJSON ) .then( response => { if ( !response.ok ) { throw Error( response.statusText ); } return response; } ) + .then( response => response.json() ) + .then( data => fetch( data.image_uris.normal ) ) .then( response => response.blob() ) .then( blob => { const url = URL.createObjectURL( blob ),