-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathekos_script.js
78 lines (62 loc) · 1.72 KB
/
ekos_script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var integrate = function(overlay) {
console.log('parsing page');
if (overlay != null) {
// Paint the overlay.
overlay();
} else {
console.log('no page overlay');
}
}
var teardown = function() {
console.log('teardown');
}
var pageMatchers = [
{matcher: function(domRoot) {
return $("h1.page_title:contains('Inventory')", domRoot).length > 0;
},
overlay: deployInventoryScan},
{matcher: function(domRoot) {
return $("div#invoice_title", domRoot).length > 0;
},
overlay: invoiceAddons}];
var matchPageToOverlay = function() {
if ($('div#batch_main_info_panel').length > 0){
return batchPageOverlay;
}
console.log('no overlay found for this page');
for (var i in pageMatchers) {
if (pageMatchers[i].matcher(document)) {
console.log('matched page');
return pageMatchers[i].overlay(document);
}
}
return null;
}
/**
* Main Function.
*/
var main = function() {
// Check to see if this is a frame. If so, paint any applicable overlay.
var overlay = matchPageToOverlay();
if (overlay == null) {
// Inform the background page that this tab should have a page-action.
chrome.runtime.sendMessage({
action: MSG_ACTIONS.SHOW_PAGE_ACTION
});
return;
}
// Listen for changes to firebase authentication.
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.action == MSG_ACTIONS.AUTH_STATE) {
if (request.state) {
integrate(overlay);
} else {
teardown();
}
}
});
// Subscribe to the auth state change. The AUTH_STATE message will be sent
// immediately with the current state, and sent again as the state changes.
chrome.runtime.sendMessage({action: MSG_ACTIONS.SUB_AUTH_STATE});
}();