Move onMessage to separate function in WebExtension

main
Elbert Alias 8 years ago
parent 51b598cd65
commit 92fbcbd6e5

@ -84,7 +84,7 @@ a:active {
#about {
border-top: 1px solid #dbdbdb;
margin-top: 2.5rem;
padding: 1.5rem 0 1.5rem 0;
padding: 1.5rem 0 0 0;
}
#about img {

@ -75,22 +75,3 @@ img {
font-style: italic;
text-align: center;
}
#footer {
border-top: 1px solid #ccc;
margin-top: 17px;
overflow: hidden;
padding-top: 11px;
}
#footer a {
text-decoration: none;
}
#footer a:hover {
border-bottom: 1px solid #dbdbdb;
}
#options {
float: right;
}

@ -64,52 +64,10 @@
localStorage['version'] = version;
} catch(e) { }
function newMsg(message, sender, sendResponse) {
var
hostname,
a = document.createElement('a');
if ( typeof message.id != 'undefined' ) {
w.log('message: ' + message.id);
switch ( message.id ) {
case 'log':
w.log(message.message);
break;
case 'analyze':
tab = sender.tab;
a.href = tab.url.replace(/#.*$/, '');
hostname = a.hostname;
if ( headersCache[a.href] !== undefined ) {
message.subject.headers = headersCache[a.href];
}
w.analyze(hostname, a.href, message.subject);
break;
case 'ad_log':
w.adCache.push(message.subject);
break;
case 'get_apps':
sendResponse({
tabCache: tabCache[message.tab.id],
apps: w.apps,
categories: w.categories
});
break;
}
}
}
if (typeof chrome === "undefined") {
browser.runtime.onMessage.addListener(newMsg);
if ( typeof chrome === 'undefined' ) {
browser.runtime.onMessage.addListener(w.driver.onMessage);
} else {
chrome.runtime.onMessage.addListener(newMsg);
chrome.runtime.onMessage.addListener(w.driver.onMessage);
}
browser.tabs.query({}).then(function(tabs) {
@ -168,6 +126,49 @@
}
},
onMessage: function(message, sender, sendResponse) {
var
hostname,
a = document.createElement('a');
if ( typeof message.id != 'undefined' ) {
w.log('message: ' + message.id);
switch ( message.id ) {
case 'log':
w.log(message.message);
break;
case 'analyze':
tab = sender.tab;
a.href = tab.url.replace(/#.*$/, '');
hostname = a.hostname;
if ( headersCache[a.href] !== undefined ) {
message.subject.headers = headersCache[a.href];
}
w.analyze(hostname, a.href, message.subject);
break;
case 'ad_log':
w.adCache.push(message.subject);
break;
case 'get_apps':
sendResponse({
tabCache: tabCache[message.tab.id],
apps: w.apps,
categories: w.categories
});
break;
}
}
},
goToURL: function(args) {
var url = args.url + ( typeof args.medium === 'undefined' ? '' : '?pk_campaign=chrome&pk_kwd=' + args.medium);

@ -10,11 +10,6 @@ document.addEventListener('DOMContentLoaded', function() {
popup = {
init: function() {
d.getElementById('options').addEventListener('click', function() {
window.open(browser.extension.getURL('options.html'));
});
browser.tabs.query({ active: true }).then(function(tabs) {
if ( tabs[0].url.match(/https?:\/\//) ) {
detectedApps.innerHTML = '<div class="empty">' + browser.i18n.getMessage('noAppsDetected') + '</div>';

@ -13,9 +13,5 @@
</head>
<body>
<div id="detected-apps"></div>
<div id="footer">
<a href="javascript: void(0);" data-i18n="options" id="options">Options</a>
</div>
</body>
</html>

Loading…
Cancel
Save