-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
97 lines (87 loc) · 3.36 KB
/
Copy pathbackground.js
File metadata and controls
97 lines (87 loc) · 3.36 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Search Citeria
*/
const ADDRESS_DESCRIPTION_CRITERIA = 'private';
const CONTENT_URL_CASEID_CRITERIA = 'caseID';
const BASE_URI_CASEID_CRITERIA = 'baseURI';
const CONTENT_URL_ATTRIBUTE = 'data-content-url';
const ADDRESS_PAGE_TITLE_CRITERIA = CONFIG.pageTitles.address;
const LIVING_ARRANGEMENTS_PAGE_TITLE_CRITERIA = CONFIG.pageTitles.livingArrangement;
const HOUSEHOLD_MEAL_GROUP_PAGE_TITLE_CRITERIA = CONFIG.pageTitles.householdMealGroup;
/*
Selectors
*/
const ACTIVE_PAGE_TITLE_SELECTOR = `.tabLabel[aria-selected="true"][id*="${CONFIG.domSelectorPrefix}"][id*="Client"][id*="Section-stc_tablist"][id*="ContentPane"]:not([title="Cases and Clients"])`;
const TAB_LIST_SELECTOR = '[id*="Client"][id$="Section-stc_tablist"][class*="TabList"]';
const ALL_TABS_SELECTOR = `.tabLabel[id*="${CONFIG.domSelectorPrefix}"][id*="Client"][id*="Section-stc_tablist"][id*="ContentPane"]:not([title="Cases and Clients"])`;
const CURRENT_USER_SELECTOR = '[title*="Welcome "]';
/*
Observer
*/
const OBSERVER_CONFIG = {
attributes: true,
subtree: true,
childList: true,
attributeFilter: ["aria-selected"]
};
// create an observer instance
const observer = new MutationObserver(function (mutations) {
// We need only first event and only new value of the title
mutations.forEach(mutation => {
if (mutation.target.ariaSelected === "true")
handleTitleElement(mutation.target)
})
});
/*
Start script
*/
// setting selector to retrieve selected tab
waitForElement(ACTIVE_PAGE_TITLE_SELECTOR).then((element) => {
handleTitleElement(element);
console.debug("Adding listener to tab list for new entries")
let tabStrip = document.querySelector(TAB_LIST_SELECTOR);
// pass in the target node, as well as the observer options
observer.observe(tabStrip, OBSERVER_CONFIG);
console.debug("Adding listener to existing tabs")
document.querySelectorAll(ALL_TABS_SELECTOR)
.forEach(tab => {
observer.observe(tab, OBSERVER_CONFIG);
});
});
function handleTitleElement(titleElement) {
const titleText = titleElement.textContent.trim();
if (titleText.startsWith(ADDRESS_PAGE_TITLE_CRITERIA)) {
console.log("Running address validation")
try {
runAddressValidation(titleElement);
} catch (error) {
const usageData = getUsageData(titleElement);
saveErrorData(usageData, error);
}
}
else if (titleText.startsWith(LIVING_ARRANGEMENTS_PAGE_TITLE_CRITERIA)) {
console.log('Running living arrangements validation');
try {
runLivingArrangementValidation(titleElement);
} catch (error) {
const usageData = getUsageData(titleElement);
saveErrorData(usageData, error);
}
}
else if (titleText.startsWith(HOUSEHOLD_MEAL_GROUP_PAGE_TITLE_CRITERIA)) {
console.log('Running household meal group validation');
try {
runMealGroupMemberValidation(titleElement);
} catch (error) {
const usageData = getUsageData(titleElement);
saveErrorData(usageData, error);
}
}
else {
console.log('Closing popup for non extension page');
updatePopupData(NOT_SUPPORTED_ACTION)
var isPopupOpen =
document.querySelector(POPUP_SELECTOR).style.display === 'block';
if (isPopupOpen) toggleExtensionPopup();
}
}