PageSourceSearch

https://gospelradio.me/js/listening-time.js?v=1.0.3

js gospelradio.me collected 2026-10-02 19:50:21 UTC 4,088 bytes, 141 lines download raw bytes

1(function () {
2    "use strict";
3
4    var elapsedMs = 0;
5    var startedAt = null;
6    var stationKey = "";
7    var updateTimer = null;
8
9    var now = function () {
10        return new Date().getTime();
11    };
12
13    var pad = function (number) {
14        return number < 10 ? "0" + number : String(number);
15    };
16
17    var formatTime = function (milliseconds) {
18        var seconds = Math.max(0, Math.floor(milliseconds / 1000));
19        var hours = Math.floor(seconds / 3600);
20        var minutes = Math.floor((seconds % 3600) / 60);
21        var remainingSeconds = seconds % 60;
22        var shortTime = pad(minutes) + ":" + pad(remainingSeconds);
23
24        return hours > 0 ? pad(hours) + ":" + shortTime : shortTime;
25    };
26
27    var getElapsedMs = function () {
28        return elapsedMs + (startedAt === null ? 0 : now() - startedAt);
29    };
30
31    var getStationKey = function () {
32        var title = document.getElementById("radio_title");
33        var category = document.getElementById("radio_category");
34        var cover = document.querySelector("#player .radio-cover");
35
36        return [
37            title ? title.textContent : "",
38            category ? category.textContent : "",
39            cover ? cover.getAttribute("src") : ""
40        ].join("|");
41    };
42
43    var getTimeOutput = function () {
44        var container = document.querySelector("#player .mejs__time");
45        if (!container) {
46            return null;
47        }
48
49        var nativeTime = container.querySelector(".mejs__currenttime");
50        if (nativeTime) {
51            nativeTime.style.display = "none";
52            nativeTime.setAttribute("aria-hidden", "true");
53        }
54
55        var output = container.querySelector(".radio-listening-time");
56        if (!output) {
57            output = document.createElement("span");
58            output.className = "radio-listening-time";
59            output.setAttribute("aria-live", "off");
60            output.style.display = "inline-block";
61            output.style.minWidth = "4.5rem";
62            output.style.textAlign = "center";
63            output.style.whiteSpace = "nowrap";
64            output.style.fontVariantNumeric = "tabular-nums";
65            container.appendChild(output);
66        }
67
68        return output;
69    };
70
71    var updateView = function () {
72        var time = getTimeOutput();
73        if (time) {
74            time.textContent = formatTime(getElapsedMs());
75        }
76    };
77
78    var pauseClock = function () {
79        if (startedAt !== null) {
80            elapsedMs += now() - startedAt;
81            startedAt = null;
82        }
83        updateView();
84    };
85
86    var startClock = function () {
87        var nextStationKey = getStationKey();
88        if (nextStationKey !== stationKey) {
89            stationKey = nextStationKey;
90            elapsedMs = 0;
91            startedAt = null;
92        }
93
94        if (startedAt === null) {
95            startedAt = now();
96        }
97        updateView();
98    };
99
100    var getActiveAudio = function () {
101        var audioElements = document.querySelectorAll(
102            "audio#audio_player, #audio_player audio, #audio_player_html5, #player audio"
103        );
104        var fallbackAudio = audioElements.length ? audioElements[0] : null;
105
106        for (var index = 0; index < audioElements.length; index++) {
107            if (!audioElements[index].paused && !audioElements[index].ended) {
108                return audioElements[index];
109            }
110        }
111
112        return fallbackAudio;
113    };
114
115    var syncClock = function () {
116        var audio = getActiveAudio();
117        if (!audio) {
118            updateView();
119            return;
120        }
121
122        if (audio.paused || audio.ended) {
123            pauseClock();
124        } else {
125            startClock();
126        }
127    };
128
129    var bindAudio = function () {
130        syncClock();
131        if (updateTimer === null) {
132            updateTimer = window.setInterval(syncClock, 250);
133        }
134    };
135
136    if (document.readyState === "complete") {
137        window.setTimeout(bindAudio, 0);
138    } else {
139        window.addEventListener("load", bindAudio, false);
140    }
141})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.