-
Notifications
You must be signed in to change notification settings - Fork 1
/
mlbtv_time_zones.user.js
47 lines (36 loc) · 1.42 KB
/
mlbtv_time_zones.user.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
// ==UserScript==
// @name MLB.tv Time Zones
// @namespace https://github.com/int3h
// @description Modifies the times listed on the MLB.tv media center to have times in Pacific Time, instead of Eastern Time
// @include http://mlb.mlb.com/mediacenter/*
// ==/UserScript==
var time_differential = -3;
var time_header = 'Time PT';
var mgTimes = document.evaluate("//*[@class='mmg_time']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = mgTimes.snapshotLength - 1; i >= 0; i--) {
var elem = mgTimes.snapshotItem(i);
// Check to make sure if this is a time cell
if(elem.innerHTML.indexOf(':') == -1) {
// If not, is this the header?
if(elem.innerHTML.indexOf('ET') != -1) {
elem.innerHTML = time_header;
}
continue;
}
// Break up the time cell into its component parts
var time_parts = new Array();
time_parts = elem.innerHTML.split(':');
hour = time_parts[0] * 1;
m_ampm = time_parts[1].split(' ');
minutes = m_ampm[0];
ampm = m_ampm[1];
hour += time_differential;
// If we've wrapped around in time (from, e.g., 1pm to 11 am) rebase the time
if(hour < 1)
hour += 12;
// If we *did* wrap around time, change the ampm (but not if the new time is
// twelve, but definitely if the old time was twelve)
if(hour < 12 && hour >= 12 + time_differential)
ampm = ampm == 'AM' ? 'PM' : 'AM';
elem.innerHTML = hour.toString() + ':' + minutes + ' ' + ampm;
}