I made a chrome extension. Its very simple. Theres an array of compliments and I randomly pull out one when somebody clicks on the extension and prints it out. I also use chromes tts(text to speech) to say the compliment out loud.Thats very simple, but....
I want it to randomly give you a compliment without somebody clicking on the chrome extension. Is this possible? I've done some research with no success. Heres my code:
popup.js:
$(document).ready(function() {
var compliments = ['You are awesome.', 'Looking good.'];
var randomCompliment = Math.floor(Math.random()*compliments.length);
$('#compliment').append('<li>' + compliments[randomCompliment] + '</li>');
chrome.tts.speak(compliments[randomCompliment])
});
manifest.json:
{
"manifest_version": 2,
"name": "Complimentor",
"description": "This extension gives you a compliment.",
"version": "1.0",
"browser_action": {
"default_icon": {
"19": "icon_19.png",
"38": "icon_38.png"
},
"default_title": "Complimentor",
"default_popup": "popup.html"
},
"permissions": ["tts"]
}
popup.html:
<!doctype html>
<html>
<head>
<script src="jquery.js"></script>
<script src="popup.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="popup">
<div id="highlight"></div>
<ul id="compliment"></ul>
</div>
</body>
</html>
style.css:
body {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(0,0,0,0.1))); /* Chrome,Safari4+ */
}
.popup {
width: 300px;
font: 14px helvetica-neue, helvetica, sans-serif;
color: #666;
position: relative;
text-align: center;
}
#hightlight {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,.3)), color-stop(100%, rgba(255,255,255,0))); /* Chrome,Safari4+ */
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.popup ul {
list-style: none;
margin: 0;
padding: 0;
}
.popup li {
padding: 3px 0;
}