|
|
@ -4,15 +4,11 @@
|
|
|
|
(function() {
|
|
|
|
(function() {
|
|
|
|
var popup = {
|
|
|
|
var popup = {
|
|
|
|
init: function() {
|
|
|
|
init: function() {
|
|
|
|
|
|
|
|
popup.update([ 'p', {}, ' ' ], document, {});
|
|
|
|
|
|
|
|
|
|
|
|
var callback = function(tabs) {
|
|
|
|
var callback = function(tabs) {
|
|
|
|
( chrome || browser ).runtime.sendMessage({ id: 'get_apps', tab: tabs[0], source: 'popup.js' }, function(response) {
|
|
|
|
( chrome || browser ).runtime.sendMessage({ id: 'get_apps', tab: tabs[0], source: 'popup.js' }, function(response) {
|
|
|
|
if ( /complete|interacrive|loaded/.test(document.readyState) ) {
|
|
|
|
popup.update(popup.appsToDomTemplate(response));
|
|
|
|
popup.displayApps(response)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
|
|
|
|
popup.displayApps(response)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -25,18 +21,36 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
displayApps: function(response) {
|
|
|
|
update: function(dom) {
|
|
|
|
|
|
|
|
if ( /complete|interacrive|loaded/.test(document.readyState) ) {
|
|
|
|
|
|
|
|
popup.replaceDom(dom);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
|
|
|
|
popup.replaceDom(dom);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
replaceDom: function(domTemplate) {
|
|
|
|
|
|
|
|
var body = document.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while ( body.firstChild ) {
|
|
|
|
|
|
|
|
body.removeChild(body.firstChild);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body.append(jsonToDOM(domTemplate, document, {}));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
appsToDomTemplate: function(response) {
|
|
|
|
var
|
|
|
|
var
|
|
|
|
appName, confidence, version,
|
|
|
|
appName, confidence, version,
|
|
|
|
detectedApps = document.querySelector('#detected-apps'),
|
|
|
|
|
|
|
|
categories = [],
|
|
|
|
categories = [],
|
|
|
|
json = [];
|
|
|
|
template = [];
|
|
|
|
|
|
|
|
|
|
|
|
if ( response.tabCache && response.tabCache.count > 0 ) {
|
|
|
|
if ( response.tabCache && response.tabCache.count > 0 ) {
|
|
|
|
for ( appName in response.tabCache.appsDetected ) {
|
|
|
|
for ( appName in response.tabCache.appsDetected ) {
|
|
|
|
confidence = response.tabCache.appsDetected[appName].confidenceTotal;
|
|
|
|
confidence = response.tabCache.appsDetected[appName].confidenceTotal;
|
|
|
|
version = response.tabCache.appsDetected[appName].version;
|
|
|
|
version = response.tabCache.appsDetected[appName].version;
|
|
|
|
|
|
|
|
|
|
|
|
categories = [];
|
|
|
|
categories = [];
|
|
|
|
|
|
|
|
|
|
|
|
response.apps[appName].cats.forEach(function(cat) {
|
|
|
|
response.apps[appName].cats.forEach(function(cat) {
|
|
|
@ -59,7 +73,7 @@
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
json.push(
|
|
|
|
template.push(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'div', {
|
|
|
|
'div', {
|
|
|
|
class: 'detected-app'
|
|
|
|
class: 'detected-app'
|
|
|
@ -88,7 +102,7 @@
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
json = [
|
|
|
|
template = [
|
|
|
|
'div', {
|
|
|
|
'div', {
|
|
|
|
class: 'empty'
|
|
|
|
class: 'empty'
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -96,12 +110,7 @@
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
detectedApps.appendChild(jsonToDOM(json, document, {}));
|
|
|
|
return template;
|
|
|
|
|
|
|
|
|
|
|
|
// Force redraw after popup animation on Mac OS
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
|
|
document.body.appendChild(jsonToDOM([ 'span', { style: 'line-height: 1px;' }], document, {}));
|
|
|
|
|
|
|
|
}, 800);
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
slugify: function(string) {
|
|
|
|
slugify: function(string) {
|
|
|
|