I am currently making a Chrome extension which will fetch all the images from a website in the background and cache it. Upon clicking the icon, it should show all the cached images in the pop up.
Everything is working fine and i used this code to run the background script:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) {
chrome.tabs.executeScript(tabId, {file:"memo.js"});
});
But issue is: This script is caching only first time when page loads. When the user scrolls down the page and images which are coming dynamically are not being cached. My question is: How can I execute this script continuously so that images which are coming through ajax can be saved?
Also, this is my code for caching the image in background:
$.each($imgContainers, function (e, t) {
var n = t;
var img = new Image;
img.src = (t.getAttribute ? t.getAttribute("src") : false) || t.src;
img.description = (t.getAttribute ? t.getAttribute("alt") : false) || t.alt;
img.pinId=$(n).closest('a').attr('href');
img.height=t.height;
img.width=t.width;
if(img.description == "") {
img.description = n.alt;
}
window.cache = window.cache || {};
var data = window.cache[img.description];
window.cache[img.description] =img;
//console.log(window.cache['test']);
i++;
//console.log(img);
});
Thanks in advance..