(function(document, window){ function Counter(){ this.SUMMARY_TIMEFRAME = 1; this.id = 'npp-widget-war'; this.title = 'Total Cost of War on Terror'; this.location = 'New Jersey'; this.slug = 'war'; this.startAmount = 6409000000000; this.startDate = Date.UTC(2020, 9, 1, 4, 0, 0, 0); this.endAmount = 8043000000000; this.endDate = Date.UTC(2022, 9, 1, 3, 59, 59, 0); this.ratePerMS = 25.9069004615; this.pause = false; this.timer = null; this.multiplier = 0.04102958197885700500; this.intcomma = function(number) { return parseInt(number, 10).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }; this.increment = function() { var now = new Date(); var endDate = Date.UTC( now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds() ); if(this.pause) { endDate = this.endDate; } var diff = endDate - this.startDate; return (this.startAmount + (diff * this.ratePerMS)) * this.multiplier; }; this.init = function() { var counterEl = document.getElementById(this.id); var titleEl = document.createElement('h3'); titleEl.innerHTML = this.title; titleEl.setAttribute('class', 'npp-widget-title'); counterEl.appendChild(titleEl); var summaryEl = document.createElement('p'); summaryEl.setAttribute('class', 'npp-widget-summary'); var summaryText = ''; var duration = 'hour'; if(this.SUMMARY_TIMEFRAME > 1) { duration = this.SUMMARY_TIMEFRAME + ' hrs'; } if("military" === "non-military") { summaryText = 'Every ' + duration + ' federal taxpayers in ' + this.location + ' pay ' + this.costPerTimeframe() + ' toward ' + this.title + '.'; } else { summaryText = 'Every ' + duration + ' taxpayers in ' + this.location + ' are paying ' + this.costPerTimeframe() + ' for ' + this.title + '.'; } summaryEl.innerHTML = summaryText; counterEl.appendChild(summaryEl); var totalEl = document.createElement('p'); totalEl.setAttribute('id', this.id + '-total'); totalEl.setAttribute('class', 'npp-widget-total'); counterEl.appendChild(totalEl); var metaEl = document.createElement('p'); metaEl.setAttribute('class', 'npp-widget-meta'); metaEl.innerHTML = 'See more counters at ' + '' + "https://www.nationalpriorities.org/cost-of/" + ''; counterEl.appendChild(metaEl); this.timer = window.setInterval(function(that) {that.update(); }, 100, this); }; this.update = function() { document.getElementById(this.id + "-total").innerHTML = "$" + this.intcomma(this.increment()); }; this.costPerTimeframe = function() { var timeframeMilliseconds = this.SUMMARY_TIMEFRAME * 3600 * 1000; var perTimeframeIncrementAmount = (timeframeMilliseconds * this.ratePerMS * this.multiplier); return '$' + this.intcomma(perTimeframeIncrementAmount); }; } function addOnloadHandler(func) { if (window.addEventListener) { window.addEventListener('load', func, false); } else if (window.attachEvent) { window.attachEvent('onload', func); } } var initCounter = function() { if(document.getElementById("npp-widget-war") !== null) { new Counter().init(); } }; addOnloadHandler(initCounter); }(document, window));