randydev commited on
Commit
82ebe5f
·
verified ·
1 Parent(s): 2ef9661

Create utils.js

Browse files
Files changed (1) hide show
  1. lib/snapsave/utils.js +62 -0
lib/snapsave/utils.js ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export function getEncodedSnapSave(data) {
2
+ return data.split('decodeURIComponent(escape(r))}(')[1]
3
+ ?.split('))')[0]
4
+ ?.split(',')
5
+ ?.map(v => v.replace(/"/g, '').trim()) || [];
6
+ }
7
+
8
+ export function getDecodedSnapSave(data) {
9
+ return data.split('getElementById("download-section").innerHTML = "')[1]
10
+ ?.split('"; document.getElementById("inputData").remove(); ')[0]
11
+ ?.replace(/\\(\\)?/g, '') || '';
12
+ }
13
+
14
+ export function decryptSnapSave(data) {
15
+ const args = getEncodedSnapSave(data);
16
+ if (args.length === 0) {
17
+ throw new Error("Failed to extract encoded SnapSave data.");
18
+ }
19
+ const decoded = decodeSnapSave(...args);
20
+ return getDecodedSnapSave(decoded);
21
+ }
22
+
23
+ export function decodeSnapSave(...args) {
24
+ if (args.length < 6) {
25
+ throw new Error("Invalid SnapSave decryption arguments.");
26
+ }
27
+
28
+ let [h, u, n, t, e, r] = args;
29
+
30
+ function decode(d, e, f) {
31
+ const g = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/'.split('');
32
+ let h = g.slice(0, e);
33
+ let i = g.slice(0, f);
34
+
35
+ let j = d.split('').reverse().reduce((a, b, c) => {
36
+ let index = h.indexOf(b);
37
+ return index !== -1 ? a + index * Math.pow(e, c) : a;
38
+ }, 0);
39
+
40
+ let k = '';
41
+ while (j > 0) {
42
+ k = i[j % f] + k;
43
+ j = Math.floor(j / f);
44
+ }
45
+ return k || '0';
46
+ }
47
+
48
+ let r = '';
49
+ for (let i = 0, len = h.length; i < len; i++) {
50
+ let s = "";
51
+ while (h[i] !== n[e]) {
52
+ s += h[i];
53
+ i++;
54
+ }
55
+ for (let j = 0; j < n.length; j++) {
56
+ s = s.replace(new RegExp(n[j], "g"), j.toString());
57
+ }
58
+ r += String.fromCharCode(decode(s, e, 10) - t);
59
+ }
60
+
61
+ return decodeURIComponent(encodeURIComponent(r));
62
+ }