chemicaljs 1.7.3 → 1.7.4
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 +2 -368
- package/index.js +2 -0
- package/package.json +1 -1
- package/examples/example/README.md +0 -3
- package/examples/example/index.js +0 -21
- package/examples/example/package-lock.json +0 -2661
- package/examples/example/package.json +0 -24
- package/examples/example/public/index.html +0 -13
- package/examples/example-build/README.md +0 -5
- package/examples/example-build/build.js +0 -13
- package/examples/example-build/index.js +0 -16
- package/examples/example-build/package-lock.json +0 -2661
- package/examples/example-build/package.json +0 -25
- package/examples/example-build/public/index.html +0 -13
- package/examples/example-components/README.md +0 -3
- package/examples/example-components/index.js +0 -16
- package/examples/example-components/package-lock.json +0 -2661
- package/examples/example-components/package.json +0 -24
- package/examples/example-components/public/index.html +0 -45
- package/examples/example-styled/README.md +0 -3
- package/examples/example-styled/index.js +0 -16
- package/examples/example-styled/package-lock.json +0 -2661
- package/examples/example-styled/package.json +0 -24
- package/examples/example-styled/public/index.html +0 -24
- package/examples/example-styled/public/style.css +0 -82
- package/examples/example-vite/README.md +0 -9
- package/examples/example-vite/index.html +0 -12
- package/examples/example-vite/index.js +0 -16
- package/examples/example-vite/package-lock.json +0 -3636
- package/examples/example-vite/package.json +0 -19
- package/examples/example-vite/src/app.jsx +0 -14
- package/examples/example-vite/src/main.jsx +0 -4
- package/examples/example-vite/vite.config.js +0 -10
- package/update.bash +0 -16
package/README.md
CHANGED
|
@@ -1,374 +1,8 @@
|
|
|
1
1
|
# Chemical
|
|
2
2
|
Easily create your own web proxy with no experience required.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Setup
|
|
8
|
-
|
|
9
|
-
A simple example can be found in [`/example/`](https://github.com/chemicaljs/chemical/tree/main/examples/example).
|
|
10
|
-
|
|
11
|
-
A example with the vite plugin can be found in [`/example-vite/`](https://github.com/chemicaljs/chemical/tree/main/examples/example-vite).
|
|
12
|
-
|
|
13
|
-
A example with all the components can be found in [`/example-components/`](https://github.com/chemicaljs/chemical/tree/main/examples/example-components).
|
|
14
|
-
|
|
15
|
-
A real world styled example can be found in [`/example-styled/`](https://github.com/chemicaljs/chemical/tree/main/examples/example-styled).
|
|
16
|
-
|
|
17
|
-
A example with a build command and an external wisp server can be found in [`/example-build/`](https://github.com/chemicaljs/chemical/tree/main/examples/example-build).
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
### Server
|
|
21
|
-
|
|
22
|
-
Create a new Node.js project and create a script file for the server.
|
|
23
|
-
|
|
24
|
-
1. Install Chemical `npm install chemicaljs`.
|
|
25
|
-
|
|
26
|
-
2. Import `ChemicalServer` and create a new server.
|
|
27
|
-
|
|
28
|
-
```js
|
|
29
|
-
import { ChemicalServer } from "chemicaljs";
|
|
30
|
-
|
|
31
|
-
const [app, listen] = new ChemicalServer();
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
You can pass options to disable proxy services and set the default service.
|
|
35
|
-
|
|
36
|
-
```js
|
|
37
|
-
const [app, listen] = new ChemicalServer({
|
|
38
|
-
default: "rammerhead",
|
|
39
|
-
uv: true,
|
|
40
|
-
scramjet: false,
|
|
41
|
-
rammerhead: true,
|
|
42
|
-
hostname_blacklist: [ /google\.com/, /reddit\.com/ ],
|
|
43
|
-
hostname_whitelist: [ /example\.com/ ]
|
|
44
|
-
});
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
`hostname_whitelist` overrides `hostname_blacklist` if you try to set them both.
|
|
48
|
-
|
|
49
|
-
3. Use `app` which is an express app. You may need to import express for certain APIs.
|
|
50
|
-
|
|
51
|
-
```js
|
|
52
|
-
app.get("/", function(req, res){
|
|
53
|
-
res.send("Hello World");
|
|
54
|
-
});
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
4. Use `app.serveChemical()` to serve Chemical routes.
|
|
58
|
-
|
|
59
|
-
5. Use `serveChemical` after main routes but before 404 routes. Example 404 page.
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
app.use((req, res) => {
|
|
63
|
-
res.status(404);
|
|
64
|
-
res.send("404 Error");
|
|
65
|
-
});
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
4. Use `listen` on a port of your choosing.
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
listen(3000);
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Below is an example of a simple backend. This example will setup Chemical and serve the "public" folder along with the `index.html` file as `/` and `.html` files without the extension.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
```js
|
|
78
|
-
import { ChemicalServer } from "chemicaljs";
|
|
79
|
-
import express from "express";
|
|
80
|
-
|
|
81
|
-
const [app, listen] = new ChemicalServer();
|
|
82
|
-
const port = process.env.PORT || 3000;
|
|
83
|
-
|
|
84
|
-
app.use(express.static("public", {
|
|
85
|
-
index: "index.html",
|
|
86
|
-
extensions: ["html"]
|
|
87
|
-
}));
|
|
88
|
-
|
|
89
|
-
app.serveChemical();
|
|
90
|
-
|
|
91
|
-
app.use((req, res) => {
|
|
92
|
-
res.status(404);
|
|
93
|
-
res.send("404 Error");
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
listen(port, () => {
|
|
97
|
-
console.log(`Chemical demo listening on port ${port}`);
|
|
98
|
-
});
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Build
|
|
102
|
-
|
|
103
|
-
Want to use Chemical without using a custom wisp and/or rammerhead server or without a server at all?
|
|
104
|
-
|
|
105
|
-
Using the build command you can clone all needed assets into your build folder (like BareMux, Libcurl, and proxies enabled). Note that UV and Scramjet will need an external wisp server to function if you do not provide your own and Rammerhead will not work without your own Rammerhead server running.
|
|
106
|
-
|
|
107
|
-
1. Import `ChemicalBuild` and create a new build.
|
|
108
|
-
|
|
109
|
-
```js
|
|
110
|
-
const build = new ChemicalBuild({
|
|
111
|
-
path: "dist",
|
|
112
|
-
default: "uv",
|
|
113
|
-
uv: true,
|
|
114
|
-
scramjet: true,
|
|
115
|
-
rammerhead: false,
|
|
116
|
-
});
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
2. Use `build.write()` to write into the build path.
|
|
120
|
-
|
|
121
|
-
3. Use `build.write(true)` to first empty the build path.
|
|
122
|
-
|
|
123
|
-
Below if a full example of building Chemical.
|
|
124
|
-
|
|
125
|
-
```js
|
|
126
|
-
const build = new ChemicalBuild({
|
|
127
|
-
path: "dist",
|
|
128
|
-
default: "uv",
|
|
129
|
-
uv: true,
|
|
130
|
-
scramjet: true,
|
|
131
|
-
rammerhead: false,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
await build.write(true);
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Client
|
|
138
|
-
|
|
139
|
-
In your project create a folder to store your static assets. Create an index.html file which will be the homepage of your website.
|
|
140
|
-
|
|
141
|
-
1. Add the Chemical script to the top of your page. This will load all needed scripts for Chemical and other packages.
|
|
142
|
-
|
|
143
|
-
```html
|
|
144
|
-
<script src="/chemical.js"></script>
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
If you want to set the wisp server to an external server just change the `wisp` attribute.
|
|
148
|
-
|
|
149
|
-
```html
|
|
150
|
-
<script data-wisp="wss://wisp.mercurywork.shop/" src="/chemical.js"></script>
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
If you want to set the transport just change the `transport` attribute. Choose `libcurl` (default becuase it supports Firefox) or `epoxy`.
|
|
154
|
-
|
|
155
|
-
```html
|
|
156
|
-
<script data-transport="epoxy" src="/chemical.js"></script>
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
2. In a inline script or javascript file, encode a URL with Chemical using the async function `chemical.encode`.
|
|
160
|
-
|
|
161
|
-
```js
|
|
162
|
-
await chemical.encode("https://example.com")
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
Optional: Change service to `uv`, `scramjet`, or `rammerhead`. Defaults to `uv` or server option.
|
|
166
|
-
|
|
167
|
-
```js
|
|
168
|
-
await chemical.encode("https://example.com", {
|
|
169
|
-
service: "rammerhead"
|
|
170
|
-
})
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
3. To decode a URL use `chemical.decode`
|
|
174
|
-
|
|
175
|
-
```js
|
|
176
|
-
const encodedURL = await chemical.encode("https://example.com")
|
|
177
|
-
const decodedURL = await chemical.decode(encodedURL)
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
4. Set `autoHttps` to make `example.com` > `https://example.com`
|
|
181
|
-
|
|
182
|
-
```js
|
|
183
|
-
await chemical.encode("example.com", {
|
|
184
|
-
autoHttps: true
|
|
185
|
-
})
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
5. Use a search engine with the `searchEngine` property. Use a search engine URL with "%s" in place of query.
|
|
189
|
-
|
|
190
|
-
```js
|
|
191
|
-
await chemical.encode("cheese", {
|
|
192
|
-
searchEngine: "https://www.google.com/search?q=%s"
|
|
193
|
-
})
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
6. You may want to check if Chemical has loaded before encoding a URL.
|
|
197
|
-
|
|
198
|
-
```js
|
|
199
|
-
if (window.chemical.loaded) {
|
|
200
|
-
//Chemical is loaded
|
|
201
|
-
}
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
```js
|
|
205
|
-
window.addEventListener("chemicalLoaded", function(e) {
|
|
206
|
-
//Chemical has loaded
|
|
207
|
-
});
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
7. Change the transport with `chemical.setTransport`
|
|
211
|
-
|
|
212
|
-
```js
|
|
213
|
-
await chemical.setTransport("libcurl") //libcurl or epoxy
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
8. Change the Wisp URL with `chemical.setWisp`
|
|
217
|
-
|
|
218
|
-
```js
|
|
219
|
-
await chemical.setWisp("wss://wisp.mercurywork.shop/")
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
Below is a simple example of a simple input that redirects to the encoded URL when the user presses enter. It checks if there is any input and if Chemical has loaded before loading.
|
|
223
|
-
|
|
224
|
-
```html
|
|
225
|
-
<h1>Chemical Example</h1>
|
|
226
|
-
<input id="search" placeholder="Enter URL">
|
|
227
|
-
|
|
228
|
-
<script src="/chemical.js"></script>
|
|
229
|
-
<script>
|
|
230
|
-
const search = document.getElementById("search");
|
|
231
|
-
|
|
232
|
-
search.addEventListener("keydown", async function (e) {
|
|
233
|
-
if (e.key == "Enter" && chemical.loaded && e.target.value) {
|
|
234
|
-
window.location = await chemical.encode(e.target.value)
|
|
235
|
-
}
|
|
236
|
-
})
|
|
237
|
-
</script>
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
9. Fetch websites through Wisp using `chemical.fetch`. This works the same as the fetch API.
|
|
241
|
-
|
|
242
|
-
10. Get search suggestions via DuckDuckGo using `chemical.getSuggestions`
|
|
243
|
-
|
|
244
|
-
```js
|
|
245
|
-
await chemical.getSuggestions("google")
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
## Vite Plugin
|
|
249
|
-
|
|
250
|
-
1. Create a new vite app and open `vite.config.js` or `vite.config.ts`
|
|
251
|
-
|
|
252
|
-
2. Import `ChemicalVitePlugin` and add it to plugins.
|
|
253
|
-
|
|
254
|
-
```js
|
|
255
|
-
import { defineConfig } from "vite"
|
|
256
|
-
import { ChemicalVitePlugin } from "chemicaljs"
|
|
257
|
-
|
|
258
|
-
export default defineConfig({
|
|
259
|
-
plugins: [/*Other plugins*/ChemicalVitePlugin()],
|
|
260
|
-
})
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
You can pass options to just like on the main server.
|
|
264
|
-
|
|
265
|
-
```js
|
|
266
|
-
export default defineConfig({
|
|
267
|
-
plugins: [
|
|
268
|
-
ChemicalVitePlugin({
|
|
269
|
-
default: "rammerhead",
|
|
270
|
-
uv: true,
|
|
271
|
-
scramjet: false,
|
|
272
|
-
rammerhead: true,
|
|
273
|
-
hostname_blacklist: [ /google\.com/, /reddit\.com/ ],
|
|
274
|
-
hostname_whitelist: [ /example\.com/ ]
|
|
275
|
-
})
|
|
276
|
-
],
|
|
277
|
-
})
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
## Components
|
|
281
|
-
Setup a proxy site with easy HTML components.
|
|
282
|
-
|
|
283
|
-
1. Add the Chemical components along with the main script to the top of your page.
|
|
284
|
-
|
|
285
|
-
```html
|
|
286
|
-
<script src="/chemical.js"></script>
|
|
287
|
-
<script src="/chemical.components.js"></script>
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
2. Now add any component to your site!
|
|
291
|
-
|
|
292
|
-
### Link
|
|
293
|
-
|
|
294
|
-
An anchor link but it automatically encodes the URL.
|
|
295
|
-
|
|
296
|
-
```html
|
|
297
|
-
<a data-href="https://example.com" is="chemical-link">Link</a>
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
You can also add `data-service="uv"`, `data-autoHttps`, and `data-search-engine="https://www.google.com/search?q=%s"`
|
|
301
|
-
|
|
302
|
-
You can style the link as chemical is loading.
|
|
303
|
-
|
|
304
|
-
```css
|
|
305
|
-
a[data-chemical-loading="true"] {
|
|
306
|
-
cursor: wait;
|
|
307
|
-
}
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
### Basic Input
|
|
311
|
-
|
|
312
|
-
Opens in the current tab when the enter key is pressed.
|
|
313
|
-
|
|
314
|
-
```html
|
|
315
|
-
<input data-target="_self" placeholder="Enter URL" is="chemical-input">
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
You can also add `data-service="uv"`, `data-autoHttps`, and `data-search-engine="https://www.google.com/search?q=%s"`
|
|
319
|
-
|
|
320
|
-
Opens in current tab when the enter key is pressed.
|
|
321
|
-
|
|
322
|
-
```html
|
|
323
|
-
<input data-target="_blank" placeholder="Enter URL" is="chemical-input">
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
Custom action when the enter key is pressed. Change `data-action` to your function name. The first parameter of the action will be the encoded URL.
|
|
327
|
-
|
|
328
|
-
```html
|
|
329
|
-
<input data-action="logURL" placeholder="Enter URL" is="chemical-input">
|
|
330
|
-
<script>
|
|
331
|
-
function logURL(url) {
|
|
332
|
-
console.log(url)
|
|
333
|
-
}
|
|
334
|
-
</script>
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
### Input with Button
|
|
338
|
-
|
|
339
|
-
Opens when the enter key is pressed or button is clicked. Set the `for` attribute to the `id` of the button.
|
|
340
|
-
|
|
341
|
-
```html
|
|
342
|
-
<input id="my-input" data-target="_blank" placeholder="Enter URL" is="chemical-input">
|
|
343
|
-
<button data-for="my-input" is="chemical-button">Go!</button>
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
### With iframe
|
|
347
|
-
|
|
348
|
-
A hidden iframe that is shown when the enter key is pressed. Set the `frame` attribute to the `id` of the iframe.
|
|
349
|
-
|
|
350
|
-
```html
|
|
351
|
-
<input data-frame="my-iframe" placeholder="Enter URL" is="chemical-input">
|
|
352
|
-
<iframe id="my-iframe" is="chemical-iframe"></iframe>
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
A hidden iframe that is shown when the enter key is pressed. Includes controls the are hidden when the iframe is hidden and can control websites in the iframe as well as hiding the iframe and controls.
|
|
356
|
-
|
|
357
|
-
Set the `frame` attribute to the `id` of the iframe.
|
|
358
|
-
Set the `controls` attribute to the `id` of the controls.
|
|
359
|
-
|
|
360
|
-
Set the second parameter of `chemicalAction` to the `id` of the iframe.
|
|
361
|
-
|
|
362
|
-
```html
|
|
363
|
-
<input data-frame="my-iframe-2" placeholder="Enter URL" is="chemical-input">
|
|
364
|
-
<section id="my-controls-2" is="chemical-controls">
|
|
365
|
-
<button onclick="chemicalAction('back', 'my-iframe-2')">←</button>
|
|
366
|
-
<button onclick="chemicalAction('forward', 'my-iframe-2')">→</button>
|
|
367
|
-
<button onclick="chemicalAction('reload', 'my-iframe-2')">⟳</button>
|
|
368
|
-
<button onclick="chemicalAction('close', 'my-iframe-2')">🗙</button>
|
|
369
|
-
</section>
|
|
370
|
-
<iframe data-controls="my-controls-2" id="my-iframe-2" is="chemical-iframe"></iframe>
|
|
371
|
-
```
|
|
4
|
+
## Docs
|
|
5
|
+
You can find documentation for Chemical on our website [https://chemicaljs.github.io](chemicaljs.github.io).
|
|
372
6
|
|
|
373
7
|
## License
|
|
374
8
|
Chemical uses the AGPL 3.0 license.
|
package/index.js
CHANGED
|
@@ -296,6 +296,8 @@ class ChemicalBuild {
|
|
|
296
296
|
chemicalMain = "const scramjetEnabled = " + String(this.options.scramjet) + ";\n" + chemicalMain
|
|
297
297
|
chemicalMain = "const rammerheadEnabled = " + String(this.options.rammerhead) + ";\n" + chemicalMain
|
|
298
298
|
|
|
299
|
+
chemicalMain = "(async () => {\n" + chemicalMain + "\n})();";
|
|
300
|
+
|
|
299
301
|
writeFileSync(resolve(this.options.path, "chemical.js"), chemicalMain);
|
|
300
302
|
|
|
301
303
|
let chemicalSW = await readFileSync(resolve(__dirname, "client/chemical.sw.js"), "utf8");
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ChemicalServer } from "chemicaljs";
|
|
2
|
-
import express from "express";
|
|
3
|
-
|
|
4
|
-
const [app, listen] = new ChemicalServer();
|
|
5
|
-
const port = process.env.PORT || 3000;
|
|
6
|
-
|
|
7
|
-
app.use(express.static("public", {
|
|
8
|
-
index: "index.html",
|
|
9
|
-
extensions: ["html"]
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
app.serveChemical();
|
|
13
|
-
|
|
14
|
-
app.use((req, res) => {
|
|
15
|
-
res.status(404);
|
|
16
|
-
res.send("404 Error");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
listen(port, () => {
|
|
20
|
-
console.log(`Chemical example listening on port ${port}`);
|
|
21
|
-
});
|