Guest User

Untitled

a guest
Apr 23rd, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // manifest.json
  2. // Replace content_scripts with _content_scripts to see that
  3. // Changing the manifest file does not update the extension.
  4. //  (or simply change the version number)
  5. {
  6.   "name": "Reload test",
  7.   "version": "1",
  8.   "content_scripts": [{
  9.     "matches": ["<all_urls>"],
  10.     "js": ["script.js"]
  11.   }],
  12.   "background": {"scripts":["bg.js"]}
  13. }
  14.  
  15. // script.js
  16. alert('Test');
  17.  
  18. // bg.js
  19. function reloadOnChange(url, checkIntervalMS) {
  20.     if (!window.__watchedFiles) {
  21.         window.__watchedFiles = {};
  22.     }
  23.  
  24.     (function() {
  25.         var self = arguments.callee;
  26.         var xhr = new XMLHttpRequest();
  27.  
  28.         xhr.onreadystatechange = function() {
  29.             if (xhr.readyState == 4) {
  30.                 if (__watchedFiles[url] &&
  31.                     __watchedFiles[url] != xhr.responseText) {
  32.                     window.location.reload();
  33.                 } else {
  34.                     __watchedFiles[url] = xhr.responseText
  35.                     window.setTimeout(self, checkIntervalMS || 1000);
  36.                 }
  37.             }
  38.         };
  39.  
  40.         xhr.open("GET", url, true);
  41.         xhr.send();
  42.     })();
  43. }
  44. console.log('loaded')
  45. reloadOnChange(chrome.extension.getURL('/manifest.json'));
Advertisement
Add Comment
Please, Sign In to add comment