Skip to content

Instantly share code, notes, and snippets.

@lelinhtinh
Last active June 21, 2025 04:15
Show Gist options
  • Save lelinhtinh/8f1dbac30a8b806f55470a96b4504285 to your computer and use it in GitHub Desktop.
Save lelinhtinh/8f1dbac30a8b806f55470a96b4504285 to your computer and use it in GitHub Desktop.
Web worker trong Userscript với thư viện đính kèm
// ==UserScript==
// @name Web Worker in Userscript
// @namespace http://baivong.github.io
// @version 2.0.1
// @description Use Web Worker in Userscript with libraries
// @author Zzbaivong
// @match https://github.com/baivong
// @require https://greasyfork.org/scripts/18532-filesaver/code/FileSaver.js?version=128198
// @resource jszip https://greasyfork.org/scripts/19855-jszip/code/jszip.js?version=126859
// @resource worker https://gist.githubusercontent.com/baivong/e8a13c341a4814e726653d1f9fce02c2/raw/75e747879d1fab98708b08112d228e4acd3dec35/worker-withLibs.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 jszipURL = resourceToBlobUrl('jszip');
var workerURL = resourceToBlobUrl('worker');
var worker = new Worker(workerURL);
worker.addEventListener('message', function(e) {
saveAs(e.data, 'test.zip');
}, false);
worker.postMessage({
libs: jszipURL,
content: 'Hello World!'
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment