0

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..

Garrett Kadillak
  • 1,026
  • 9
  • 18
Kevin
  • 1
  • 2
  • 1
    Wrong approach. You should be watching the DOM for changes, not running on an interval. See http://stackoverflow.com/questions/2844565/is-there-a-jquery-dom-change-listener and https://code.google.com/p/mutation-summary/ – Xan Sep 24 '14 at 18:51
  • so how i can use this code is background page..? sorry for asking basic stuff.. – Kevin Sep 24 '14 at 19:40
  • I tried using "mutation summary" for tracking the changes in "img" but i am always getting "0 item added" in call back function...pls help.. – Kevin Sep 24 '14 at 21:37

0 Answers0