-
-
Save fearphage/229038 to your computer and use it in GitHub Desktop.
This file contains 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
const Name = 'gatherer', | |
Gatherer = 'http://gatherer.wizards.com/', | |
Base = '<style>'+ <![CDATA[ | |
.error {font-style:oblique; line-height:1.8} | |
.logo {display:inline-block; max-width:100%} | |
.logo > img {border:none; max-width:100%} | |
.loading + .logo {opacity:0.4} | |
.error + .logo {opacity:0.7} | |
]]> +'</style>'+ | |
<div class={Name}><div id={Name}> </div | |
><a class="gatherer logo" href={Gatherer} accesskey="l"><img | |
src="http://resources.wizards.com/Gatherer/Images/gatherer_card_banner.jpg" | |
/></a></div>; | |
CmdUtils.CreateCommand({ | |
name: 'gatherer', | |
description: 'Gatherer'.link(Gatherer), | |
icon: Gatherer +'Images/favicon.ico', | |
argument: { | |
name: 'gatherer suggest', | |
label: 'card name', | |
rankLast: true, | |
suggest: function gtrr_suggest(txt, htm, cb, sx){ | |
var ss = [CmdUtils.makeSugg(txt, null, null, sx)]; | |
sx || ss.push($.ajax({ | |
url: Gatherer +'Handlers/InlineCardSearch.ashx', | |
data: {nameFragment: txt}, | |
dataType: 'json', | |
success: function nt_gtrrsg_success(o){ | |
var tl = txt.toLowerCase(), ss = []; | |
for each(let c in o.Results){ | |
let {Name} = c; | |
if(Name.toLowerCase() === tl) continue; | |
let nh = Utils.escapeHtml(Name); | |
ss.push({ | |
text: Name, html: nh, | |
summary: nh +' '+ c.Snippet.small(), | |
}); | |
} | |
ss.length && cb(ss); | |
}, | |
})); | |
return ss; | |
}, | |
}, | |
execute: function gtrr_execute({object: {text}}){ | |
Utils.openUrlInBrowser(this._req(text)); | |
}, | |
preview: function gtrr_preview(pb, {object: {text}}){ | |
var cn; | |
while(!(cn = pb.ownerDocument.getElementById(Name))) pb.innerHTML = Base; | |
if(!text) return; | |
cn.className += ' loading'; | |
CmdUtils.previewAjax(pb, { | |
url: this._req(text), | |
success: function gtrr_success(htm){ | |
if(/<img src="..\/..\/(Handlers\/Image.*?)"/.test(htm)){ | |
cn.innerHTML = ( | |
'<img class="card" src="'+ Gatherer + RegExp.$1 + | |
'" border="0"/>').link(this.url); | |
cn.className = ''; | |
return; | |
} | |
var h = (/<div\s+id=".*?_DidYouMean">[^]+?<\/div>/.test(htm) | |
? CmdUtils.absUrl(RegExp.lastMatch, Gatherer) | |
: htm); | |
cn.innerHTML = h; | |
cn.className = 'error'; | |
}, | |
}); | |
}, | |
_req: function gtrr__req(x)(Gatherer +'Pages/Card/Details.aspx?name='+ | |
encodeURIComponent(x.trim())), | |
author: 'satyr', license: 'MIT', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment