Created
April 9, 2018 11:35
-
-
Save rusco/eebe2730d6afebe3e388a2cb814eded9 to your computer and use it in GitHub Desktop.
downloads woff files embedded in links like https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons
This file contains hidden or 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
// 09.04.2018 | |
// node --experimental-modules cssdownload.mjs | |
// downloads woff files embedded in links like https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons | |
import http from "http"; | |
import readline from "readline"; | |
import fs from "fs"; | |
const rl = readline.createInterface({ input: fs.createReadStream("css.css"), crlfDelay: Infinity }); | |
let idx = 0; | |
rl.on("line", (line) => { | |
if (line.indexOf("url(") > -1) { | |
const linkStart = line.indexOf("url(") + 4; | |
const linkStop = line.indexOf(")", linkStart); | |
const link = line.substring(linkStart, linkStop).replace("https", "http"); | |
const fileNameStart = link.lastIndexOf("/") + 1; | |
const fileNameStop = link.lenght; | |
const fileName = link.substring(fileNameStart, fileNameStop); | |
const file = fs.createWriteStream(fileName); | |
http.get(link, (response) => response.pipe(file)); | |
console.log(`${new String(idx++).padStart(2, "0")}: ${fileName} `); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment