diff --git a/lib/mule.js b/lib/mule.js index 8cf7685..34a97d0 100644 --- a/lib/mule.js +++ b/lib/mule.js @@ -89,7 +89,7 @@ function addreloader(mule, target) { var rld = $('
') rld.text('\u21bb') if (mule.data) { - var updated = new Date(mule.data.query.created) + var updated = new Date(mule.data.created) rld.attr('title', 'last updated: ' + updated.toLocaleString()) } rld.click(function(){ mule.reload() }) @@ -224,7 +224,11 @@ Mule.prototype.query = function(ignore_cache) { this.log('loading data') window.realmAPI('char/list', CR, function(xhr) { - xhr.done(onResponse).fail(onFail) + if(xhr.Chars){ + onResponse(xhr); + } else { + onFail(); + } }) function onFail() { @@ -239,15 +243,9 @@ Mule.prototype.query = function(ignore_cache) { } function onResponse(data) { + //console.log(data); self.busy = false; - if (!data.query || !data.query.results) { - self.error(data.query ? 'server error' : 'YQL service denied'); - if (data.query) { - self.log('full response:' + JSON.stringify(data.query)) - } - return; - } - var res = data.query.results + var res = data; function watchProgress(percent) { if (typeof percent != 'string') { @@ -309,13 +307,22 @@ var STATTAGS = 'MaxHitPoints MaxMagicPoints Attack Defense Speed Dexterity HpReg var STATABBR = 'HP MP ATT DEF SPD DEX VIT WIS'.split(' ') Mule.prototype.parse = function(data) { if (this.overlay) this.overlay.hide() - - var d = data.query.results.Chars + console.log(data); + if(data.Chars){ + var d = data.Chars + } else { + var d = data.query.results.Chars + } d = { Char: d.Char, Account: d.Account || {} } - data.query.results.Chars = d + if(data.Chars){ + data.Chars = d + } else { + data.query.results.Chars = d + } + // check if data changed? /* if (this.data && compare(d, this.data.query.results.Chars)) { diff --git a/lib/realmapi.js b/lib/realmapi.js index ffefe0b..fe75b31 100644 --- a/lib/realmapi.js +++ b/lib/realmapi.js @@ -1,3 +1,4 @@ + (function($, window) { var BASEURL = [ @@ -27,11 +28,10 @@ function update_counter() { $('#counter').text(_cnt).parent().toggle(!!_cnt); } - +var x2js = new X2JS(); function realmAPI(path, opts, extraopts, callback) { opts.ignore = Math.floor(1e3 + 9e3 * Math.random()) var url = BASEURL + path + '?' + $.param(opts) - if (typeof extraopts == 'function') { callback = extraopts extraopts = {} @@ -48,7 +48,7 @@ function realmAPI(path, opts, extraopts, callback) { ifr.src = url return } - +/* queue_request({ dataType: 'jsonp', url: 'https://query.yahooapis.com/v1/public/yql', @@ -56,7 +56,19 @@ function realmAPI(path, opts, extraopts, callback) { q: 'select * from xml where url="' + url + '"', format: 'json' }, - complete: callback + complete: function(result){ + console.log(JSON.stringify(result)); + callback(result); + } + }) +*/ + queue_request({ + url: 'https://cors-anywhere.herokuapp.com/' + url, + complete: function(result){ + var jsonResult = x2js.xml_str2json(result.responseText); + //console.log(JSON.stringify(jsonResult)); + callback(jsonResult); + } }) }