Skip to content

Commit

Permalink
Merge pull request #1099 from GrosPoulet/master
Browse files Browse the repository at this point in the history
New plug-in for: geograph.org
  • Loading branch information
GrosPoulet authored Feb 26, 2023
2 parents 4329ce4 + 9b87e4a commit 08f15f3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,14 @@
{
"js": ["plugins/hejto.js"],
"matches": ["*://*.hejto.pl/*"]
},
{
"js": ["plugins/geograph.js"],
"matches": ["*://*.geograph.org/*",
"*://*.geograph.org.uk/*",
"*://*.geograph.org.gg/*",
"*://*.geograph.ie/*",
"*://*.hlipp.de/*"]
}
]
}
53 changes: 53 additions & 0 deletions plugins/geograph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'geograph',
version:'0.1',
prepareImgLinks:function (callback) {
var res = [];

hoverZoom.urlReplace(res,
'img[src], [style*="url"]',
[/_\d+x\d+/, /_\d+XX\d+/],
['', '']
);

hoverZoom.urlReplace(res,
'img[src], [style*="url"]',
[/_\d+x\d+/, /_\d+XX\d+/],
['_1024x1024', '_1024x1024']
);

// sample: https://s0.geograph.org.uk/geophotos/02/50/43/2504372_3398f781_120x120.jpg
// fullsize: https://s0.geograph.org.uk/geophotos/02/50/43/2504372_3398f781_original.jpg (NSFW !)
hoverZoom.urlReplace(res,
'img[src], [style*="url"]',
[/_\d+x\d+/, /_\d+XX\d+/],
['_original', '_original']
);

$('[href*="/photo/"], [href*="/gridref/"]').one('mouseenter', function() {
if ($(this).find('img').length) return;
var link = $(this);
// clean previous result
link.data().hoverZoomSrc = [];
link.data().hoverZoomGallerySrc = [];
link.data().hoverZoomGalleryCaption = [];
hoverZoom.prepareFromDocument($(this), this.href, function(doc, callback) {
console.log(link);
let imgs = doc.querySelectorAll('img[src*="photos/"]');
if (imgs) {
var gallery = [];
$(imgs).each(function() {
console.log(this.src);
gallery.push([this.src.replace(/_\d+x\d+/, '').replace(/_\d+XX\d+/, '')]);
link.data().hoverZoomGalleryCaption.push([this.alt]);
});
callback(gallery);
hoverZoom.displayPicFromElement(link);
}
}, true); // get source async
});

callback($(res), this.name);
}
});

0 comments on commit 08f15f3

Please sign in to comment.