chemicaljs 1.7.0 → 1.7.2
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 +15 -0
- package/client/chemical.js +143 -105
- package/examples/example/package-lock.json +4 -4
- package/examples/example/package.json +1 -1
- package/examples/example-build/package-lock.json +4 -4
- package/examples/example-build/package.json +1 -1
- package/examples/example-components/package-lock.json +4 -4
- package/examples/example-components/package.json +1 -1
- package/examples/example-styled/package-lock.json +4 -4
- package/examples/example-styled/package.json +1 -1
- package/examples/example-vite/package-lock.json +4 -4
- package/examples/example-vite/package.json +1 -1
- package/index.js +15 -78
- package/package.json +3 -3
- package/rammerhead.tgz +0 -0
package/README.md
CHANGED
|
@@ -170,6 +170,13 @@ await chemical.encode("https://example.com", {
|
|
|
170
170
|
})
|
|
171
171
|
```
|
|
172
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
|
+
|
|
173
180
|
4. Set `autoHttps` to make `example.com` > `https://example.com`
|
|
174
181
|
|
|
175
182
|
```js
|
|
@@ -230,6 +237,14 @@ Below is a simple example of a simple input that redirects to the encoded URL wh
|
|
|
230
237
|
</script>
|
|
231
238
|
```
|
|
232
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
|
+
|
|
233
248
|
## Vite Plugin
|
|
234
249
|
|
|
235
250
|
1. Create a new vite app and open `vite.config.js` or `vite.config.ts`
|
package/client/chemical.js
CHANGED
|
@@ -4,178 +4,192 @@ window.chemical = {
|
|
|
4
4
|
wisp: document.currentScript.dataset.wisp || (location.protocol === "https:" ? "wss" : "ws") + "://" + location.host + "/wisp/"
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
function rammerheadEncode(baseUrl) {
|
|
8
|
-
const mod = (n, m) => ((n % m) + m) % m
|
|
7
|
+
function rammerheadEncode(baseUrl, decode = false) {
|
|
8
|
+
const mod = (n, m) => ((n % m) + m) % m;
|
|
9
9
|
const baseDictionary =
|
|
10
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~-"
|
|
11
|
-
const shuffledIndicator = "_rhs"
|
|
10
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~-";
|
|
11
|
+
const shuffledIndicator = "_rhs";
|
|
12
|
+
|
|
12
13
|
const generateDictionary = function () {
|
|
13
|
-
let str = ""
|
|
14
|
-
const split = baseDictionary.split("")
|
|
14
|
+
let str = "";
|
|
15
|
+
const split = baseDictionary.split("");
|
|
15
16
|
while (split.length > 0) {
|
|
16
|
-
str += split.splice(Math.floor(Math.random() * split.length), 1)[0]
|
|
17
|
+
str += split.splice(Math.floor(Math.random() * split.length), 1)[0];
|
|
17
18
|
}
|
|
18
|
-
return str
|
|
19
|
-
}
|
|
19
|
+
return str;
|
|
20
|
+
};
|
|
21
|
+
|
|
20
22
|
class StrShuffler {
|
|
21
23
|
constructor(dictionary = generateDictionary()) {
|
|
22
|
-
this.dictionary = dictionary
|
|
24
|
+
this.dictionary = dictionary;
|
|
23
25
|
}
|
|
26
|
+
|
|
24
27
|
shuffle(str) {
|
|
25
28
|
if (str.startsWith(shuffledIndicator)) {
|
|
26
|
-
return str
|
|
29
|
+
return str;
|
|
27
30
|
}
|
|
28
|
-
let shuffledStr = ""
|
|
31
|
+
let shuffledStr = "";
|
|
29
32
|
for (let i = 0; i < str.length; i++) {
|
|
30
|
-
const char = str.charAt(i)
|
|
31
|
-
const idx = baseDictionary.indexOf(char)
|
|
33
|
+
const char = str.charAt(i);
|
|
34
|
+
const idx = baseDictionary.indexOf(char);
|
|
32
35
|
if (char === "%" && str.length - i >= 3) {
|
|
33
|
-
shuffledStr += char
|
|
34
|
-
shuffledStr += str.charAt(++i)
|
|
35
|
-
shuffledStr += str.charAt(++i)
|
|
36
|
+
shuffledStr += char;
|
|
37
|
+
shuffledStr += str.charAt(++i);
|
|
38
|
+
shuffledStr += str.charAt(++i);
|
|
36
39
|
} else if (idx === -1) {
|
|
37
|
-
shuffledStr += char
|
|
40
|
+
shuffledStr += char;
|
|
38
41
|
} else {
|
|
39
42
|
shuffledStr += this.dictionary.charAt(
|
|
40
43
|
mod(idx + i, baseDictionary.length)
|
|
41
|
-
)
|
|
44
|
+
);
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
|
-
return shuffledIndicator + shuffledStr
|
|
47
|
+
return shuffledIndicator + shuffledStr;
|
|
45
48
|
}
|
|
49
|
+
|
|
46
50
|
unshuffle(str) {
|
|
47
51
|
if (!str.startsWith(shuffledIndicator)) {
|
|
48
|
-
return str
|
|
52
|
+
return str;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
str = str.slice(shuffledIndicator.length)
|
|
55
|
+
str = str.slice(shuffledIndicator.length);
|
|
52
56
|
|
|
53
|
-
let unshuffledStr = ""
|
|
57
|
+
let unshuffledStr = "";
|
|
54
58
|
for (let i = 0; i < str.length; i++) {
|
|
55
|
-
const char = str.charAt(i)
|
|
56
|
-
const idx = this.dictionary.indexOf(char)
|
|
59
|
+
const char = str.charAt(i);
|
|
60
|
+
const idx = this.dictionary.indexOf(char);
|
|
57
61
|
if (char === "%" && str.length - i >= 3) {
|
|
58
|
-
unshuffledStr += char
|
|
59
|
-
unshuffledStr += str.charAt(++i)
|
|
60
|
-
unshuffledStr += str.charAt(++i)
|
|
62
|
+
unshuffledStr += char;
|
|
63
|
+
unshuffledStr += str.charAt(++i);
|
|
64
|
+
unshuffledStr += str.charAt(++i);
|
|
61
65
|
} else if (idx === -1) {
|
|
62
|
-
unshuffledStr += char
|
|
66
|
+
unshuffledStr += char;
|
|
63
67
|
} else {
|
|
64
68
|
unshuffledStr += baseDictionary.charAt(
|
|
65
69
|
mod(idx - i, baseDictionary.length)
|
|
66
|
-
)
|
|
70
|
+
);
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
|
-
return unshuffledStr
|
|
73
|
+
return unshuffledStr;
|
|
70
74
|
}
|
|
71
75
|
}
|
|
76
|
+
|
|
72
77
|
function get(url, callback, shush = false) {
|
|
73
|
-
var request = new XMLHttpRequest()
|
|
74
|
-
request.open("GET", url, true)
|
|
75
|
-
request.send()
|
|
78
|
+
var request = new XMLHttpRequest();
|
|
79
|
+
request.open("GET", url, true);
|
|
80
|
+
request.send();
|
|
76
81
|
|
|
77
82
|
request.onerror = function () {
|
|
78
|
-
if (!shush) console.log("Cannot communicate with the server")
|
|
79
|
-
}
|
|
83
|
+
if (!shush) console.log("Cannot communicate with the server");
|
|
84
|
+
};
|
|
80
85
|
request.onload = function () {
|
|
81
86
|
if (request.status === 200) {
|
|
82
|
-
callback(request.responseText)
|
|
87
|
+
callback(request.responseText);
|
|
83
88
|
} else {
|
|
84
89
|
if (!shush)
|
|
85
90
|
console.log(
|
|
86
91
|
'unexpected server response to not match "200". Server says "' +
|
|
87
92
|
request.responseText +
|
|
88
93
|
'"'
|
|
89
|
-
)
|
|
94
|
+
);
|
|
90
95
|
}
|
|
91
|
-
}
|
|
96
|
+
};
|
|
92
97
|
}
|
|
98
|
+
|
|
93
99
|
var api = {
|
|
94
100
|
newsession(callback) {
|
|
95
|
-
get("/newsession", callback)
|
|
101
|
+
get("/newsession", callback);
|
|
96
102
|
},
|
|
97
103
|
sessionexists(id, callback) {
|
|
98
104
|
get("/sessionexists?id=" + encodeURIComponent(id), function (res) {
|
|
99
|
-
if (res === "exists") return callback(true)
|
|
100
|
-
if (res === "not found") return callback(false)
|
|
101
|
-
console.log("unexpected response from server. received" + res)
|
|
102
|
-
})
|
|
105
|
+
if (res === "exists") return callback(true);
|
|
106
|
+
if (res === "not found") return callback(false);
|
|
107
|
+
console.log("unexpected response from server. received" + res);
|
|
108
|
+
});
|
|
103
109
|
},
|
|
104
110
|
shuffleDict(id, callback) {
|
|
105
|
-
console.log("Shuffling", id)
|
|
111
|
+
console.log("Shuffling", id);
|
|
106
112
|
get("/api/shuffleDict?id=" + encodeURIComponent(id), function (res) {
|
|
107
|
-
callback(JSON.parse(res))
|
|
108
|
-
})
|
|
113
|
+
callback(JSON.parse(res));
|
|
114
|
+
});
|
|
109
115
|
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
var
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
var localStorageKey = "rammerhead_sessionids";
|
|
119
|
+
var localStorageKeyDefault = "rammerhead_default_sessionid";
|
|
113
120
|
var sessionIdsStore = {
|
|
114
121
|
get() {
|
|
115
|
-
var rawData = localStorage.getItem(localStorageKey)
|
|
116
|
-
if (!rawData) return []
|
|
122
|
+
var rawData = localStorage.getItem(localStorageKey);
|
|
123
|
+
if (!rawData) return [];
|
|
117
124
|
try {
|
|
118
|
-
var data = JSON.parse(rawData)
|
|
119
|
-
if (!Array.isArray(data)) throw "getout"
|
|
120
|
-
return data
|
|
125
|
+
var data = JSON.parse(rawData);
|
|
126
|
+
if (!Array.isArray(data)) throw "getout";
|
|
127
|
+
return data;
|
|
121
128
|
} catch (e) {
|
|
122
|
-
return []
|
|
129
|
+
return [];
|
|
123
130
|
}
|
|
124
131
|
},
|
|
125
132
|
set(data) {
|
|
126
|
-
if (!data || !Array.isArray(data)) throw new TypeError("must be array")
|
|
127
|
-
localStorage.setItem(localStorageKey, JSON.stringify(data))
|
|
133
|
+
if (!data || !Array.isArray(data)) throw new TypeError("must be array");
|
|
134
|
+
localStorage.setItem(localStorageKey, JSON.stringify(data));
|
|
128
135
|
},
|
|
129
136
|
getDefault() {
|
|
130
|
-
var sessionId = localStorage.getItem(localStorageKeyDefault)
|
|
137
|
+
var sessionId = localStorage.getItem(localStorageKeyDefault);
|
|
131
138
|
if (sessionId) {
|
|
132
|
-
var data = sessionIdsStore.get()
|
|
139
|
+
var data = sessionIdsStore.get();
|
|
133
140
|
data.filter(function (e) {
|
|
134
|
-
return e.id === sessionId
|
|
135
|
-
})
|
|
136
|
-
if (data.length) return data[0]
|
|
141
|
+
return e.id === sessionId;
|
|
142
|
+
});
|
|
143
|
+
if (data.length) return data[0];
|
|
137
144
|
}
|
|
138
|
-
return null
|
|
145
|
+
return null;
|
|
139
146
|
},
|
|
140
147
|
setDefault(id) {
|
|
141
|
-
localStorage.setItem(localStorageKeyDefault, id)
|
|
148
|
+
localStorage.setItem(localStorageKeyDefault, id);
|
|
142
149
|
}
|
|
143
|
-
}
|
|
150
|
+
};
|
|
151
|
+
|
|
144
152
|
function addSession(id) {
|
|
145
|
-
var data = sessionIdsStore.get()
|
|
146
|
-
data.unshift({ id: id, createdOn: new Date().toLocaleString() })
|
|
147
|
-
sessionIdsStore.set(data)
|
|
153
|
+
var data = sessionIdsStore.get();
|
|
154
|
+
data.unshift({ id: id, createdOn: new Date().toLocaleString() });
|
|
155
|
+
sessionIdsStore.set(data);
|
|
148
156
|
}
|
|
157
|
+
|
|
149
158
|
function getSessionId() {
|
|
150
159
|
return new Promise(resolve => {
|
|
151
|
-
var id = localStorage.getItem("session-string")
|
|
160
|
+
var id = localStorage.getItem("session-string");
|
|
152
161
|
api.sessionexists(id, function (value) {
|
|
153
162
|
if (!value) {
|
|
154
|
-
console.log("Session validation failed")
|
|
163
|
+
console.log("Session validation failed");
|
|
155
164
|
api.newsession(function (id) {
|
|
156
|
-
addSession(id)
|
|
157
|
-
localStorage.setItem("session-string", id)
|
|
158
|
-
console.log(id)
|
|
159
|
-
console.log("^ new id")
|
|
160
|
-
resolve(id)
|
|
161
|
-
})
|
|
165
|
+
addSession(id);
|
|
166
|
+
localStorage.setItem("session-string", id);
|
|
167
|
+
console.log(id);
|
|
168
|
+
console.log("^ new id");
|
|
169
|
+
resolve(id);
|
|
170
|
+
});
|
|
162
171
|
} else {
|
|
163
|
-
resolve(id)
|
|
172
|
+
resolve(id);
|
|
164
173
|
}
|
|
165
|
-
})
|
|
166
|
-
})
|
|
174
|
+
});
|
|
175
|
+
});
|
|
167
176
|
}
|
|
168
|
-
|
|
177
|
+
|
|
178
|
+
var ProxyHref;
|
|
169
179
|
|
|
170
180
|
return getSessionId().then(id => {
|
|
171
181
|
return new Promise(resolve => {
|
|
172
182
|
api.shuffleDict(id, function (shuffleDict) {
|
|
173
|
-
var shuffler = new StrShuffler(shuffleDict)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
var shuffler = new StrShuffler(shuffleDict);
|
|
184
|
+
if (decode) {
|
|
185
|
+
ProxyHref = shuffler.unshuffle(baseUrl.split(id + "/")[1]);
|
|
186
|
+
} else {
|
|
187
|
+
ProxyHref = "/" + id + "/" + shuffler.shuffle(baseUrl);
|
|
188
|
+
}
|
|
189
|
+
resolve(ProxyHref);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
|
179
193
|
}
|
|
180
194
|
|
|
181
195
|
async function encodeService(url, service) {
|
|
@@ -197,7 +211,7 @@ async function encodeService(url, service) {
|
|
|
197
211
|
case "scramjet":
|
|
198
212
|
if (scramjetEnabled) {
|
|
199
213
|
return (
|
|
200
|
-
|
|
214
|
+
window.location.origin +
|
|
201
215
|
window.__scramjet$config.prefix +
|
|
202
216
|
window.__scramjet$config.codec.encode(url)
|
|
203
217
|
);
|
|
@@ -225,6 +239,32 @@ window.chemical.encode = async function (url, config) {
|
|
|
225
239
|
}
|
|
226
240
|
}
|
|
227
241
|
|
|
242
|
+
window.chemical.decode = async function (url, config) {
|
|
243
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
244
|
+
config = {
|
|
245
|
+
service: defaultService,
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
switch (config.service) {
|
|
250
|
+
case "uv":
|
|
251
|
+
if (uvEnabled) {
|
|
252
|
+
return __uv$config.decodeUrl(url.split(__uv$config.prefix)[1]);
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
case "rammerhead":
|
|
256
|
+
if (rammerheadEnabled) {
|
|
257
|
+
return await rammerheadEncode(url.split(window.location.origin)[1], true);
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
case "scramjet":
|
|
261
|
+
if (scramjetEnabled) {
|
|
262
|
+
return __scramjet$config.codec.decode(url.split(__scramjet$config.prefix)[1]);
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
228
268
|
function getTransport(transport) {
|
|
229
269
|
switch (transport) {
|
|
230
270
|
default:
|
|
@@ -291,20 +331,18 @@ function setupFetch() {
|
|
|
291
331
|
}
|
|
292
332
|
}
|
|
293
333
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
window.dispatchEvent(new Event("chemicalLoaded"));
|
|
310
|
-
})();
|
|
334
|
+
await loadScript("/baremux/index.js");
|
|
335
|
+
if (uvEnabled) {
|
|
336
|
+
await loadScript("/uv/uv.bundle.js");
|
|
337
|
+
await loadScript("/uv/uv.config.js");
|
|
338
|
+
}
|
|
339
|
+
if (scramjetEnabled) {
|
|
340
|
+
await loadScript("/scramjet/scramjet.codecs.js");
|
|
341
|
+
await loadScript("/scramjet/scramjet.config.js");
|
|
342
|
+
}
|
|
343
|
+
window.chemical.connection = new window.BareMux.BareMuxConnection("/baremux/worker.js");
|
|
344
|
+
await window.chemical.setTransport();
|
|
345
|
+
setupFetch();
|
|
346
|
+
await registerSW();
|
|
347
|
+
window.chemical.loaded = true;
|
|
348
|
+
window.dispatchEvent(new Event("chemicalLoaded"));
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"chemicaljs": "^1.
|
|
12
|
+
"chemicaljs": "^1.7.1",
|
|
13
13
|
"express": "^4.19.2"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
@@ -1163,9 +1163,9 @@
|
|
|
1163
1163
|
}
|
|
1164
1164
|
},
|
|
1165
1165
|
"node_modules/chemicaljs": {
|
|
1166
|
-
"version": "1.
|
|
1167
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.
|
|
1168
|
-
"integrity": "sha512-
|
|
1166
|
+
"version": "1.7.1",
|
|
1167
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.7.1.tgz",
|
|
1168
|
+
"integrity": "sha512-UJubi8iIBH6mApXk0gzAHguU8l7tsG44urT9RcrULqSFktoIDgWt1nHfLnLz+HgooUBuiInd63zBRsaUzFFUIw==",
|
|
1169
1169
|
"dependencies": {
|
|
1170
1170
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1171
1171
|
"@mercuryworkshop/epoxy-transport": "^2.1.8",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"chemicaljs": "^1.
|
|
12
|
+
"chemicaljs": "^1.7.1",
|
|
13
13
|
"express": "^4.19.2"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
@@ -1163,9 +1163,9 @@
|
|
|
1163
1163
|
}
|
|
1164
1164
|
},
|
|
1165
1165
|
"node_modules/chemicaljs": {
|
|
1166
|
-
"version": "1.
|
|
1167
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.
|
|
1168
|
-
"integrity": "sha512-
|
|
1166
|
+
"version": "1.7.1",
|
|
1167
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.7.1.tgz",
|
|
1168
|
+
"integrity": "sha512-UJubi8iIBH6mApXk0gzAHguU8l7tsG44urT9RcrULqSFktoIDgWt1nHfLnLz+HgooUBuiInd63zBRsaUzFFUIw==",
|
|
1169
1169
|
"dependencies": {
|
|
1170
1170
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1171
1171
|
"@mercuryworkshop/epoxy-transport": "^2.1.8",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"chemicaljs": "^1.
|
|
12
|
+
"chemicaljs": "^1.7.1",
|
|
13
13
|
"express": "^4.19.2"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
@@ -1163,9 +1163,9 @@
|
|
|
1163
1163
|
}
|
|
1164
1164
|
},
|
|
1165
1165
|
"node_modules/chemicaljs": {
|
|
1166
|
-
"version": "1.
|
|
1167
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.
|
|
1168
|
-
"integrity": "sha512-
|
|
1166
|
+
"version": "1.7.1",
|
|
1167
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.7.1.tgz",
|
|
1168
|
+
"integrity": "sha512-UJubi8iIBH6mApXk0gzAHguU8l7tsG44urT9RcrULqSFktoIDgWt1nHfLnLz+HgooUBuiInd63zBRsaUzFFUIw==",
|
|
1169
1169
|
"dependencies": {
|
|
1170
1170
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1171
1171
|
"@mercuryworkshop/epoxy-transport": "^2.1.8",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"chemicaljs": "^1.
|
|
12
|
+
"chemicaljs": "^1.7.1",
|
|
13
13
|
"express": "^4.19.2"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
@@ -1163,9 +1163,9 @@
|
|
|
1163
1163
|
}
|
|
1164
1164
|
},
|
|
1165
1165
|
"node_modules/chemicaljs": {
|
|
1166
|
-
"version": "1.
|
|
1167
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.
|
|
1168
|
-
"integrity": "sha512-
|
|
1166
|
+
"version": "1.7.1",
|
|
1167
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.7.1.tgz",
|
|
1168
|
+
"integrity": "sha512-UJubi8iIBH6mApXk0gzAHguU8l7tsG44urT9RcrULqSFktoIDgWt1nHfLnLz+HgooUBuiInd63zBRsaUzFFUIw==",
|
|
1169
1169
|
"dependencies": {
|
|
1170
1170
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1171
1171
|
"@mercuryworkshop/epoxy-transport": "^2.1.8",
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"": {
|
|
7
7
|
"name": "chemical-example-vite",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"chemicaljs": "^1.
|
|
9
|
+
"chemicaljs": "^1.7.1",
|
|
10
10
|
"express": "^4.19.2",
|
|
11
11
|
"preact": "^10.23.2"
|
|
12
12
|
},
|
|
@@ -1726,9 +1726,9 @@
|
|
|
1726
1726
|
}
|
|
1727
1727
|
},
|
|
1728
1728
|
"node_modules/chemicaljs": {
|
|
1729
|
-
"version": "1.
|
|
1730
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.
|
|
1731
|
-
"integrity": "sha512-
|
|
1729
|
+
"version": "1.7.1",
|
|
1730
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.7.1.tgz",
|
|
1731
|
+
"integrity": "sha512-UJubi8iIBH6mApXk0gzAHguU8l7tsG44urT9RcrULqSFktoIDgWt1nHfLnLz+HgooUBuiInd63zBRsaUzFFUIw==",
|
|
1732
1732
|
"dependencies": {
|
|
1733
1733
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1734
1734
|
"@mercuryworkshop/epoxy-transport": "^2.1.8",
|
package/index.js
CHANGED
|
@@ -9,8 +9,7 @@ import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
|
|
|
9
9
|
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
|
|
10
10
|
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
|
|
11
11
|
import { scramjetPath } from "@mercuryworkshop/scramjet";
|
|
12
|
-
import createRammerhead from "rammerhead
|
|
13
|
-
|
|
12
|
+
import { createRammerhead, shouldRouteRh, routeRhUpgrade, routeRhRequest } from "@rubynetwork/rammerhead";
|
|
14
13
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
14
|
|
|
16
15
|
logging.set_level(logging.ERROR)
|
|
@@ -46,42 +45,9 @@ class ChemicalServer {
|
|
|
46
45
|
return [this.app, this.listen]
|
|
47
46
|
}
|
|
48
47
|
serveChemical = () => {
|
|
49
|
-
const rh = createRammerhead(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"/rammerhead.js",
|
|
53
|
-
"/hammerhead.js",
|
|
54
|
-
"/transport-worker.js",
|
|
55
|
-
"/task.js",
|
|
56
|
-
"/iframe-task.js",
|
|
57
|
-
"/worker-hammerhead.js",
|
|
58
|
-
"/messaging",
|
|
59
|
-
"/sessionexists",
|
|
60
|
-
"/deletesession",
|
|
61
|
-
"/newsession",
|
|
62
|
-
"/editsession",
|
|
63
|
-
"/needpassword",
|
|
64
|
-
"/syncLocalStorage",
|
|
65
|
-
"/api/shuffleDict"
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
const rammerheadSession = /^\/[a-z0-9]{32}/
|
|
69
|
-
|
|
70
|
-
const shouldRouteRh = req => {
|
|
71
|
-
const url = new URL(req.url, "http://0.0.0.0")
|
|
72
|
-
return (
|
|
73
|
-
rammerheadScopes.includes(url.pathname) ||
|
|
74
|
-
rammerheadSession.test(url.pathname)
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const routeRhRequest = (req, res) => {
|
|
79
|
-
rh.emit("request", req, res)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const routeRhUpgrade = (req, socket, head) => {
|
|
83
|
-
rh.emit("upgrade", req, socket, head)
|
|
84
|
-
}
|
|
48
|
+
const rh = createRammerhead({
|
|
49
|
+
logLevel: "error",
|
|
50
|
+
});
|
|
85
51
|
|
|
86
52
|
this.app.get("/chemical.js", async (req, res) => {
|
|
87
53
|
let chemicalMain = await readFileSync(resolve(__dirname, "client/chemical.js"), "utf8");
|
|
@@ -101,6 +67,8 @@ class ChemicalServer {
|
|
|
101
67
|
chemicalMain = "const scramjetEnabled = " + String(this.options.scramjet) + ";\n" + chemicalMain
|
|
102
68
|
chemicalMain = "const rammerheadEnabled = " + String(this.options.rammerhead) + ";\n" + chemicalMain
|
|
103
69
|
|
|
70
|
+
chemicalMain = "(async () => {\n" + chemicalMain + "\n})();";
|
|
71
|
+
|
|
104
72
|
res.type("application/javascript");
|
|
105
73
|
return res.send(chemicalMain);
|
|
106
74
|
});
|
|
@@ -128,7 +96,7 @@ class ChemicalServer {
|
|
|
128
96
|
}
|
|
129
97
|
this.server.on("request", (req, res) => {
|
|
130
98
|
if (this.options.rammerhead && shouldRouteRh(req)) {
|
|
131
|
-
routeRhRequest(req, res);
|
|
99
|
+
routeRhRequest(rh, req, res);
|
|
132
100
|
} else {
|
|
133
101
|
this.app(req, res);
|
|
134
102
|
}
|
|
@@ -143,7 +111,7 @@ class ChemicalServer {
|
|
|
143
111
|
}
|
|
144
112
|
wisp.routeRequest(req, socket, head);
|
|
145
113
|
} else if (this.options.rammerhead && shouldRouteRh(req)) {
|
|
146
|
-
routeRhUpgrade(req, socket, head);
|
|
114
|
+
routeRhUpgrade(rh, req, socket, head);
|
|
147
115
|
} else {
|
|
148
116
|
socket.end();
|
|
149
117
|
}
|
|
@@ -178,42 +146,9 @@ const ChemicalVitePlugin = (options) => ({
|
|
|
178
146
|
options.rammerhead = true;
|
|
179
147
|
}
|
|
180
148
|
|
|
181
|
-
const rh = createRammerhead(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
"/rammerhead.js",
|
|
185
|
-
"/hammerhead.js",
|
|
186
|
-
"/transport-worker.js",
|
|
187
|
-
"/task.js",
|
|
188
|
-
"/iframe-task.js",
|
|
189
|
-
"/worker-hammerhead.js",
|
|
190
|
-
"/messaging",
|
|
191
|
-
"/sessionexists",
|
|
192
|
-
"/deletesession",
|
|
193
|
-
"/newsession",
|
|
194
|
-
"/editsession",
|
|
195
|
-
"/needpassword",
|
|
196
|
-
"/syncLocalStorage",
|
|
197
|
-
"/api/shuffleDict"
|
|
198
|
-
]
|
|
199
|
-
|
|
200
|
-
const rammerheadSession = /^\/[a-z0-9]{32}/
|
|
201
|
-
|
|
202
|
-
const shouldRouteRh = req => {
|
|
203
|
-
const url = new URL(req.url, "http://0.0.0.0")
|
|
204
|
-
return (
|
|
205
|
-
rammerheadScopes.includes(url.pathname) ||
|
|
206
|
-
rammerheadSession.test(url.pathname)
|
|
207
|
-
)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const routeRhRequest = (req, res) => {
|
|
211
|
-
rh.emit("request", req, res)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const routeRhUpgrade = (req, socket, head) => {
|
|
215
|
-
rh.emit("upgrade", req, socket, head)
|
|
216
|
-
}
|
|
149
|
+
const rh = createRammerhead({
|
|
150
|
+
logLevel: "error"
|
|
151
|
+
})
|
|
217
152
|
|
|
218
153
|
const app = express();
|
|
219
154
|
app.get("/chemical.js", async function (req, res) {
|
|
@@ -234,6 +169,8 @@ const ChemicalVitePlugin = (options) => ({
|
|
|
234
169
|
chemicalMain = "const scramjetEnabled = " + String(options.scramjet) + ";\n" + chemicalMain
|
|
235
170
|
chemicalMain = "const rammerheadEnabled = " + String(options.rammerhead) + ";\n" + chemicalMain
|
|
236
171
|
|
|
172
|
+
chemicalMain = "(async () => {\n" + chemicalMain + "\n})();";
|
|
173
|
+
|
|
237
174
|
res.type("application/javascript");
|
|
238
175
|
return res.send(chemicalMain);
|
|
239
176
|
});
|
|
@@ -264,7 +201,7 @@ const ChemicalVitePlugin = (options) => ({
|
|
|
264
201
|
|
|
265
202
|
server.middlewares.use((req, res, next) => {
|
|
266
203
|
if (options.rammerhead && shouldRouteRh(req)) {
|
|
267
|
-
routeRhRequest(req, res);
|
|
204
|
+
routeRhRequest(rh, req, res);
|
|
268
205
|
} else {
|
|
269
206
|
next();
|
|
270
207
|
}
|
|
@@ -286,7 +223,7 @@ const ChemicalVitePlugin = (options) => ({
|
|
|
286
223
|
}
|
|
287
224
|
wisp.routeRequest(req, socket, head)
|
|
288
225
|
} else if (options.rammerhead && shouldRouteRh(req)) {
|
|
289
|
-
routeRhUpgrade(req, socket, head)
|
|
226
|
+
routeRhUpgrade(rh, req, socket, head)
|
|
290
227
|
} else {
|
|
291
228
|
for (const upgrader of upgraders) {
|
|
292
229
|
upgrader(req, socket, head)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chemicaljs",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"description": "Easily create your own web proxy with no experience required.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"@mercuryworkshop/libcurl-transport": "^1.3.7",
|
|
17
17
|
"@mercuryworkshop/scramjet": "^1.0.2",
|
|
18
18
|
"@mercuryworkshop/wisp-js": "^0.1.1",
|
|
19
|
+
"@rubynetwork/rammerhead": "^1.3.2",
|
|
19
20
|
"@titaniumnetwork-dev/ultraviolet": "^3.2.7",
|
|
20
|
-
"express": "^4.19.2"
|
|
21
|
-
"rammerhead": "https://github.com/chemicaljs/chemical/raw/main/rammerhead.tgz"
|
|
21
|
+
"express": "^4.19.2"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/rammerhead.tgz
DELETED
|
Binary file
|