1

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;
}
  • 1
    If you need any help with this, feel free to add me on skype: zachripper – Zachrip Jul 01 '13 at 02:16
  • Awesome thank you so much Zachrip. I will probably contact you shortly! – Josh Robertson Jul 01 '13 at 04:05
  • @Zachrip I use a mac and so would my friends, so by my understanding Rich Notifications dont work on macs? Only windows and chromeOS? I would have to use Chrome Desktop Notifications and Background pages instead right? – Josh Robertson Jul 01 '13 at 04:27
  • Rich Notifications are the same thing I think. I'm not quite sure. You should be able to display some sort of notification. – Zachrip Jul 01 '13 at 11:04

1 Answers1

3

There is no way to programmatically open a Chrome Extension popup as of yet. But you can use the desktop notifications to display a notification, and in the beta Chrome versions, there are rich notifications. You would use a background script to randomly set a timeout, and when it times out you can have it create a notification, and play the sound.

Reference links:

Chrome Desktop Notifications

Rich Notifications

Background Pages

Community
  • 1
  • 1
Zachrip
  • 3,242
  • 1
  • 17
  • 32