Skip to content

Commit

Permalink
Merge pull request #1341 from GrosPoulet/master
Browse files Browse the repository at this point in the history
New plug-in for: US Army sites
  • Loading branch information
GrosPoulet authored May 1, 2024
2 parents f8fb5ae + 0cfd9be commit 17f7325
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,10 @@
{
"js": ["plugins/unsplash.js"],
"matches": ["*://*.unsplash.com/*"]
},
{
"js": ["plugins/usarmy.js"],
"matches": ["*://*.defense.gov/*", "*://*.mil/*"]
}
]
}
43 changes: 43 additions & 0 deletions plugins/usarmy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'usarmy',
version:'0.1',
prepareImgLinks:function (callback) {
var res = [];

// sample: https://media.defense.gov/2023/Mar/21/2003447102/400/400/0/230302-F-LD209-1015.JPG
// -> https://media.defense.gov/2023/Mar/21/2003447102/0/400/0/230302-F-LD209-1015.JPG

const reFind = /(.*\.defense\.gov\/.*?\/.*?\/.*?\/.*?)\/.*?\/(.*)/;
const reReplace = '$1/0/$2';

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]').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);
}
}
});

0 comments on commit 17f7325

Please sign in to comment.