Skip to content

Instantly share code, notes, and snippets.

@kodawah
Created October 14, 2019 22:08
Show Gist options
  • Save kodawah/e7756e4949e41a0160225c1410aa7d25 to your computer and use it in GitHub Desktop.
Save kodawah/e7756e4949e41a0160225c1410aa7d25 to your computer and use it in GitHub Desktop.
javascript:(function() {
var card = prompt("Card Name");
if (!card || card == "") {
return;
}
trimmedCard = card.trim();
var sites = [];
/* Buylists */
sites.push("https://www.cardkingdom.com/purchasing/mtg_singles?filter%5Bsearch%5D=mtg_advanced&filter%5Bname%5D=");
sites.push("https://abugames.com/buylist/singles?language=[\"English\"]&search=");
sites.push("https://store.channelfireball.com/buylist/search?q=");
/* Miniature Market Crazy Buylist */
var mmBuyBackSite = "https://www.miniaturemarket.com/buyback/data/productsearch/";
var form = document.createElement('FORM');
form.method = 'POST';
form.action = mmBuyBackSite;
form.target = "_blank";
var input = document.createElement("INPUT");
input.name = "search";
input.type = "hidden";
input.value = trimmedCard;
form.appendChild(input);
document.body.appendChild(form);
form.submit();
form.remove();
/* Finally StarCityGame, needs to be the last */
var xhr = new XMLHttpRequest();
var url = "https://cors-anywhere.herokuapp.com/https://www.starcitygames.com/buylist/search?search-type=name&name=" + encodeURIComponent(trimmedCard);
xhr.onreadystatechange = function() {
document.title = "StarCityGames";
if (xhr.readyState === 4) {
document.body.innerHTML = "<pre>" + syntaxHighlight(JSON.stringify(JSON.parse(xhr.response), null, 4)) + "</pre>";
} else {
document.body.innerHTML = "<h1>Loading SCG...</h1>\n";
}
};
xhr.open("GET", url, true);
xhr.send();
/* Reverse so they are in the same order as above */
sites.reverse().forEach(openWindow);
function openWindow(value, index, array) {
var theCard = encodeURIComponent(trimmedCard);
window.open(value + theCard, '_blank');
}
function syntaxHighlight(json) {
var styles = `pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
.string { color: green; }
.number { color: darkorange; }
.boolean { color: blue; }
.null { color: magenta; }
.key { color: blue; }
`;
var styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
};
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment