-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixpanel.js
182 lines (137 loc) · 4.98 KB
/
mixpanel.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Global Settings and State
var shouldHideSearchBar = true;
var shouldHideDescriptionBar = false;
var shouldDisplayConcreteNumbers = true;
// Log state, so we can continue to update.
var updatesComplete = {};
var observers = {};
// Fetch options
chrome.storage.sync.get(
{
hideSearchBar: true,
hideDescriptionBar: false,
displayConcreteNumbers: true
},
(items) => {
shouldHideSearchBar = items.hideSearchBar;
shouldHideDescriptionBar = items.hideDescriptionBar;
shouldDisplayConcreteNumbers = items.displayConcreteNumbers;
});
function updateMetricFromTooltip(metricSelector) {
const valueTooltip = metricSelector.getAttribute('value-tooltip');
const value = metricSelector.shadowRoot.querySelector('div.value');
value.innerHTML = valueTooltip;
value.style.fontSize = '4vw';
}
function updateMetric(multiMetricSelectorChart) {
//console.log(multiMetricSelectorChart);
if (multiMetricSelectorChart.shadowRoot != null) {
const multiMetricSelector = multiMetricSelectorChart.shadowRoot.querySelector('mp-multi-metric');
if (multiMetricSelector) {
const metricSelector = multiMetricSelector.shadowRoot.querySelector('mp-metric');
if (metricSelector) {
const value = metricSelector.shadowRoot.querySelector('div.value');
updateMetricFromTooltip(metricSelector);
return true;
}
}
}
return false;
}
function updateMetrics() {
const allMetricCharts = document.querySelectorAll('mp-insights-metric-chart');
if (allMetricCharts.length === 0) {
return false;
}
// Fetch all metrics and try to update
for (let i = 0; i < allMetricCharts.length; i++) {
const currentMetricChart = allMetricCharts[i];
if (!updateMetric(currentMetricChart)) {
return false;
}
}
return true;
}
function hideCompleteDescriptionBar() {
const topIntroHeader = document.querySelector('div.header');
if (topIntroHeader) {
topIntroHeader.style.display = 'none';
return true;
}
return false;
}
function hideDescriptionBar() {
const topIntroHeader = document.querySelector('div.header');
if (!topIntroHeader) {
return false;
}
const mpLastUpdatedSelector = topIntroHeader.querySelector('mp-last-updated');
if (!mpLastUpdatedSelector) {
return false;
}
mpLastUpdatedSelector.parentElement.style.marginTop = '0px';
mpLastUpdatedSelector.parentElement.style.marginBottom = '0px';
// Board description container
const boardDescriptionContainer = mpLastUpdatedSelector.parentElement.parentElement.parentElement;
// Remove first child
boardDescriptionContainer.firstChild.style.display = 'none';
const boardDescriptionContainerWrapper = boardDescriptionContainer.parentElement;
boardDescriptionContainerWrapper.firstChild.style.display = 'none';
// Container of two columns that contains entire board description.
const boardCompleteDescription = boardDescriptionContainerWrapper.parentElement;
boardCompleteDescription.lastChild.style.display = 'none';
return true;
}
function hideSearchBar() {
const topHeader = document.querySelector('#wrapper').firstChild.nextSibling;
if (topHeader) {
topHeader.style.display = 'none';
return true;
}
return false;
}
function update() {
//console.log(window.location.toString());
// Only active when tv=true
if (window.location.toString().indexOf('tv=true') === -1) {
return;
}
if (shouldHideSearchBar && !updatesComplete.hideSearchBar) {
if (hideSearchBar()) {
updatesComplete.hideSearchBar = true;
}
}
if (shouldHideDescriptionBar && !updatesComplete.hideDescriptionBar) {
if (hideDescriptionBar()) {
updatesComplete.hideDescriptionBar = true;
}
}
if (shouldDisplayConcreteNumbers && !updatesComplete.displayConcreteNumbers) {
if (updateMetrics()) {
updatesComplete.displayConcreteNumbers = true;
// Set an observer to repeatedly update the metrics.
const changingSelector = document.querySelector('.cards-container');
const hash = changingSelector.hash;
// Add observer
if (!observers[hash]) {
let observer = new MutationObserver(function(mutations) {
updatesComplete.displayConcreteNumbers = false;
update();
});
observer.observe(changingSelector, {
childList: true,
subtree: true
});
observers[hash] = observer;
}
}
}
if (updatesComplete.hideSearchBar && updatesComplete.hideDescriptionBar && updatesComplete.displayConcreteNumbers) {
return;
}
else {
// Rerun function if one of the updates failed.
setTimeout(update, 500);
}
}
setTimeout(update, 500);