Skip to content

Commit

Permalink
Merge pull request #1248 from GrosPoulet/master
Browse files Browse the repository at this point in the history
Fix for Flickr plug-ins (#1238)
  • Loading branch information
GrosPoulet authored Oct 20, 2023
2 parents c6a8527 + f2f1e1d commit 256ce05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
11 changes: 7 additions & 4 deletions plugins/flickr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'Flickr',
version:'1.2',
version:'1.3',
prepareImgLinks:function (callback) {
cLog('Plug-In: ' + this.name);

Expand Down Expand Up @@ -371,6 +371,8 @@ hoverZoomPlugins.push({
url = dataJson.sizes['h'].url;
} else if (dataJson.sizes['l']) {
url = dataJson.sizes['l'].url;
} else if (dataJson.sizes['b']) {
url = dataJson.sizes['b'].url;
}
} else {
if (dataJson.url_o) {
Expand All @@ -389,6 +391,8 @@ hoverZoomPlugins.push({
url = dataJson.url_h;
} else if (dataJson.url_l) {
url = dataJson.url_l;
} else if (dataJson.url_b) {
url = dataJson.url_b;
}
}

Expand Down Expand Up @@ -438,12 +442,11 @@ hoverZoomPlugins.push({
if (fullsizeUrl == undefined) {

cLog('Proceed with API call for id: ' + id);
// API call: api.flickr.com/services/rest/?photo_id=3379827411&method=flickr.photos.getSizes&format=json&nojsoncallback=1&api_key=26a8c097b4cc3237a4efad4df5f8fc7a
// no data found locally so proceed with API call
// WARNING: CORB error (Cross-Origin Read Blocking) raised when calling the API from the content script.
// cf https://www.chromium.org/Home/chromium-security/extension-content-script-fetches
// Workaround: call the API from background page.
var requestUrl = 'https://api.flickr.com/services/rest/?photo_id=' + id + '&method=flickr.photos.getSizes&format=json&nojsoncallback=1&api_key=26a8c097b4cc3237a4efad4df5f8fc7a';
var requestUrl = 'https://api.flickr.com/services/rest/?photo_id=' + id + '&method=flickr.photos.getSizes&format=json&nojsoncallback=1&api_key=9bb671af308f509d0c82146cbc936b3c';

chrome.runtime.sendMessage({action:'ajaxGet', url:requestUrl}, function (response) {

Expand All @@ -453,7 +456,7 @@ hoverZoomPlugins.push({
var responseJson = JSON.parse(response);
} catch (e) { return; }

// sort by width
// sort by height
let sortedsizes = responseJson.sizes.size.sort(function(a,b) { if (parseInt(a.height) > parseInt(b.height)) return -1; if (parseInt(a.height) < parseInt(b.height)) return 1; return 0; })
let fullsizeUrl = sortedsizes[0].source;

Expand Down
36 changes: 16 additions & 20 deletions plugins/flickr_a.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
var hoverZoomPluginFlickerA = {
name:'Flickr_a',
version:'0.3',
version:'0.4',
prepareImgLinks:function (callback) {
var res = [];

Expand All @@ -20,12 +20,6 @@ var hoverZoomPluginFlickerA = {
src = src.replace(/_[mst]\./, '.');
data.hoverZoomSrc = [src];
res.push(link);

// Second processing, this time with API calls.
// Will overwrite values from first processing if larger images are found.
/*if (options.showHighRes) {
hoverZoomPluginFlickerA.prepareImgLinkFromSrc(link);
}*/
});
callback($(res), this.name);

Expand All @@ -38,15 +32,12 @@ var hoverZoomPluginFlickerA = {
filter = 'a[href*="/photos/"]';
}
$(filter).each(function () {
hoverZoomPluginFlickerA.prepareImgLinkFromHref($(this));
hoverZoomPluginFlickerA.prepareImgLinkFromHref($(this), callback);
});
/*$(filter).one('mouseenter', function() {
hoverZoom.prepareOEmbedLink(this, 'http://www.flickr.com/services/oembed?format=json&url=', this.href);
});*/
},

// Get details from this URL: http://www.flickr.com/photos/{user-id}/{photo-id}
prepareImgLinkFromHref:function (link) {
prepareImgLinkFromHref:function (link, callback) {
var href = link.attr('href'),
aHref = href.split('/'),
photoIdIndex = 5;
Expand All @@ -63,7 +54,7 @@ var hoverZoomPluginFlickerA = {
if (parseInt(photoId) != photoId) {
return;
}
hoverZoomPluginFlickerA.prepareImgLinkFromPhotoId(link, photoId);
hoverZoomPluginFlickerA.prepareImgLinkFromPhotoId(link, photoId, callback);
},

// Get details from this URL: http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstbo].(jpg|gif|png)
Expand All @@ -79,7 +70,7 @@ var hoverZoomPluginFlickerA = {
},

// Prepares a link by making a Flickr API call.
prepareImgLinkFromPhotoId:function (link, photoId) {
prepareImgLinkFromPhotoId:function (link, photoId, callback) {
if (!link || !photoId) {
return;
}
Expand All @@ -90,6 +81,9 @@ var hoverZoomPluginFlickerA = {
if (storedUrl) {
data.hoverZoomSrc = [storedUrl];
link.addClass('hoverZoomLink');
var res = [];
res.push(link);
callback($(res), this.name);
} else {
link.mouseenter(function () {
data.hoverZoomMouseOver = true;
Expand All @@ -98,7 +92,8 @@ var hoverZoomPluginFlickerA = {
}
data.hoverZoomFlickrApiCalled = true;
//var apiKey = '0bb8ac4ab9a737b644c407ba8f59e9e7';
var apiKey = '26a8c097b4cc3237a4efad4df5f8fc7a';
//var apiKey = '26a8c097b4cc3237a4efad4df5f8fc7a';
const apiKey = '9bb671af308f509d0c82146cbc936b3c';
var requestUrl = 'https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=' + apiKey + '&photo_id=' + photoId + '&format=json&nojsoncallback=1';
chrome.runtime.sendMessage({action:'ajaxGet', url:requestUrl}, function (response) {
var rsp = JSON.parse(response);
Expand All @@ -107,15 +102,16 @@ var hoverZoomPluginFlickerA = {
return;
}
var src = '';
for (var i = 0; i < rsp.sizes.size.length; i++) {
if (options.showHighRes && rsp.sizes.size[i].label == 'Original' || /*options.showHighRes &&*/ rsp.sizes.size[i].label == 'Large' || rsp.sizes.size[i].label.indexOf('Medium') == 0) {
src = rsp.sizes.size[i].source;
}
}
// sort by height
let sortedsizes = rsp.sizes.size.sort(function(a,b) { if (parseInt(a.height) > parseInt(b.height)) return -1; if (parseInt(a.height) < parseInt(b.height)) return 1; return 0; })
src = sortedsizes[0].source;
if (src != '') {
data.hoverZoomSrc = [src];
link.addClass('hoverZoomLink');

var res = [];
res.push(link);
callback($(res), this.name);
// Image is displayed if the cursor is still over the link
if (data.hoverZoomMouseOver)
hoverZoom.displayPicFromElement(link);
Expand Down

0 comments on commit 256ce05

Please sign in to comment.