I am trying to make a very simple extension for chrome, but I am stuck in passing a variable from popup html.
This is the code that I still have:
manifest:
{ "background": { "scripts": [ "background.js" ] }, "browser_action": { "default_icon": "img/test.png", "default_popup": "popup.html", "default_title": "Auto Clicker" }, "description": "Auto click", "manifest_version": 2, "name": "Auto Clicker", "permissions": [ "activeTab" ], "version": "0.0.1" }
background.js
chrome.extension.onMessage.addListener( function(request, sender, sendResponse) { switch (request.directive) { case "popup-click-1":
myscript.js
function foo(){ document.getElementById('submit-button').click(); } setInterval(function(){ foo()}, 20000) foo();
popup.js
function clickHandler(e) { chrome.extension.sendMessage({directive: "popup-click-1"}, function(response) { this.close();
popup.html
<html> <head> <title>test</title> <script src="popup.js"></script> </head> <body> test <form> <input id="1" type = "text"> </br> </form> <button id='submit'> etst </button> </body> </html>
While I run foo (), when you press the submit button, which runs every 20 seconds. What I want to achieve is to add a number in the popup html and then use that number in myscript.js to set the time of the setInterval function.
So here is the scenario:
I open the page, I click the extension button. There is a popup with a form. I put 30,000 and then hit Sumbit. This way foo () will run every 30 seconds.