diff --git a/example/demo.ts b/example/demo.ts
index d1a9f44..caafbb3 100644
--- a/example/demo.ts
+++ b/example/demo.ts
@@ -38,7 +38,7 @@ app.get('/', (req, res) => {
-
+
@@ -99,10 +99,34 @@ app.get('/', (req, res) => {
`)
})
+app.get('/remote-demo', async (_, res) => {
+ const response = await fetch('http://localhost:1337/example.ttf')
+ const buffer = await response.arrayBuffer();
+
+ const noscrape = new Noscrape(buffer);
+
+ const text = noscrape.obfuscate("this is another demo");
-app.listen(1337, () => {
- console.log('listen on port', 1337)
+
+ res.send(`
+
+ Noscrape - DEMO
+
+
+
+ ${text}
+
+
+ `)
})
+app.listen(1337)
+
+
diff --git a/src/noscrape.ts b/src/noscrape.ts
index 572fa25..36f3b89 100644
--- a/src/noscrape.ts
+++ b/src/noscrape.ts
@@ -1,4 +1,4 @@
-import { Font, Glyph, loadSync } from "opentype.js";
+import { Font, Glyph, loadSync, parse } from "opentype.js";
import { DEFAULT_OPTIONS, ObfuscationOptions } from "./obfuscation-options";
import { value2glyphs } from "./value2glyphs";
import { obfuscateValue } from "./obfuscate/value";
@@ -23,16 +23,26 @@ export class Noscrape {
/**
* Initializes a new instance of the Noscrape class.
*
- * @param {string} fontFilePath - The file path to the true-type font.
+ * @param {string | ArrayBuffer | SharedArrayBuffer} font
+ * In case of string: only local file path is provided. Otherwise, load file with fetch or similar api and provide
+ * (Shared)ArrayBuffer to Noscrape. Working example can be found at the Demo-Server sources:
+ * npm run demo -> http://localhost:1337/remote-demo
* @param {ObfuscationOptions} options - Optional configuration options for obfuscation.
*/
- constructor(fontFilePath: string, options?: ObfuscationOptions) {
+ constructor(
+ font: string | ArrayBuffer | SharedArrayBuffer,
+ options?: ObfuscationOptions,
+ ) {
this.options = {
...DEFAULT_OPTIONS,
...options,
};
- this.font = loadSync(fontFilePath, { lowMemory: this.options.lowMemory });
+ if (typeof font === "string") {
+ this.font = loadSync(font, { lowMemory: this.options.lowMemory });
+ } else {
+ this.font = parse(font);
+ }
}
/**