ai-nevermore 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,16 +1,66 @@
1
1
  Nevermore
2
2
  =========
3
3
 
4
- Nevermore is a library to obfuscate plain text on the web to prevent AI scraping so while a user will see
4
+ Nevermore is a library to obfuscate media on the web to prevent AI scraping.
5
5
 
6
- ![original text](./images/original.png)
6
+ Text
7
+ ---
8
+ while a user will see
9
+
10
+ ![original text](https://raw.githubusercontent.com/khrome/nevermore/master/images/original.png)
7
11
 
8
12
  A scraper coming to your site will see something like
9
13
 
10
- ![encoded text](./images/encoded.png)
14
+ ![encoded text](https://raw.githubusercontent.com/khrome/nevermore/master/images/encoded.png)
11
15
 
12
16
  Which will both prevent the scraper from acquiring your content as well as [poisoning the model trained](https://en.wikipedia.org/wiki/Adversarial_machine_learning#Data_poisoning) from it.
13
17
 
18
+ Images
19
+ ------
20
+
21
+ First you encode an image with:
22
+
23
+ `nevermore pseudoimage <target> --image-output <output> --encode`
24
+
25
+ which produces and encoded image, seemingly static filled.
26
+
27
+ Then you include the encoded image along with it's key(This uses the source directly, but it is also is compatible with your favorite build tool) the stub entries must point at any valid ESM file and are not used.
28
+
29
+ ```html
30
+ <html>
31
+ <head>
32
+ <script type="importmap">
33
+ {"imports":{
34
+ "node:os":"<path-to-stub>",
35
+ "node:stream":"<path-to-stub>",
36
+ "fs":"<path-to-stub>",
37
+ "os":"<path-to-stub>",
38
+ "module":"<path-to-stub>",
39
+ "nevermore/encoded-image":"./node_modules/nevermore/src/encoded-image-component.mjs",
40
+ "@environment-safe/canvas":"./node_modules/@environment-safe/canvas/src/index.mjs",
41
+ "@environment-safe/file":"./node_modules/@environment-safe/file/src/index.mjs",
42
+ "@environment-safe/elements":"./node_modules/@environment-safe/elements/src/index.mjs",
43
+ "@environment-safe/runtime-context":"./node_modules/@environment-safe/runtime-context/src/index.mjs"
44
+ }}
45
+ </script>
46
+ <script type="module">
47
+ import 'nevermore/encoded-image';
48
+ </script>
49
+ </head>
50
+ <body>
51
+ <encoded-image src="encoded-image-location" key="VFYZT-HPTRG-PGHRT"></encoded-image>
52
+ </body>
53
+ </html>
54
+ ```
55
+
56
+ Markup
57
+ ------
58
+ Nevermore can traverse and inline transform all text and image elements in an HTML body.
59
+
60
+ `nevermore pseudomarkup <target> --unified-output <output location>`
61
+
62
+ this puts imports, styles and image decodes all inline.
63
+
14
64
  Programmatic Usage
15
65
  ------------------
16
66
  This library can be used to generate the html and css:
@@ -22,6 +72,19 @@ const { root, index } = await computeIndexKeys(inputText);
22
72
  const { html, css } = await generateHTMLAndCSS(root, index);
23
73
  ```
24
74
 
75
+ You can programmatically encode/decode images:
76
+ ```js
77
+ const image = new NevermoreImage({
78
+ url:'<target>',
79
+ maskDir: '<texture_dir>'
80
+ });
81
+ await image.ready;
82
+ const canvas = image.encode();
83
+ await Canvas.save('./encoded.jpg', canvas);
84
+ const decoded = image.decode();
85
+ await Canvas.save('./decoded.jpg', decoded);
86
+ ```
87
+
25
88
  Command Line Usage
26
89
  ------------------
27
90
  Install with `npm install -g ai-nevermore`
@@ -29,8 +92,9 @@ Install with `npm install -g ai-nevermore`
29
92
  nevermore [command]
30
93
 
31
94
  Commands:
32
- nevermore pseudotext [input-file] transform text to poison
33
- nevermore pseudoimage [input-file] transform XOR image encoding
95
+ nevermore pseudotext [input-file] transform text to poison
96
+ nevermore pseudoimage [input-file] transform XOR image encoding
97
+ nevermore pseudomarkup [input-file] transform html content
34
98
 
35
99
  Options:
36
100
  --version Show version number [boolean]
package/bin/nevermore CHANGED
@@ -3,7 +3,9 @@ import yargs from 'yargs';
3
3
  import { hideBin } from 'yargs/helpers';
4
4
  import { computeIndexKeys, generateHTMLAndCSS } from '../src/index.mjs';
5
5
  import { NevermoreImage } from '../src/image.mjs';
6
+ import { transformHTML } from '../src/html.mjs'
6
7
  import { Canvas } from '@environment-safe/canvas';
8
+ import { parse } from 'parse5';
7
9
  import { readFile, writeFile } from 'node:fs/promises';
8
10
  import { join } from 'node:path';
9
11
  const { cwd } = process;
@@ -100,6 +102,7 @@ yargs(hideBin(process.argv))
100
102
  let canvas = null;
101
103
  if(argv['encode']){
102
104
  canvas = await image.encode();
105
+ console.log('KEY:', image.key);
103
106
  }
104
107
  if(argv['decode']){
105
108
  canvas = await image.decode();
@@ -108,6 +111,27 @@ yargs(hideBin(process.argv))
108
111
  }else{
109
112
  throw new Error('piped output not yet supported');
110
113
  }
114
+ }).command('pseudomarkup [input-file]', 'transform html content', (yargs) => {
115
+ return yargs
116
+ .positional('input-file', {
117
+ describe: 'file input'
118
+ })
119
+ }, async (argv) => {
120
+ let result = null;
121
+ if(!argv['input-file']){
122
+ //TODO: pipe support
123
+ throw new Error('pipe not yet supported');
124
+ }else{
125
+ const target = await readFile(argv['input-file']);
126
+ const parsed = parse(target.toString());
127
+ result = await transformHTML(parsed);
128
+ }
129
+ if(result && argv['unified-output']){
130
+ await writeFile(argv['unified-output'], result);
131
+ }else{
132
+ console.log(result);
133
+ //throw new Error('piped output not yet supported');
134
+ }
111
135
  }).option('key', {
112
136
  alias: 'K',
113
137
  type: 'string',
package/decoded.jpg ADDED
Binary file
package/demo.html ADDED
@@ -0,0 +1,24 @@
1
+ <html>
2
+ <head>
3
+ <script type="importmap">
4
+ {"imports":{
5
+ "node:os":"/src/encoded-image-component.mjs",
6
+ "node:stream":"/src/encoded-image-component.mjs",
7
+ "fs":"/src/encoded-image-component.mjs",
8
+ "os":"/src/encoded-image-component.mjs",
9
+ "module":"/src/encoded-image-component.mjs",
10
+ "nevermore/encoded-image-component":"./src/encoded-image-component.mjs",
11
+ "@environment-safe/canvas":"./node_modules/@environment-safe/canvas/src/index.mjs",
12
+ "@environment-safe/file":"./node_modules/@environment-safe/file/src/index.mjs",
13
+ "@environment-safe/elements":"./node_modules/@environment-safe/elements/src/index.mjs",
14
+ "@environment-safe/runtime-context":"./node_modules/@environment-safe/runtime-context/src/index.mjs"
15
+ }}
16
+ </script>
17
+ <script type="module">
18
+ import 'nevermore/encoded-image-component';
19
+ </script>
20
+ </head>
21
+ <body>
22
+ <encoded-image src="./out.jpg" key="VFYZT-HPTRG-PGHRT"></encoded-image>
23
+ </body>
24
+ </html>
Binary file