From 2af78a268fd8782c0b213da89aaf6cf51ca5277c Mon Sep 17 00:00:00 2001 From: GrosPoulet Date: Fri, 26 Apr 2024 11:43:53 +0200 Subject: [PATCH] New plug-in for: techradar.com --- manifest.json | 4 ++++ plugins/techradar.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 plugins/techradar.js diff --git a/manifest.json b/manifest.json index ceef8eafd..ca9687bb3 100644 --- a/manifest.json +++ b/manifest.json @@ -2053,6 +2053,10 @@ { "js": ["plugins/kotnauction.js"], "matches": ["*://*.kotnauction.com/*"] + }, + { + "js": ["plugins/techradar.js"], + "matches": ["*://*.techradar.com/*"] } ] } diff --git a/plugins/techradar.js b/plugins/techradar.js new file mode 100644 index 000000000..a6455e0e9 --- /dev/null +++ b/plugins/techradar.js @@ -0,0 +1,43 @@ +var hoverZoomPlugins = hoverZoomPlugins || []; +hoverZoomPlugins.push({ + name:'techradar', + version:'0.1', + prepareImgLinks:function (callback) { + var res = []; + + // sample: https://cdn.mos.cms.futurecdn.net/mzjKCZk8VD37iw4gQgXUHV-650-80.jpg.webp + // -> https://cdn.mos.cms.futurecdn.net/mzjKCZk8VD37iw4gQgXUHV.jpg + + const reFind = /-\d+-\d+\.jpg.*/; + const reReplace = '.jpg'; + + 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); + } + } +});