console.log('POPUP.JS');
document.addEventListener('DOMContentLoaded', function() {
  console.log('POPUP LOADED');
  document.getElementById('run').addEventListener('click', function() {
    chrome.runtime.sendMessage({message: "toggle", state: "run"}, function(response){
			  console.log(response.farewell);
      	}
    );
    console.log('PRESSED ON');
  });
   chrome.runtime.sendMessage({message: "isrunning"}, function(response){
	   console.log("isrunning?", response);
      if(response.isrunning === true) document.getElementById("run").disabled = true;
      else document.getElementById("run").disabled = false;
   });
});

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
	if (request.message == "update") {
		document.getElementById('runres').innerHTML(request.state);
	}
	if (request.message == "start") {
		 document.getElementById("run").disabled = true;
	}
	if (request.message == "stop") {
		document.getElementById("run").disabled = false;
	}
});
