Skip to content

Commit

Permalink
Add inline worker.
Browse files Browse the repository at this point in the history
  • Loading branch information
wibimaster committed Jul 24, 2015
1 parent 48e64bc commit db6743a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
44 changes: 43 additions & 1 deletion HackTimer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
var blob = new Blob(["\
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;\
}\
}\
"]);
// Obtain a blob URL reference to our worker 'file'.
var blobURL = window.URL.createObjectURL(blob);

(function (workerScript) {
var worker,
fakeIdToCallback = {},
Expand Down Expand Up @@ -87,4 +129,4 @@
} else {
console.log (logPrefix + 'Initialisation failed - HTML5 Web Worker is not supported');
}
})('HackTimerWorker.js');
})(blobURL);
2 changes: 1 addition & 1 deletion HackTimer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db6743a

Please sign in to comment.