You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.9 KiB

document.addEventListener('DOMContentLoaded', function() {
var
d = document,
analyzeHeaders = d.getElementById('analyze-headers'),
detectedApps = d.getElementById('detected-apps')
;
var popup = {
pollHeaders: null,
init: function() {
d.getElementById('options').addEventListener('click', function() {
12 years ago
window.open(chrome.extension.getURL('options.html'));
});
analyzeHeaders.innerHTML = chrome.i18n.getMessage('analyzeHeaders');
analyzeHeaders.removeAttribute('disabled');
chrome.tabs.getSelected(null, function(tab) {
if ( tab.url.match(/https?:\/\//) ) {
detectedApps.innerHTML = '<div class="empty">' + chrome.i18n.getMessage('noAppsDetected') + '</div>';
analyzeHeaders.addEventListener('click', function() {
analyzeHeaders.setAttribute('disabled', 'disabled');
12 years ago
chrome.extension.sendRequest({ id: 'fetch_headers', tab: tab });
12 years ago
popup.pollHeaders = setInterval(popup.displayApps, 100);
});
if ( parseInt(localStorage['autoAnalyzeHeaders']) ) {
analyzeHeaders.click();
}
} else {
detectedApps.innerHTML = '<div class="empty">' + chrome.i18n.getMessage('nothingToDo') + '</div>';
analyzeHeaders.setAttribute('disabled', 'disabled');
}
});
popup.displayApps();
},
displayApps: function() {
var appName, confidence;
chrome.tabs.getSelected(null, function(tab) {
chrome.extension.sendRequest({ id: 'get_apps', tab: tab }, function(response) {
if ( response.tabCache.analyzed.indexOf('headers') > 0 ) {
if ( popup.pollHeaders != null ) {
clearTimeout(popup.pollHeaders);
analyzeHeaders.innerHTML = chrome.i18n.getMessage('analyzeHeadersDone');
}
}
if ( response.tabCache.count > 0 ) {
detectedApps.innerHTML = '';
for ( appName in response.tabCache.appsDetected ) {
confidence = response.tabCache.appsDetected[appName].total;
html =
'<div class="detected-app">' +
12 years ago
'<a target="_blank" href="http://wappalyzer.com/applications/' + appName.toLowerCase().replace(/ /g, '-').replace(/[^\w-]/g, '') + '?utm_source=chrome&utm_medium=popup&utm_campaign=extensions">' +
'<img src="images/icons/' + appName + '.png"/>' +
'<span class="label">' + appName + ( confidence < 100 ? ' (' + confidence + '% sure)' : '' ) + '</span>' +
'</a>';
response.apps[appName].cats.map(function(cat) {
html +=
12 years ago
'<a target="_blank" href="http://wappalyzer.com/categories/' + response.categories[cat] + '?utm_source=chrome&utm_medium=popup&utm_campaign=extensions">' +
12 years ago
'<span class="category">' + chrome.i18n.getMessage('categoryName' + cat) + '</span>' +
'</a>';
});
html +=
'</a>' +
'</div>';
detectedApps.innerHTML = detectedApps.innerHTML + html;
}
}
});
});
}
};
popup.init();
});