Skip to content

Commit

Permalink
Fix multiface cards
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
NilsEnevoldsen committed Apr 27, 2018
1 parent 634ebf9 commit 6d64fca
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion modules/ext.scryfallLinks.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,31 @@ $( function () {
return response;
} )
.then( response => response.json() )
.then( data => fetch( data.image_uris.normal ) )
.then( data => {
if ( data.hasOwnProperty( 'card_faces' ) ) {
// Is a multiface card
if ( data.card_faces[0].hasOwnProperty( 'image_uris' ) ) {
const frontside =
decodeURIComponent(target.dataset.cardName).replace(/[^a-z]/ig,'').toUpperCase() ==
data.card_faces[0].name.replace(/[^a-z]/ig,'').toUpperCase()
// Is a double-sided card
if ( frontside ) {
// Is a front side
return data.card_faces[0].image_uris.normal;
} else {
// Is a back side
return data.card_faces[1].image_uris.normal;
}
} else {
// Is a split or flip card
return data.image_uris.normal;
}
} else {
// Not a multiface card
return data.image_uris.normal;
}
} )
.then( imageURI => fetch( imageURI ) )
.then( response => response.blob() )
.then( blob => {
const url = URL.createObjectURL( blob ),
Expand Down

0 comments on commit 6d64fca

Please sign in to comment.