forked from Glodenox/wme-closure-details
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwme-closure-details.user.js
More file actions
166 lines (156 loc) · 7.8 KB
/
Copy pathwme-closure-details.user.js
File metadata and controls
166 lines (156 loc) · 7.8 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
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
// ==UserScript==
// @name WME Closure Details
// @namespace http://www.tomputtemans.com/
// @description Provide access to all closure details within the closures list
// @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4AMUFRY0ZYorwwAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAGAklEQVRYw+2XbWidZxnHf9fzct6SnPOcpElNs6ZdSyy4VU3dqrQDabUlhYV17YdNqlbmNgSXjkbckKlDQVeqbgMjzuEYRVTEdQw7WZxD3ZdGmzcXOmRrwTYlMS89yck5T3KSnOe5Lz+cnDQvdSTC0A+7vt73dV3/6/+/7uu+b/jA/scmnZ2dtLS0oKqx3r7emDHmfU2oquy+c3cgIj6AAPR09zz3yIlHjuRyOff9rlhVicfjHDt27LftJ9tPSMdPOu45derUKyJCY0RKtOg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+bEJrUol9cjRI7reS2fvXXtP1Wyo0b//rVubPtykra2tCjAzM+OoqgVw5swZrIMHDi5oJxqPxYsAY2NjgYgQiURIJqvIZDLrvvV23r7zUBiG1G2owxLBn/YBSCQSgYgYgOPHj98YREtt661b7xARXMchnfL+KwAVlRUfDY3B8zyqqpLk8/mb7rspgEQikZKFM5xMpchms6jqjvUAyGQypbs/maSmuhrf99cOIJ/PgwjGtkgmU2hppMbWA+D69es4jgMOeNXVTE1Noarb1gTA931s2yYQqEymEBH6+vtYL4C0l8IAqeoaisUivu9/ds0MeOlq/AAqkkkA+vv71w0glUrjB1DpVSMiDAwMvLcE4+PjiwDSNTXkgpBoZRIRoae7Zz3vvjsKhQJVqRT5ABJeGgEuXrz43gBqa2tR1QdyuSmq0jX4gRKtKklwofuCrqMBiyJCRTJFLlBiXjUi8NbAW6v2rppsly9fdmzL5tI/3ubbbQ8ydPUKxhjuPXzvrr7evoG1ADjfdR6AocGrfOurDzA+OoLrRm4q4yoAnudNRWOxuczYaCEzNloeUjQ0NKxZgs23bJ6LRCL+1ORE0P3mnxYe0Hasqalpvut813927O3tBeChhx9KN25p9Bq3NHqbGzd7uz+52yuPz7Va+9fa0w23NHjlOM27mtOqGvngL/h/Z/8GrAeaT+aWBXcAAAAASUVORK5CYII=
// @version 1.2
// @grant none
// ==/UserScript==
/* global W, $, I18n */
var styleElement; // Style element to reuse whenever it gets removed by the WME (user login, for example)
function init(e) {
if (e && e.user === null) {
return;
}
if (document.getElementById('user-info') === null) {
setTimeout(init, 500);
return;
}
if (typeof W.loginManager === 'undefined' || W.app.modeController === 'undefined' || W.selectionManager === 'undefined') {
setTimeout(init, 300);
return;
}
if (!W.loginManager.user) {
W.loginManager.events.register('login', null, init);
W.loginManager.events.register('loginStatus', null, init);
// Double check as event might have triggered already
if (!W.loginManager.user) {
return;
}
}
// Deal with events mode
if (W.app.modeController) {
W.app.modeController.model.bind('change:mode', function(model, modeId) {
if (modeId === 0) {
observeContentsPane();
applyStyles();
}
});
}
observeContentsPane();
applyStyles();
}
init();
function observeContentsPane() {
function handleMutations(mutations) {
mutations.forEach(function(mutation) {
var closureBlocks = mutation.target.querySelectorAll('.closure-item');
var selectedIDs = W.selectionManager.getSelectedFeatures().filter(function(obj) {
return obj.model.type == 'segment';
}).map(function(obj) {
return obj.model.attributes.id;
});
var selectedClosures = W.model.roadClosures.getObjectArray().filter(function(closure) {
return selectedIDs.indexOf(closure.segID) != -1;
});
for (var i = 0; i < closureBlocks.length; i++) {
var closureBlock = closureBlocks[i];
closureBlock.addEventListener('click', removeAllTooltips);
closureBlock.querySelector(".menu-initiator").addEventListener('click', removeAllTooltips);
var buttons = closureBlock.querySelectorAll('a');
for (var j = 0; j < buttons.length; j++) {
buttons[j].addEventListener('click', removeAllTooltips);
}
var matchedClosure = selectedClosures.find(function(closure) {
return getLocalizedTime(closure.startDate) == getTimeFromBlock(closureBlock.querySelector('.start-date')) &&
getLocalizedTime(closure.endDate) == getTimeFromBlock(closureBlock.querySelector('.end-date'));
});
if (matchedClosure) {
var description;
if (matchedClosure.reason !== '') {
description = '<strong class="description">' + matchedClosure.reason + '</strong>';
} else {
description = '<em class="description">No description set</em>';
}
description += '<table class="details"><tbody>';
if (matchedClosure.provider) {
description += '<tr><th>Provided by</th><td>' + matchedClosure.provider + '</td></tr>';
}
description += '<tr><th>Created by</th><td>' + getUsername(matchedClosure.createdBy) + '</td></tr><tr><th>Created on</th><td>' + I18n.l('time.formats.long', matchedClosure.createdOn) + '</td></tr>';
if (matchedClosure.updatedBy) {
description += '<tr><th>Updated by</th><td>' + getUsername(matchedClosure.updatedBy) + '</td></tr>';
}
if (matchedClosure.updatedOn) {
description += '<tr><th>Updated on</th><td>' + I18n.l('time.formats.long', matchedClosure.updatedOn) + '</td></tr>';
}
description += '<tr><td colspan="2" style="text-align:center"><em>' + (matchedClosure.permanent ? 'Ignores traffic' : 'Listens to traffic') + '</em></td></tr></tbody></table></div>';
$(closureBlock).tooltip({
placement: 'right',
container: 'body',
trigger: 'hover',
html: true,
title: description
}).on('hidden.bs.tooltip', removeAllTooltips);
}
}
});
if (document.querySelector('.contents .closures')) {
(new MutationObserver(handleMutations)).observe(document.querySelector('.contents .closures'), {
childList: true
});
}
}
(new MutationObserver(handleMutations)).observe(document.querySelector('.contents'), {
childList: true
});
}
function removeAllTooltips() {
var tooltips = document.querySelectorAll('.tooltip');
if (tooltips.length > 0) {
for (var tooltip of tooltips) {
tooltip.parentNode.removeChild(tooltip);
}
}
}
function getTimeFromBlock(node) {
return node.querySelector('.date').textContent + ' ' + node.querySelector('.time').textContent;
}
function getLocalizedTime(date) {
var splitDate = date.split(' ');
return I18n.l('date.formats.default', splitDate[0]) + ' ' + splitDate[1];
}
function getUsername(id) {
var user = W.model.users.getObjectById(id);
if (user) {
return user.userName;
} else {
return id + ' (user not loaded)';
}
}
function applyStyles() {
if (!styleElement) {
styleElement = document.createElement('style');
styleElement.textContent = `
.tooltip .tooltip-inner {
max-width: 400px;
}
.tooltip-inner .description {
font-size: 120%;
}
.tooltip-inner .details {
border-width: 0;
text-align: left;
width: 100%;
}
.tooltip-inner .details th {
text-align: right;
padding-right: 0.4em;
color: #fff;
}
`;
}
if (!styleElement.parentNode) {
document.head.appendChild(styleElement);
}
}