Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 7822ed2

Browse files
committed
update from JSONP to JSON API
1 parent cf7e0d4 commit 7822ed2

File tree

5 files changed

+2319
-56
lines changed

5 files changed

+2319
-56
lines changed

build/gfycat.js

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ var gfyObject = function (gfyElem, gfyIndex) {
373373
gfyRootElem.parentNode.replaceChild(newElem, gfyRootElem);
374374
gfyRootElem = newElem;
375375
// call gfycat API to get info for this gfycat
376-
loadJSONP("https://gfycat.com/cajax/get/" + gfyId, function (data) {
377-
if (data) {
378-
gfyItem = data.gfyItem;
376+
loadJSON("https://api.gfycat.com/v1/gfycats/" + gfyId, function (dataGfyData) {
377+
if (dataGfyData) {
378+
gfyItem = JSON.parse(dataGfyData).gfyItem;
379379
gfyMp4Url = gfyItem.mp4Url;
380380
gfyWebmUrl = gfyItem.webmUrl;
381381
gfyFrameRate = gfyItem.frameRate;
@@ -416,30 +416,17 @@ var gfyObject = function (gfyElem, gfyIndex) {
416416

417417
// used to load ajax info for each gfycat on the page
418418
// callback functions must be setup and uniquely named for each
419-
function loadJSONP(url, callback, context) {
420-
var unique = Math.floor((Math.random()*10000000) + 1);
421-
// INIT
422-
var name = "_" + gfyId + "_" + unique++;
423-
if (url.match(/\?/)) url += "&callback=" + name;
424-
else url += "?callback=" + name;
425-
426-
// Create script
427-
var script = document.createElement('script');
428-
script.type = 'text/javascript';
429-
script.src = url;
430-
431-
// Setup handler
432-
window[name] = function (data) {
433-
callback.call((context || window), data);
434-
document.getElementsByTagName('head')[0].removeChild(script);
435-
script = null;
436-
try {
437-
delete window[name];
438-
} catch (e) {}
419+
function loadJSON(url, callback, context) {
420+
var xobj = new XMLHttpRequest();
421+
xobj.overrideMimeType("application/json");
422+
xobj.open('GET', url, true); // Replace 'my_data' with the path to your file
423+
xobj.onreadystatechange = function () {
424+
if (xobj.readyState == 4 && xobj.status == "200") {
425+
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
426+
callback(xobj.responseText);
427+
}
439428
};
440-
441-
// Load JSON
442-
document.getElementsByTagName('head')[0].appendChild(script);
429+
xobj.send(null);
443430
}
444431

445432
function setSize() {

build/gfycat.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)