Created
August 6, 2009 22:36
-
-
Save satyr/163600 to your computer and use it in GitHub Desktop.
Opens all the latest strips on http://comics.com in a new tab.
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
CmdUtils.CreateCommand({ | |
name: 'comics.com', | |
description: ( | |
'Opens all the latest strips on '+ | |
'<a href="http://comics.com">comics.com</a> in a new tab.'), | |
author: {name: 'satyr', email: 'murky.satyr\x40gmail.com'}, | |
license: 'MIT', | |
icon: 'http://c0389161.cdn.cloudfiles.rackspacecloud.com/img/v1/favicon.ico', | |
argument: CmdUtils.NounType('cmc type', ['Comics', 'Editorials'], '^'), | |
execute: function cmc_execute(args){ | |
var {proto} = this; | |
proto._type = args.object.text; | |
$.ajax(proto); | |
}, | |
preview: function cmc_preview(pb, args){ | |
pb.innerHTML = this.description. | |
replace(/\bstrips\b/, args.object.text.bold()); | |
}, | |
url: 'http://comics.com/', | |
success: function cmca_success(h){ | |
var sb = Cu.Sandbox(this.url); | |
Cu.evalInSandbox(/\bvar CMC\b[^]+?(?=<\/script>)/(h), sb); | |
var {CMC} = sb, me = this, durl = ( | |
'data:text/html,<!--comics-->'+ | |
(<><title>{this._type} - {this.name}</title><base | |
href={this.url} target="_blank"/><link | |
rel="icon" href={this.icon}/></>)); | |
var {browser} = Utils.openUrlInBrowser(durl); | |
Utils.listenOnce(browser, 'load', function onload(){ | |
var doc = this.contentDocument; | |
for each(let [o] in CMC[me._type]){ | |
$.ajax({ | |
p: doc.body.appendChild(doc.createElement('p')), | |
url: me.url + o.URL, | |
title: o.Comic, | |
desc: o.Description.replace(/<br[^>]*>/g, '\n'), | |
success: me._set, | |
error: me.error, | |
}); | |
} | |
}, true); | |
}, | |
error: Utils.log, | |
_set: function cmc__set(h){ | |
var src = /\bhttp:\/\/[^/\s]+\/dyn\/str_\S+?\.full\.gif/(h); | |
this.p.innerHTML = ( | |
(<a href={this.url} title={this.desc}>{this.title}</a>) + | |
(<br/>) + | |
(<img src={src}/>)); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment