Last active
April 24, 2025 17:12
-
-
Save the-glima/58315cfc94fc0ef5cbd162996b904cf8 to your computer and use it in GitHub Desktop.
Some checks before buying on Liga/MTG Brasil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find Duplicate Cards | |
var ligaCards = $('.cardtitle').toArray() | |
var mtgBrasilcards = $('.checkout-product--subtitle a').toArray() | |
var cardTitles = [...ligaCards, ...mtgBrasilcards].map(c => c.innerText) | |
var toFindDuplicates = array => array.filter((item, index) => array.indexOf(item) !== index) | |
var duplicateElements = toFindDuplicates(cardTitles); | |
var findDiff = (array, array2) => array.filter(i => !array2.includes(i)); | |
console.log(`%cCards ${cardTitles.length}`, "color:aqua; font-size: 18px"); | |
console.log(cardTitles) | |
// Log Duplicates | |
if (!duplicateElements.length) { | |
console.log("%cNo duplicates, all good!", "color:lime; font-size: 18px"); | |
console.log('') | |
} else { | |
console.log("%cFound some duplicate cards", "color:red; font-size: 18px"); | |
duplicateElements.forEach(item => console.log(item)) | |
console.log('') | |
} | |
// Log quantities above 1 | |
var qtyLiga = $('.qty').toArray() | |
var qtyMTGBrasil = $('.checkout-product--qty').toArray() | |
var qtyValues = [...qtyLiga, ...qtyMTGBrasil].map(q => q.value) | |
var valuesLiga = qtyLiga.filter(q => q.value !== '1') | |
var valuesMTGBrasil = qtyMTGBrasil.filter(q => q.value !== '1') | |
if (!valuesLiga.length && !valuesMTGBrasil.length) { | |
console.log("%cNo quantity above 1", "color:lime; font-size: 18px"); | |
console.log('') | |
} else { | |
console.log("%cFound a card with quantity above 1", "color:orange; font-size: 18px"); | |
var resultLiga = valuesLiga.map(i => i.closest('.row').querySelector('.cardtitle')) | |
var resultMTGBrasil = valuesMTGBrasil.map(i => i.closest('.table-cart-row').querySelector('.checkout-product--qty')) | |
resultLiga.forEach(item => console.log(item.innerText, item)) | |
resultMTGBrasil.forEach(item => console.log(item.innerText, item)) | |
console.log('') | |
} | |
// Log comparison with custom list | |
var customList = [] | |
var dupsInCustomList = toFindDuplicates(customList) | |
if (!dupsInCustomList.length) { | |
console.log("%cNo duplicate in custom list", "color:lime; font-size: 18px"); | |
console.log('') | |
} else { | |
console.log("%cFound some dupes in custom list", "color:red; font-size: 18px"); | |
dupsInCustomList.forEach(item => console.log(item)) | |
console.log('') | |
} | |
var foundCustomDup = cardTitles.filter(c => { | |
var result = customList.some(p => { | |
if (c.match(new RegExp(p, 'ig'))) { | |
return !!c.match(new RegExp(p, 'ig')).filter((str) => str !== '').length | |
} | |
}) | |
if (result) return c | |
}) | |
if (!foundCustomDup.length) { | |
console.log("%cNo duplicate from shopping list and custom list", "color:lime; font-size: 18px"); | |
console.log('') | |
} else { | |
console.log("%cFound some dupes from shopping list and custom list", "color:red; font-size: 18px"); | |
[...new Set(foundCustomDup)].forEach(item => console.log(item)) | |
console.log('') | |
} | |
// Log missing cards in custom list | |
var missingCustomList = [] | |
var diffInCustomList = findDiff(missingCustomList, cardTitles) | |
if (!diffInCustomList.length) { | |
console.log("%cNo missing cards from custom list", "color:lime; font-size: 18px"); | |
console.log('') | |
} else { | |
console.log("%cFound some missing cards in custom list", "color:red; font-size: 18px"); | |
diffInCustomList.forEach(item => console.log(item)) | |
console.log('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment