Skip to content

Instantly share code, notes, and snippets.

@0xkarambit
Last active April 22, 2022 17:05
Show Gist options
  • Save 0xkarambit/808865f6da08c9643bce94ec85721ec2 to your computer and use it in GitHub Desktop.
Save 0xkarambit/808865f6da08c9643bce94ec85721ec2 to your computer and use it in GitHub Desktop.
script to open multiple urls from a text file
// Harshit Joshi, 22-04-2022
// MIT license
// unsafe dont use .... any arg can be placed in the urls file and it wont be filtered
import cp from "child_process";
import fs from "fs";
let COMMAND = `start firefox `;
function readUrls(file) {
let contents = fs.readFileSync(file).toString();
// removing empty lines and adding "" to avoid having to escape special characters
return contents
.split("\r\n")
.filter((str) => str.length)
.map((str) => `"${str}"`);
}
async function main() {
let file = process.argv[2];
if (process.argv.length < 3) {
console.log(`Usage: opener [file]`);
process.exit(1);
}
const canAccess = fs.lstatSync(file).isFile();
if (!canAccess) {
console.error(`Unable to read file "${file}"`);
process.exit(1);
}
let urls = readUrls(process.argv[2]);
COMMAND += urls.join(" ");
console.log(COMMAND);
cp.execSync(COMMAND);
process.exit(0);
}
await main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment