Skip to content

Instantly share code, notes, and snippets.

@aarongrando
Last active June 11, 2020 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarongrando/51f99974317f8991157a882b0460558c to your computer and use it in GitHub Desktop.
Save aarongrando/51f99974317f8991157a882b0460558c to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Scryfall Oracle Search
// @namespace https://gran.do
// @version 0.1
// @description Click oracle text on Scryfall cards to search for other cards with that text.
// @match http*://scryfall.com/*
// @include http*://scryfall.com/*
// @copyright 2020+, Aaron Grando
// @require http://code.jquery.com/jquery-latest.min.js
// @match http*://scryfall.com/*
// @run-at document-idle
// @grant GM_addStyle
// ==/UserScript==
/* global $ */
GM_addStyle ( `
.card-text-oracle p:hover {
cursor: pointer;
text-decoration: underline;
}
` );
(function () {
function pickSearchWords(element) {
var oracle_line = element.clone().children().remove().end().text().trim(),
card_name = element.parent().parent().parent().find('.card-text-title').clone().children().remove().end().text().trim(),
non_words = ['a', 'the', 'it', 'that', 'this', 'they', 'would', 'be', 'by', 'to', 'an'],
numbers = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],
punctuation = '•!"#$%&\'()*,-.:;<=>?@[\\]^_`{|}~';
var nameless_oracle_line = oracle_line.replace(card_name, '')
var raw_characters = nameless_oracle_line.trim().split('');
var clean_characters = raw_characters.filter(function(letter) {
return punctuation.indexOf(letter) === -1;
});
var clean_oracle_line = clean_characters.join('');
var clean_words = clean_oracle_line.replace(/\+/g,'%2B').replace(/\//g,'%2F').split(' ');
clean_words = clean_words.filter(Boolean)
var good_words = clean_words.filter(function(word) {
return non_words.indexOf(word) === -1;
});
var good_nonnumeric_words = good_words.filter(function(word) {
return numbers.indexOf(word) === -1;
});
var search_string = '';
return good_nonnumeric_words;
}
$('.card-text-oracle p').click(function(e) {
e.preventDefault();
var search_string = '';
pickSearchWords($(this)).forEach(function(word) {
search_string += 'o%3A' + word + "+"
});
window.location = 'https://scryfall.com/search?q=' + search_string
});
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment