Last active
December 28, 2023 22:04
-
-
Save overestimate/9e3cbf86c69045419a19a739c7bd7f81 to your computer and use it in GitHub Desktop.
userscript template to use with bun for development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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