Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 23rd, 2012  |  syntax: JavaScript  |  size: 1.38 KB  |  views: 65  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Test 1: Update 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. // Test 2: Update contentscript.js
  7. // For example, replace alert with confirm.
  8.  
  9. // manifest.json
  10. {
  11.   "name": "Reload test",
  12.   "version": "1",
  13.   "content_scripts": [{
  14.     "matches": ["<all_urls>"],
  15.     "js": ["contentscript.js"]
  16.   }],
  17.   "background": {"scripts":["bg.js"]}
  18. }
  19.  
  20. // contentscript.js
  21. alert('Test');
  22.  
  23. // bg.js
  24. function reloadOnChange(url, checkIntervalMS) {
  25.     if (!window.__watchedFiles) {
  26.         window.__watchedFiles = {};
  27.     }
  28.  
  29.     (function() {
  30.         var self = arguments.callee;
  31.         var xhr = new XMLHttpRequest();
  32.  
  33.         xhr.onreadystatechange = function() {
  34.             if (xhr.readyState == 4) {
  35.                 if (__watchedFiles[url] &&
  36.                     __watchedFiles[url] != xhr.responseText) {
  37.                     window.location.reload();
  38.                 } else {
  39.                     __watchedFiles[url] = xhr.responseText
  40.                     window.setTimeout(self, checkIntervalMS || 1000);
  41.                 }
  42.             }
  43.         };
  44.  
  45.         xhr.open("GET", url, true);
  46.         xhr.send();
  47.     })();
  48. }
  49. reloadOnChange(chrome.extension.getURL('/manifest.json'));
  50. reloadOnChange(chrome.extension.getURL('/contentscript.js'));
clone this paste RAW Paste Data