Skip to content

Instantly share code, notes, and snippets.

@overestimate
Last active December 28, 2023 22:04
Show Gist options
  • Save overestimate/9e3cbf86c69045419a19a739c7bd7f81 to your computer and use it in GitHub Desktop.
Save overestimate/9e3cbf86c69045419a19a739c7bd7f81 to your computer and use it in GitHub Desktop.
userscript template to use with bun for development
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version <$DATE$>
// @description try to take over the world!
// @author You
// @match <$URL$>
// @icon <$ICON$>
// @grant none
// ==/UserScript==
if (typeof Bun != "undefined") {
import('node:process');
const server = Bun.serve({
port: 9457,
async fetch(req) {
if (req.url.indexOf("stopServer") != -1) { setTimeout(() => { process.exit(0) }, 100); return new Response("done") }
return new Response(await Bun.file("./wikitool.user.js").text(), { "headers": { "content-type": "application/javascript" } })
},
});
console.log(`Listening on http://localhost:${server.port} ...`);
} else {
(function () {
'use strict';
// Your code here...
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment