I am trying to create a manual Google search from chrome extension. The html contains a form field. The user can enter a number to this field. Then I add that number into a url parameter and initiate a GET request based on that.
Here is my manifest file
{
"manifest_version": 2,
"name": "Qoogle",
"description": "Customized google search for your daily needs",
"version": "1.0",
"permissions": [
"tabs",
"http://www.google.co.in/",
"https://www.google.co.in/"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
This is my html that is opened in a new tab when clicked on the extension button.
<form action="" name="timer">
<input type="number" name="quantity" id="time">
<input type="radio" name="timertype" id="t1" value="seconds" checked>Seconds
<input type="radio" name="timertype" id="t2" value="minutes">Minutes
<br>
<input type="submit" id="timer" value="Set Timer">
*<b>Enter any positive number</b>
</form>
<script src="validate.js"></script>
And finally this is my validate.js
//Method for new http request
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );0
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
// do stuff here
xmlHttp.send(null);
return xmlHttp.responseText;
};
}
}
//Funtion to validate and send timer request
function timer() {
var value = document.getElementById('time').value;
var url;
if(document.getElementById('t1').checked) {
url = "https://www.google.co.in/#q=set+timer+for+" + value + "+seconds";
httpGet(url)
}
else{
url = "https://www.google.co.in/#q=set+timer+for+" + value + "+minutes";
httpGet(url)
}
}
window.onload = function(){
document.getElementById('timer').onclick = timer;
};
This doesn't seem to be working. What could be the reason? No error messages are logged to the console.