shared/scripts/lib/notifications.js
/**
 * Polls and runs threshold logic on the background thread to avoid the need
 * for being in the extension to get notifications.
 */
Polls and runs threshold logic on the background thread to avoid the need
for being in the extension to get notifications.
Polls and runs threshold logic on the background thread to avoid the need for being in the extension to get notifications .
function pollForNotifications() {
  Promise.all([
    storage.get('settings'),
    storage.get('log')
  ]).then(function(resp) {
    var settings = resp[0];
    var log = resp[1];
    var totalOwed = 0;
    Object.keys(log).forEach(function(domain) {
      log[domain].filter(function(item) {
        if (item && item.author && item.author.list.length) {
          return item.author.list.some(function(item) {
            return item.bitcoin || item.dwolla || item.paypal;
          });
        }
      }).forEach(function(hasPaymentInfo) {
        var internal = Object.create(hasPaymentInfo);
        var calculated = calculate(settings, internal);
        var amountNum = parseFloat(calculated.estimatedAmount);
        totalOwed += amountNum;
        if (amountNum > 0) {
          settings.moneyIsOwed = true;
        }
        if (settings.reminderThreshLocal && (amountNum >= parseFloat(settings.reminderThreshLocal.slice(1))) && !settings.localReminded)  {
          notify('tipsy-thersh-local', 'local', amountNum.toFixed(2));
          settings.localReminded = true;
        }
      });
    });
    if (settings.reminderThreshGlobal && (totalOwed >= parseFloat(settings.reminderThreshGlobal.slice(1))) && !settings.globalReminded) {
      notify('tipsy-thresh-global', 'global', totalOwed.toFixed(2));
      settings.globalReminded = true;
    }
  }).catch(function(ex) {
    console.log(ex, ex.message);
  });
}
function pollForNotifications ( ) { Promise . all ( [ storage . get ( 'settings' ) , storage . get ( 'log' ) ] ) . then ( function ( resp ) { var settings = resp [ 0 ] ; var log = resp [ 1 ] ; var totalOwed = 0 ; Object . keys ( log ) . forEach ( function ( domain ) { log [ domain ] . filter ( function ( item ) { if ( item && item . author && item . author . list . length ) { return item . author . list . some ( function ( item ) { return item . bitcoin || item . dwolla || item . paypal ; } ) ; } } ) . forEach ( function ( hasPaymentInfo ) { var internal = Object . create ( hasPaymentInfo ) ; var calculated = calculate ( settings , internal ) ; var amountNum = parseFloat ( calculated . estimatedAmount ) ; totalOwed += amountNum ; if ( amountNum > 0 ) { settings . moneyIsOwed = true ; } if ( settings . reminderThreshLocal && ( amountNum >= parseFloat ( settings . reminderThreshLocal . slice ( 1 ) ) ) && ! settings . localReminded ) { notify ( 'tipsy-thersh-local' , 'local' , amountNum . toFixed ( 2 ) ) ; settings . localReminded = true ; } } ) ; } ) ; if ( settings . reminderThreshGlobal && ( totalOwed >= parseFloat ( settings . reminderThreshGlobal . slice ( 1 ) ) ) && ! settings . globalReminded ) { notify ( 'tipsy-thresh-global' , 'global' , totalOwed . toFixed ( 2 ) ) ; settings . globalReminded = true ; } } ) . catch ( function ( ex ) { console . log ( ex , ex . message ) ; } ) ; }
Polls and runs threshold logic on the background thread to avoid the need
 for being in the extension to get notifications.
Polls and runs threshold logic on the background thread to avoid the need for being in the extension to get notifications .
// Iterate all visited pages. // Filter down to those with valid payment information. // Has a valid author list. // Don't modify the existing object. // let notifications know there is money to pay