document.addEventListener('DOMContentLoaded', function() { var d = document, detectedApps = d.getElementById('detected-apps'); var popup = { init: function() { d.getElementById('options').addEventListener('click', function() { window.open(chrome.extension.getURL('options.html')); }); chrome.tabs.getSelected(null, function(tab) { if ( tab.url.match(/https?:\/\//) ) { detectedApps.innerHTML = '
' + chrome.i18n.getMessage('noAppsDetected') + '
'; } else { detectedApps.innerHTML = '
' + chrome.i18n.getMessage('nothingToDo') + '
'; } }); popup.displayApps(); }, displayApps: function() { var appName, confidence, version; chrome.tabs.getSelected(null, function(tab) { chrome.extension.sendRequest({ id: 'get_apps', tab: tab }, function(response) { if ( response.tabCache && response.tabCache.count > 0 ) { detectedApps.innerHTML = ''; for ( appName in response.tabCache.appsDetected ) { confidence = response.tabCache.appsDetected[appName].confidenceTotal; version = response.tabCache.appsDetected[appName].version; html = '
' + '' + '' + '' + appName + '' + ( version ? ' ' + version : '' ) + ( confidence < 100 ? ' (' + confidence + '% sure)' : '' ) + '' + ''; response.apps[appName].cats.forEach(function(cat) { html += '' + '' + chrome.i18n.getMessage('categoryName' + cat) + '' + ''; }); html += '' + '
'; detectedApps.innerHTML = detectedApps.innerHTML + html; } } }); }); } }; popup.init(); });