Scryfall Hover Price

Show prices of MTG cards by hovering over them while searching Scryfall

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        Scryfall Hover Price
// @namespace   Tripp Lyons
// @match       *://scryfall.com/search
// @version     1.0
// @author      Tripp Lyons
// @description Show prices of MTG cards by hovering over them while searching Scryfall
// ==/UserScript==

/* jshint esversion: 6 */

function makePriceElement() {
  let el = document.createElement('div')
  el.innerText = 'Loading...'
  el.className = 'price'
  el.style.backgroundColor = 'rgba(0,0,0,0.5)'
  el.style.color = 'white'
  el.style.fontFamily = 'sans-serif'
  el.style.fontSize = '18px'
  el.style.display = 'flex'
  el.style.justifyContent = 'center'
  el.style.alignItems = 'center'
  el.style.position = 'absolute'
  el.style.left = '0px'
  el.style.right = '0px'
  el.style.top = '0px'
  el.style.bottom = '0px'
  el.style.zIndex = '999'
  el.style.borderRadius = '4.75% / 3.5%'
  return el
}

let cards = [...document.querySelectorAll('.card-grid-item-card')]

cards.forEach(card => {
  let id = card.href.split('card/').slice(1).join('').split('/').slice(0,-1).join('/')
  let priceUrl = 'https://api.scryfall.com/cards/' + id
  let lastEnter = 0
  card.addEventListener('mouseenter', () => {
    let el = makePriceElement()
    card.appendChild(el)
    fetch(priceUrl).then(result => result.json()).then(obj => {
      let price = obj.prices.usd
      if(price) {
        el.innerText = '$' + price
      } else {
        el.innerText = 'No price found.'
      }
    })
  })
  card.addEventListener('mouseleave', () => {
    document.querySelectorAll('.price').forEach(a => a.parentNode.removeChild(a))
  })
})