Skip to content

Commit

Permalink
Merge pull request #1328 from GrosPoulet/master
Browse files Browse the repository at this point in the history
Fix for GitLab plug-in + new plug-ins (Nature, opendata)
  • Loading branch information
GrosPoulet authored Apr 14, 2024
2 parents 66caaf2 + 290f13b commit 9000795
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 4 deletions.
8 changes: 8 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,14 @@
{
"js": ["plugins/cineserie.js"],
"matches": ["*://*.cineserie.com/*"]
},
{
"js": ["plugins/opendata92.js"],
"matches": ["*://*.opendata.hauts-de-seine.fr/*"]
},
{
"js": ["plugins/nature.js"],
"matches": ["*://*.nature.com/*"]
}
]
}
8 changes: 4 additions & 4 deletions plugins/gitlab.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'gitlab',
version:'0.1',
version:'0.2',
favicon:'gitlab.png',
prepareImgLinks:function (callback) {
var res = [];

Expand Down Expand Up @@ -36,9 +37,8 @@ hoverZoomPlugins.push({
} else {
href = href + '&s=512';
}
}
// gitlab
if (href.indexOf('gitlab') != -1) {
} else {
// gitlab
href = href.replace(/\?width.*/, '');
}

Expand Down
47 changes: 47 additions & 0 deletions plugins/nature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'nature',
version:'0.1',
prepareImgLinks:function (callback) {
var res = [];

// sample: https://media.springernature.com/lw685/springer-static/image/art%3A10.1038%2Fs41586-024-07053-4/MediaObjects/41586_2024_7053_Fig1_HTML.png?as=webp
// -> https://media.springernature.com/full/springer-static/image/art%3A10.1038%2Fs41586-024-07053-4/MediaObjects/41586_2024_7053_Fig1_HTML.png?as=webp
// sample: https://images.nature.com/w140h79/magazine-assets/d41586-024-01036-1/d41586-024-01036-1_26947866.jpg
// -> https://images.nature.com/original/magazine-assets/d41586-024-01036-1/d41586-024-01036-1_26947866.jpg

const reFind1 = /\.nature.com\/l?[hw]\d+.*?\//;
const reReplace1 = '.nature.com/original/';
const reFind2 = /springernature.com\/l?[hw]\d+.*?\//;
const reReplace2 = 'springernature.com/full/';

function findFullsizeUrl(link, src) {
let fullsizeUrl = src.replace(reFind1, reReplace1).replace(reFind2, reReplace2);
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]').each(function() {
findFullsizeUrl($(this), this.src);
});

$('[style*=url]').each(function() {
// extract url from style
var backgroundImage = this.style.backgroundImage;
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);
}
}
});
54 changes: 54 additions & 0 deletions plugins/opendata92.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'opendata92',
version:'0.1',
prepareImgLinks:function (callback) {
var res = [];

// sample: https://opendata.hauts-de-seine.fr/explore/dataset/fr-229200506-plans-de-carrieres/files/aea63b50e86f1ed8d3f5f26b3a39c0af/300/
// -> https://opendata.hauts-de-seine.fr/explore/dataset/fr-229200506-plans-de-carrieres/files/aea63b50e86f1ed8d3f5f26b3a39c0af/download/

const reFind = '/300/';
const reReplace = '/download/';

function findFullsizeUrl(link, src) {
let fullsizeUrl = src.replace(reFind, reReplace);
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*="/300/"]').each(function() {
findFullsizeUrl($(this), this.src);
});

$('[style*=url]').filter(function() { return /\/300\//.test(this.style.backgroundImage) }).each(function() {
// extract url from style
var backgroundImage = this.style.backgroundImage;
const reUrl = /.*url\s*\(\s*(.*)\s*\).*/i
backgroundImage = backgroundImage.replace(reUrl, '$1');
// remove leading & trailing quotes
var backgroundImageUrl = backgroundImage.replace(/^['"]/, '').replace(/['"]+$/, '');
findFullsizeUrl($(this), backgroundImageUrl);
});

$('a[href*="/download/"]').each(function() {
let link = $(this);
let fullsizeUrl = this.href;

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

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

0 comments on commit 9000795

Please sign in to comment.