Skip to content

Commit

Permalink
Merge pull request #1322 from GrosPoulet/master
Browse files Browse the repository at this point in the history
New plug-in for: onzemondial
  • Loading branch information
GrosPoulet authored Mar 31, 2024
2 parents 9e174d6 + cd56c97 commit 5125a92
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
6 changes: 5 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,10 @@
{
"js": ["plugins/bluesky.js"],
"matches": ["*://*.bsky.app/*"]
}
},
{
"js": ["plugins/onzemondial.js"],
"matches": ["*://*.onzemondial.com/*"]
}
]
}
42 changes: 42 additions & 0 deletions plugins/onzemondial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'onzemondial',
version:'0.1',
prepareImgLinks:function (callback) {
var res = [];

// sample: https://static.onzemondial.com/8/2024/01/photos/340481/zoom-%F0%9F%93%9D-c%C3%B4te-d-ivoire---nigeria--les-tops-et-les-flops-.jpg
// -> https://static.onzemondial.com/8/2024/01/photos/340481/%F0%9F%93%9D-c%C3%B4te-d-ivoire---nigeria--les-tops-et-les-flops-.jpg

function findFullsizeUrl(link, src) {
let fullsizeUrl = src.replace('/zoom-', '/').replace('/moyen-', '/');
if (fullsizeUrl == src) return;

if (link.data().hoverZoomSrc == undefined) { link.data().hoverZoomSrc = [] }
if (link.data().hoverZoomSrc.indexOf(fullsizeUrl) == -1) {
link.data().hoverZoomSrc.unshift(fullsizeUrl);
res.push(link);
}
}

$('img[src*="/zoom-"], img[src*="/moyen-"]').each(function() {
findFullsizeUrl($(this), this.src);
});

$('[style*="/zoom-"], [style*="/moyen-"]').each(function() {
// extract url from style
var backgroundImage = this.style.backgroundImage;
if (backgroundImage && (backgroundImage.indexOf('/zoom-') != -1 || backgroundImage.indexOf('/moyen-') != -1)) {
const reUrl = /.*url\s*\(\s*(.*)\s*\).*/i
backgroundImage = backgroundImage.replace(reUrl, '$1');
// remove leading & trailing quotes
var backgroundImageUrl = backgroundImage.replace(/^['"]/, '').replace(/['"]+$/, '');
findFullsizeUrl($(this), backgroundImageUrl);
}
});

if (res.length) {
callback($(res), this.name);
}
}
});

0 comments on commit 5125a92

Please sign in to comment.