1. var timeToSee = '0'; // This is the hour in 24-hour time
  2. var stocks = [ 'GOOG', 'TXN', 'AAPL' ]; // Array of stocks
  3.  
  4. var onlyOnce = 1; // If this is 1, then it only gives you the stocks the first time you unlock the screen after timeToSee.  If it is 0, then it will display the stocks every time you unlock the screen after timeToSee
  5.  
  6.  
  7. device.screen.on("unlock", function(){
  8.     var screenUnlocked = device.localStorage.getItem('stockScreenUnlocked');
  9.     var today = new Date();
  10.     if ((!screenUnlocked || screenUnlocked !== today.toLocaleDateString() || onlyOnce != 1) && timeToSee <= today.getHours())
  11.     {
  12.         var urlS = 'http://finance.google.com/finance/info?client=ig&q=';
  13.         urlS += stocks.join();
  14.         device.ajax(
  15.             {
  16.                 url: urlS,
  17.                 type: 'GET',
  18.                 headers: {
  19.                     'Content-Type': 'application/json'
  20.                 }
  21.             }, function onSuccess(body, textStatus, response)
  22.                 {
  23.                     var notify;
  24.                     body = body.substring(3);
  25.                     body = body.replace(/(\r\n|\n|\r)/gm,"");
  26.                     var bodyJson = JSON.parse(body);
  27.                     if (!(body) && bodyJson)
  28.                     {
  29.                         notify = device.notifications.createNotification('Error');
  30.                         notify.content = 'Error: ' + body;
  31.                         notify.show();
  32.                     }
  33.                     else
  34.                     {
  35.                         for (var x=0; x < bodyJson.length;++x)
  36.                         {
  37.                             notify = device.notifications.createNotification('Stock: ' + bodyJson[x].t);
  38.                             notify.content = 'Current: ' + bodyJson[x].l_cur + ', ' + bodyJson[x].c + ' updated at ' + bodyJson[x].lt;
  39.                             notify.on('click', makeFunc(x));
  40.                             notify.show();
  41.                         }
  42.                         if (onlyOnce == 1)
  43.                             device.localStorage.setItem('stockScreenUnlocked', today);
  44.                     }
  45.                 },
  46.                 function onError(textStatus, response)
  47.                 {
  48.                     notify = device.notifications.createNotification('Error');
  49.                     notify.content = 'Error: ' + textStatus;
  50.                     notify.show();
  51.                 }
  52.             );
  53.     }
  54. });
  55.  
  56. function makeFunc(j)
  57. {
  58.     return function()
  59.     {
  60.         device.browser.launch('http://www.google.com/finance?q='+stocks[j]);
  61.     };
  62. }