Bonjour,

J'ai une checkbox en bas de ma popup.html ( elle permet de modifier les temps UTC du tableau en temps locale )

Tout ça fonctionne correctement, pas de soucis.

En revanche, elle se met systématiquement en "surbrillance" et fait défiler le contenu de la popup jusqu'a ce quelle devienne visible ( comme pour montrer qu'elle est là ) ...

Y'a t'il un moyen d'empêcher ça ?

Quand elle n'était pas implémentée la popup ne "réagissait" pas comme ça ...

C'est difficile à décrire du coup j'ai fais une vidéo, j'espère que ça sera plus parlant.



popup.html
Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
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
<!doctype html>
<html>
<body style="height:auto;width:719px;">
<table border="1" align="center">
    <thead>
    <tr>
        <th>Date</th>
        <th>Time</th>
        <th title="Timezone">TZ</th>
        <th title="Time To Waypoint">TTW</th>
        <th title="Distance To Waypoint">DTW</th>
        <th title="Distance To Go">DTG</th>
        <th title="True Wind Direction">TWD</th>
        <th title="True Wind Speed">TWS</th>
        <th title="True Wind Angle">TWA</th>
        <th title="Bearing To Waypoint - Heading">BTW</th>
        <th>Sail</th>
        <th title="Speed Through Water - Boat speed">STW</th>
        <th title="Average True Wind Angle">TWAm</th>
        <th title="Average Bearing To Waypoint">BTWm</th>
    </tr>
    </thead>
    <tbody id="pointsTable" align="center">
    </tbody>
</table>
<br>
<div style="float:left;">
    <input type="checkbox" id="localtime">
    <label>Local Time</label>
</div>
<div style="float:right" ;>
    <label>Version</label>
    <label id="version"></label>
</div>
<!-- <div style="margin:0 auto;text-align: center;">
    <input type="button" value=".GPX" onclick="file_gpx()">
</div> -->
</body>
<script src="popup.js"></script>
</html>

popup.js
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
var background = chrome.extension.getBackgroundPage();
 
var hour_actu = 0;
var hour_change = 0;
var hour_prec = 0;
var nb_step = 0;
 
var twam = 0;
var twa_prec = 0;
var tot_twa_prec = 0;
var tot_twa = 0;
 
var btwm = 0;
var btw_prec = 0;
var tot_btw_prec = 0;
var tot_btw = 0;
 
var twa_btw_change = 0;
 
function createCell(value, row) {
    var cell = document.createElement("td");
    cell.innerHTML = value;
    row.appendChild(cell);
}
 
function ttwStyling(value, cell) {
    cell.align = "left";
    cell.innerHTML = value;
}
 
function dtwStyling(value, cell) {
    cell.align = "left";
    cell.innerHTML = value;
}
 
function dtgStyling(value, cell) {
    cell.align = "left";
    cell.innerHTML = value;
}
 
function twsStyling(value1, value2, cell) {
    var tws_foil = value1.replace(' kt', '');
    var twa_bd = value2.replace('\u00B0', '');
    if (tws_foil >= 11.1 && tws_foil <= 39.9 && Math.abs(twa_bd) >= 71 && Math.abs(twa_bd) <= 169) {
        cell.style.backgroundColor = "black";
        cell.style.color = "white";
    } else {
        cell.style.backgroundColor = "white";
        cell.style.color = "black";
    }
    cell.innerHTML = tws_foil + ' kt';
}
 
function twaStyling(value, cell) {
    var twa_bd = value.replace('\u00B0', '');
    if (twa_bd >= 0) {
        cell.style.color = "green";
    } else {
        cell.style.color = "red";
    }
    cell.innerHTML = Math.abs(twa_bd) + '\u00B0';
}
 
function btwStyling(value, cell) {
    cell.style.color = "blue";
    cell.innerHTML = value;
}
 
function sailStyling(value, cell) {
    switch (value.trim()) {
        // Upwind sail
        case 'Jib':
            cell.style.backgroundColor = "#FFD479";
            break;
        case 'LJ':
            cell.style.backgroundColor = "#FFFC79";
            break;
        case 'Stay':
            cell.style.backgroundColor = "#D4FB79";
            break;
        // Downwind sail
        case 'Spi':
            cell.style.backgroundColor = "#76D6FF";
            break;
        case 'LG':
            cell.style.backgroundColor = "#7A81FF";
            break;
        case 'HG':
            cell.style.backgroundColor = "#D783FF";
            break;
        // Reaching sail
        case 'C0':
            cell.style.backgroundColor = "#FF7E79";
            break;
    }
    cell.innerHTML = value;
}
 
function twamStyling(value, cell) {
    if (value >= 0) {
        cell.style.color = "green";
    } else {
        cell.style.color = "red";
    }
    if (value != '-') {
        cell.innerHTML = Math.abs(value) + '\u00B0';
    } else {
        cell.style.color = "black";
        cell.innerHTML = value;
    }
}
 
function btwmStyling(value, cell) {
    cell.style.color = "blue";
    if (value != '-') {
        cell.innerHTML = value + '\u00B0';
    } else {
        cell.style.color = "black";
        cell.innerHTML = value;
    }
}
 
function createCellWithCustomStyling(value, row, customStyling) {
    var cell = document.createElement("td");
    customStyling(value, cell);
    row.appendChild(cell);
}
 
function createCellWithCustomStyling2(value1, value2, row, customStyling) {
    var cell = document.createElement("td");
    customStyling(value1, value2, cell);
    row.appendChild(cell);
}
 
function calc_nb_ite(value) {
    var delta_t = value.match(/.*?([0-9]{1,}):([0-9]{2})/);
    hour_prec = hour_actu;
    hour_actu = delta_t[1] * 6 + delta_t[2] / 10;
    nb_step = hour_actu - hour_prec;
}
 
function calc_twam(value) {
    ss_tot = parseFloat(value.replace('\u00B0', ''));
    tot_twa = tot_twa_prec + (twa_prec * nb_step);
    if (hour_actu == hour_change) {
        twam = '-';
    } else {
        twam = tot_twa / (hour_actu - hour_change);
        twam = Math.round(twam);
    }
    tot_twa_prec = tot_twa;
    twa_btw_change = 0;
    if ((twa_prec * ss_tot) <= 0) {
        tot_twa_prec = 0;
        twa_btw_change = 1;
    }
    twa_prec = ss_tot;
}
 
function calc_btwm(value) {
    ss_tot = parseFloat(value.replace('\u00B0', ''));
    // N1
    if (btwm >= 270 && btw_prec <= 90) {
        btw_prec = btw_prec + 360;
    } else {
        if (btwm <= 90 && btw_prec >= 270) {
            btw_prec = btw_prec - 360;
        }
    }
    // End N1
    tot_btw = tot_btw_prec + (btw_prec * nb_step);
    if (hour_actu == hour_change) {
        btwm = '-';
    } else {
        btwm = tot_btw / (hour_actu - hour_change);
        // N2
        if (btwm >= 360) {
            btwm = btwm - 360;
        } else {
            if (btwm < 0) {
                btwm = btwm + 360;
            }
        }
        // End N2
        btwm = Math.round(btwm);
    }
    tot_btw_prec = tot_btw;
    if (twa_btw_change == 1) {
        tot_btw_prec = 0;
        nb_step = 0;
        hour_prec = hour_actu;
        hour_change = hour_actu;
    }
    btw_prec = ss_tot;
}
 
function reinitializeDisplay() {
    document.getElementById("pointsTable").innerHTML = "";
}
 
function convertUtcToLocal(date, time) {
    // 2018-02-07
    var utcYear = date.split("-")[0];
    var utcMonth = date.split("-")[1];
    var utcDay = date.split("-")[2];
 
    var utcHour = time.split(":")[0];
    var utcMinutes = time.split(":")[1];
 
    var dateUtc = Date.UTC(utcYear, utcMonth, utcDay, utcHour, utcMinutes, 0, 0);
    var localDate = new Date(dateUtc);
 
    var year = localDate.getFullYear();
    var month = ("0"+localDate.getMonth()).slice(-2);
    var day = ("0"+localDate.getDate()).slice(-2);
 
    var hours = ("0" + localDate.getHours()).slice(-2);
    var minutes = ("0" + localDate.getMinutes()).slice(-2);
 
 
    var formattedDate = year + "-" + month + "-" + day;
    var formattedTime = hours + ":" + minutes;
    return [formattedDate,formattedTime];
}
 
function getTimeZone() {
    var o = -new Date().getTimezoneOffset(), t = Math.abs(o);
    var s = (o < 0) ? "-" : "+";
    var h = Math.trunc(t) / 60;
    var mh = (h == 0) ? "" : s + h;
    var m = t % 60;
    var hm = (m == 0) ? mh : s + h + ":" + m;
    return "UTC" + hm
}
 
function displayTable(localTime) {
    points.forEach(function (element) {
        var row = document.createElement("tr");
        document.getElementById("pointsTable").appendChild(row);
        if (localTime) {
            var localDateAndTime = convertUtcToLocal(element.date,element.time);
            createCell(localDateAndTime[0], row);
            createCell(localDateAndTime[1], row);
        } else {
            createCell(element.date, row);
            createCell(element.time, row);
        }
        if (localTime) {
            createCell(getTimeZone(), row);
        } else {
            createCell(element.timezone, row);
        }
        createCellWithCustomStyling(element.ttw, row, ttwStyling);
        calc_nb_ite(element.ttw);
        createCellWithCustomStyling(element.dtw, row, dtwStyling);
        createCellWithCustomStyling(element.dtg, row, dtgStyling);
        createCell(element.twd, row);
        createCellWithCustomStyling2(element.tws, element.twa, row, twsStyling);
        createCellWithCustomStyling(element.twa, row, twaStyling);
        calc_twam(element.twa);
        createCellWithCustomStyling(element.btw, row, btwStyling);
        calc_btwm(element.btw);
        createCellWithCustomStyling(element.sail, row, sailStyling);
        createCell(element.stw, row);
        createCellWithCustomStyling(twam, row, twamStyling);
        createCellWithCustomStyling(btwm, row, btwmStyling);
        var manifest = chrome.runtime.getManifest();
        document.getElementById("version").innerHTML = manifest.version;
        console.log(element);
    });
}
 
var displayLocal = function () {
    reinitializeDisplay();
    if (document.getElementById("localtime").checked) {
        chrome.storage.local.set({'localTime':true});
        displayTable(true);
    } else {
        chrome.storage.local.set({'localTime':false});
        displayTable(false);
    }
};
 
document.getElementById("localtime").addEventListener('change', displayLocal);
 
chrome.storage.local.get('localTime',function (result) {
    if(result.localTime===true){
        document.getElementById("localtime").checked=true;
        displayLocal();
    } else {
        document.getElementById("localtime").checked=false;
    }
});
reinitializeDisplay();
var points = background.points[background.currentTab];
displayTable(false);
Merci