mirror of
https://github.com/turuslan/HackTimer
synced 2024-11-21 15:10:11 +00:00
38 lines
856 B
JavaScript
38 lines
856 B
JavaScript
var fakeIdToId = {};
|
|
onmessage = function (event) {
|
|
var data = event.data,
|
|
name = data.name,
|
|
fakeId = data.fakeId,
|
|
time;
|
|
if(data.hasOwnProperty('time')) {
|
|
time = data.time;
|
|
}
|
|
switch (name) {
|
|
case 'setInterval':
|
|
fakeIdToId[fakeId] = setInterval(function () {
|
|
postMessage({fakeId: fakeId});
|
|
}, time);
|
|
break;
|
|
case 'clearInterval':
|
|
if (fakeIdToId.hasOwnProperty (fakeId)) {
|
|
clearInterval(fakeIdToId[fakeId]);
|
|
delete fakeIdToId[fakeId];
|
|
}
|
|
break;
|
|
case 'setTimeout':
|
|
fakeIdToId[fakeId] = setTimeout(function () {
|
|
postMessage({fakeId: fakeId});
|
|
if (fakeIdToId.hasOwnProperty (fakeId)) {
|
|
delete fakeIdToId[fakeId];
|
|
}
|
|
}, time);
|
|
break;
|
|
case 'clearTimeout':
|
|
if (fakeIdToId.hasOwnProperty (fakeId)) {
|
|
clearTimeout(fakeIdToId[fakeId]);
|
|
delete fakeIdToId[fakeId];
|
|
}
|
|
break;
|
|
}
|
|
}
|