MCPcopy Create free account
hub / github.com/Tampermonkey/tampermonkey / syncTime

Function syncTime

src/syncinfo.js:90–141  ·  view source on GitHub ↗
(callback)

Source from the content-addressed store, hash-verified

88 };
89
90 var syncTime = function(callback) {
91 var srv = 0;
92 var next = function() {
93 srv++;
94 window.setTimeout(run, 1);
95 };
96
97 var error = function() {
98 _timeoffset = 0;
99 console.log('si: time offset detection failed!');
100 if (callback) callback(false);
101 };
102
103 var succ = function(t) {
104 _timeoffset = t;
105 console.log('si: detected a time offset of ' + t + ' ms');
106 if (callback) callback(true);
107 };
108
109 var run = function() {
110 if (srv < _timeservers.length) {
111 var o = _timeservers[srv];
112
113 var details = {
114 method: o.method,
115 url: o.url,
116 };
117
118 var got = function(req) {
119 if (req.readyState == 4) {
120 if (req.status == 200) {
121 var t = o.extract(req.responseText, req.responseHeaders);
122 if (t === null) {
123 next();
124 } else {
125 succ(t);
126 }
127 } else {
128 next();
129 }
130 }
131 };
132
133 if (V) console.log('si: determine time offset with server ' + o.url);
134 xmlhttpRequest(details, got);
135 } else {
136 error();
137 };
138 };
139
140 run();
141 };
142
143 var registerOnChange = function() {
144 if (_registered) return;

Callers 2

handleChangeFunction · 0.85
listFunction · 0.85

Calls 1

runFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…