Skip to content

Instantly share code, notes, and snippets.

@lelinhtinh
Last active June 7, 2016 07:49
Show Gist options
  • Save lelinhtinh/40a66547a9b03348dbf10c0f13bdc358 to your computer and use it in GitHub Desktop.
Save lelinhtinh/40a66547a9b03348dbf10c0f13bdc358 to your computer and use it in GitHub Desktop.
Web worker trong Userscript
// ==UserScript==
// @name Web Worker in Userscript
// @namespace http://baivong.github.io
// @version 1.0.2
// @description Use Web Worker in Userscript
// @author Zzbaivong
// @match https://github.com/baivong
// @resource worker https://gist.githubusercontent.com/baivong/4830c63ad2351d76d019e7e451121eb2/raw/77eda54e0a0c1136d6ac93ad8ccafb275b410866/worker.js
// @grant GM_getResourceText
// ==/UserScript==
(function() {
'use strict';
function resourceToBlobUrl(resourceName) {
var blob = new Blob([GM_getResourceText(resourceName)], {
type: 'text/javascript'
});
return window.URL.createObjectURL(blob);
}
var workerURL = resourceToBlobUrl('worker');
var worker = new Worker(workerURL);
worker.addEventListener('message', function(e) {
alert(e.data);
}, false);
worker.postMessage('Hello');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment