title: Timer for chrome extension
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/14023983/chrome-extension-delay-condition">Chrome extension delay condition</a>  </p>
  </blockquote>
  
  
  
  <p>Im very beginner at extensions and by collecting codes from here and there I created a simple one which collects the tab's url (works for specific website) and using ajax Im sending it to my server in order to store it in my database.
  What Im trying to do is to add a timer so the browser button will be disabled (or do nothing) if the previous click occured in less than 5 seconds.</p>
  
  <p>Below is the structure of the extension:</p>
  
  <p><strong>Manifest:</strong></p>
  
  <pre><code>{
  "name": "The name",
  "icons": { "16": "Big.png",
         "48": "Big.png",
         "128": "Big.png" },
  "version": "1.0",
  "manifest_version": 2,
  "description": "and the description",
  "browser_action": {
  "default_icon": "icon.png",
  "default_popup": "popup.html"
  },
  "permissions": ["tabs", "&lt;all_urls&gt;"]
  }
  </code></pre>
  
  <p><strong>popup.js:</strong></p>
  
  <pre><code>chrome.tabs.getSelected(null,function(tab) {
  var Mp=tab.url
  if(Mp=='http://www.examplesite.com')
  {
  var xhr=new XMLHttpRequest();
  var Params;
  xhr.open("POST", "http://myserver.com/post_from_extension.asp", true);
  xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  Params='Url=' + tab.url;
  xhr.onreadystatechange=function()
      {
          if(xhr.readyState==4)
          {
          message.innerHTML=xhr.responseText;
          }
      }
  xhr.send(Params);
  }
  else
  {
  message.innerHTML='&lt;span style="font-family: Segoe UI, Tahoma;color: #f00"&gt;This is not a valid url&lt;/span&gt;';
  }
  });
  </code></pre>
  
  <p><strong>popup.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html style=''&gt;
  &lt;head&gt;
  &lt;script src='popup.js'&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body style="width:400px;"&gt;
  &lt;div id='message'&gt;&lt;span style="font-family: Segoe UI, Tahoma;color: #00f"&gt;Sending request&lt;/span&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>As a side question, is there any other method to post the url in my database, if not with Ajax?</p>
  
  <p>Thank you for reading me.</p>