From a98b4dbb7dd8a007d8778e1aafdec700c151b744 Mon Sep 17 00:00:00 2001 From: Emma J Date: Mon, 1 Oct 2018 15:05:35 +0000 Subject: [PATCH] Updated cors proxy for codewars --- dist/codebadges.min.js | 2 +- js/codebadges.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/codebadges.min.js b/dist/codebadges.min.js index 3aa159c..8cdebef 100644 --- a/dist/codebadges.min.js +++ b/dist/codebadges.min.js @@ -3,4 +3,4 @@ * Copyright 2018 codemzy * Licensed under MIT */ -if("undefined"==typeof jQuery)throw new Error("codeBadges JavaScript requires jQuery. jQuery must be included before codeBadges JavaScript.");!function(t,e){var o=function(t){return e(".code-badge").html('
Loading...
'),new o.init(t)},a={codecademy:!0,codeschool:!0,codewars:!0,freecodecamp:!0,github:!0,treehouse:!0},s='
-
-
User
Not Found
',n=function(t,e){var o=e.small?"smaller":"";return'
'+t.top+'
'+t.top_type+'
'+e.name+'
'+t.user_type+'
'+t.bottom_type+"
"+t.bottom+'
since '+t.date+"
"};o.prototype={_get:{_codecademyAPI:function(t,o){var a="https://www.codecademy.com/"+t;e.get(a,function(t){var e=t.match(/

Skills completed<\/p>[\s|\S]*?

([\s|\S]*?)<\/h3>[\s|\S]*?

Badges<\/p>/m)[1],a=t.match(/

([\s|\S]*?)<\/h3>[\s|\S]*?total points<\/small>/m)[1],s=t.match(/Joined([\s|\S]*?)<\/small>/m)[1].split(", ")[1];o(!1,{top:parseInt(e,10),top_type:"badges",user_type:"Codecademy Student",bottom:a,bottom_type:"Points",date:s})}).fail(function(){o("error")})},_codeschoolAPI:function(t,o){var a="https://www.codeschool.com/users/"+t+".json";e.ajax({type:"GET",dataType:"jsonp",url:a}).done(function(t){var e=t.badges.length,a=t.user.total_score,s=t.user.member_since.split("-")[0];o(!1,{top:e,top_type:"badges",user_type:"CodeSchool Student",bottom:a,bottom_type:"Score",date:s})}).fail(function(){o("error")})},_codewarsAPI:function(t,o){var a="https://cors.now.sh/https://www.codewars.com/users/"+t;e.get(a,function(t){var e=t.match(/Honor:<\/b>(.+?)<\/div>/m)[1],a=t.match(/Rank:<\/b>(.+?)<\/div>/m)[1],s=t.match(/Member Since:<\/b>(.+?)<\/div>/m)[1].split(" ")[1];o(!1,{top:e,top_type:"honor",user_type:"CodeWars Member",bottom:a,bottom_type:"Rank",date:s})}).fail(function(){o("error")})},_freecodecampAPI:function(t,o){var a="https://www.freecodecamp.org/"+t;e.get(a,function(t){for(var a=t.match(/

\[ ([\s|\S]*?) \]<\/h1>/)[1],s=t.replace(/[\s|\S]*?<\/thead>/g).match(//g).length+" challenges",n=t.match(//g).join(" "),i=e(n).find("tbody").find("tr:first td:eq(1)"),r=[],d=0;d<3;d++)r.push(parseInt(e(i[d]).text().split(",")[1],10));r.sort(function(t,e){return t-e});var c=r[0];o(!1,{top:parseInt(a,10),top_type:"points",user_type:"FreeCodeCamp Student",bottom:s,bottom_type:"Completed",date:c})}).fail(function(){o("error")})},_githubAPI:function(t,o){var a="https://api.github.com/users/"+t;e.get(a,function(t){var e=t.followers,a=t.public_repos+" public repos",s=t.created_at.split("-")[0];o(!1,{top:e,top_type:"followers",user_type:"GitHub User",bottom:a,bottom_type:"Created",date:s})}).fail(function(){o("error")})},_treehouseAPI:function(t,o){var a="https://teamtreehouse.com/"+t+".json";e.get(a,function(t){var e=t.points.total,a=t.badges.length+" achievements",s=t.badges&&t.badges.length>0?t.badges[0].earned_date.split("-")[0]:"-";o(!1,{top:e,top_type:"points",user_type:"Treehouse Student",bottom:a,bottom_type:"Completed",date:s})}).fail(function(){o("error")})}},_html:{badgeDisplay:function(t,o,a){var s=this.nameDisplay(a),i=n(o,s);return e(".code-badge."+t+" .inner").html(i),i},badgeError:function(t){return e(".code-badge."+t+" .inner").html(s),s},nameDisplay:function(t){return t.length>10?t.length>16?{name:t.slice(0,13)+"...",small:!0}:{name:t,small:!0}:{name:t,small:!1}}},_validate:{checkName:function(t){return("string"==typeof t||t instanceof String)&&t.length<150&&t},checkBadge:function(t){return!!a[t]&&t}},anyBadge:function(t,e){var o=this._validate.checkName(e)||this.name;this.lastName=o;var a=this._validate.checkBadge(t);return this.lastBadge=a,a&&o?this._get["_"+a+"API"](o,function(t,e){t?t&&this._html.badgeError(a):this._html.badgeDisplay(a,e,o)}.bind(this)):this._html.badgeError(a),this},codecademy:function(t){return this.anyBadge("codecademy",t)},codeschool:function(t){return this.anyBadge("codeschool",t)},codewars:function(t){return this.anyBadge("codewars",t)},freecodecamp:function(t){return this.anyBadge("freecodecamp",t)},github:function(t){return this.anyBadge("github",t)},treehouse:function(t){return this.anyBadge("treehouse",t)}},o.init=function(t){this._validate.checkName(t)&&(this.name=t||"codemzy")},o.init.prototype=o.prototype,t.codeBadges=o}(window,jQuery); \ No newline at end of file +if("undefined"==typeof jQuery)throw new Error("codeBadges JavaScript requires jQuery. jQuery must be included before codeBadges JavaScript.");!function(t,e){var a=function(t){return e(".code-badge").html('
Loading...
'),new a.init(t)},o={codecademy:!0,codeschool:!0,codewars:!0,freecodecamp:!0,github:!0,treehouse:!0},s='
-
-
User
Not Found
',n=function(t,e){var a=e.small?"smaller":"";return'
'+t.top+'
'+t.top_type+'
'+e.name+'
'+t.user_type+'
'+t.bottom_type+"
"+t.bottom+'
since '+t.date+"
"};a.prototype={_get:{_codecademyAPI:function(t,a){var o="https://www.codecademy.com/"+t;e.get(o,function(t){var e=t.match(/

Skills completed<\/p>[\s|\S]*?

([\s|\S]*?)<\/h3>[\s|\S]*?

Badges<\/p>/m)[1],o=t.match(/

([\s|\S]*?)<\/h3>[\s|\S]*?total points<\/small>/m)[1],s=t.match(/Joined([\s|\S]*?)<\/small>/m)[1].split(", ")[1];a(!1,{top:parseInt(e,10),top_type:"badges",user_type:"Codecademy Student",bottom:o,bottom_type:"Points",date:s})}).fail(function(){a("error")})},_codeschoolAPI:function(t,a){var o="https://www.codeschool.com/users/"+t+".json";e.ajax({type:"GET",dataType:"jsonp",url:o}).done(function(t){var e=t.badges.length,o=t.user.total_score,s=t.user.member_since.split("-")[0];a(!1,{top:e,top_type:"badges",user_type:"CodeSchool Student",bottom:o,bottom_type:"Score",date:s})}).fail(function(){a("error")})},_codewarsAPI:function(t,a){var o="https://cors-anywhere.herokuapp.com/https://www.codewars.com/users/"+t;e.get(o,function(t){var e=t.match(/Honor:<\/b>(.+?)<\/div>/m)[1],o=t.match(/Rank:<\/b>(.+?)<\/div>/m)[1],s=t.match(/Member Since:<\/b>(.+?)<\/div>/m)[1].split(" ")[1];a(!1,{top:e,top_type:"honor",user_type:"CodeWars Member",bottom:o,bottom_type:"Rank",date:s})}).fail(function(){a("error")})},_freecodecampAPI:function(t,a){var o="https://www.freecodecamp.org/"+t;e.get(o,function(t){for(var o=t.match(/

\[ ([\s|\S]*?) \]<\/h1>/)[1],s=t.replace(/[\s|\S]*?<\/thead>/g).match(//g).length+" challenges",n=t.match(//g).join(" "),i=e(n).find("tbody").find("tr:first td:eq(1)"),r=[],d=0;d<3;d++)r.push(parseInt(e(i[d]).text().split(",")[1],10));r.sort(function(t,e){return t-e});var c=r[0];a(!1,{top:parseInt(o,10),top_type:"points",user_type:"FreeCodeCamp Student",bottom:s,bottom_type:"Completed",date:c})}).fail(function(){a("error")})},_githubAPI:function(t,a){var o="https://api.github.com/users/"+t;e.get(o,function(t){var e=t.followers,o=t.public_repos+" public repos",s=t.created_at.split("-")[0];a(!1,{top:e,top_type:"followers",user_type:"GitHub User",bottom:o,bottom_type:"Created",date:s})}).fail(function(){a("error")})},_treehouseAPI:function(t,a){var o="https://teamtreehouse.com/"+t+".json";e.get(o,function(t){var e=t.points.total,o=t.badges.length+" achievements",s=t.badges&&t.badges.length>0?t.badges[0].earned_date.split("-")[0]:"-";a(!1,{top:e,top_type:"points",user_type:"Treehouse Student",bottom:o,bottom_type:"Completed",date:s})}).fail(function(){a("error")})}},_html:{badgeDisplay:function(t,a,o){var s=this.nameDisplay(o),i=n(a,s);return e(".code-badge."+t+" .inner").html(i),i},badgeError:function(t){return e(".code-badge."+t+" .inner").html(s),s},nameDisplay:function(t){return t.length>10?t.length>16?{name:t.slice(0,13)+"...",small:!0}:{name:t,small:!0}:{name:t,small:!1}}},_validate:{checkName:function(t){return("string"==typeof t||t instanceof String)&&t.length<150&&t},checkBadge:function(t){return!!o[t]&&t}},anyBadge:function(t,e){var a=this._validate.checkName(e)||this.name;this.lastName=a;var o=this._validate.checkBadge(t);return this.lastBadge=o,o&&a?this._get["_"+o+"API"](a,function(t,e){t?t&&this._html.badgeError(o):this._html.badgeDisplay(o,e,a)}.bind(this)):this._html.badgeError(o),this},codecademy:function(t){return this.anyBadge("codecademy",t)},codeschool:function(t){return this.anyBadge("codeschool",t)},codewars:function(t){return this.anyBadge("codewars",t)},freecodecamp:function(t){return this.anyBadge("freecodecamp",t)},github:function(t){return this.anyBadge("github",t)},treehouse:function(t){return this.anyBadge("treehouse",t)}},a.init=function(t){this._validate.checkName(t)&&(this.name=t||"codemzy")},a.init.prototype=a.prototype,t.codeBadges=a}(window,jQuery); \ No newline at end of file diff --git a/js/codebadges.js b/js/codebadges.js index 564e1ab..63df732 100644 --- a/js/codebadges.js +++ b/js/codebadges.js @@ -76,7 +76,7 @@ if (typeof jQuery === 'undefined') { }); }, _codewarsAPI: function(name, callback) { - var url = 'https://cors.now.sh/' + 'https://www.codewars.com/users/' + name; // scraping via cors.now.sh due to CORS + var url = 'https://cors-anywhere.herokuapp.com/' + 'https://www.codewars.com/users/' + name; // scraping via cors.now.sh due to CORS $.get(url, function(data){ var points = data.match(/Honor:<\/b>(.+?)<\/div>/m)[1]; var kyu = data.match(/Rank:<\/b>(.+?)<\/div>/m)[1];