-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudflareExtractor.user.js
More file actions
39 lines (32 loc) · 1.01 KB
/
cloudflareExtractor.user.js
File metadata and controls
39 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const cfParamsRx = /\s*\(\s*function\s*\(\)\s*\{\s*window\s*\[\s*(["'])__CF\$cv\$params\1\s*\]\s*=\s*\{\s*([^}]+)\s*\}\s*\}\s*\)\s*\(\s*\)\s*/i;
const stringRx = /(\w+)\s*:\s*('[^']+'|"[^"]+"),?/g;
const numberRxTextSrc = "(?:0x[\\da-f]+|\\d+)";
const numberArrayRxSrc = "(\\w+)\\s*:\\s*\\[((?:\\s*" + numberRxTextSrc + "\\s*,\\s*)+" + numberRxTextSrc + "?\\s*)\\]";
const numberArrayRx = new RegExp(numberArrayRxSrc);
function parseCloudFlareParams() {
let res = [];
for (let el of document.getElementsByTagName("SCRIPT")) {
if (el.src) {
continue;
}
let t = el.textContent;
let m = t.match(cfParamsRx);
if (m) {
m = m[2];
console.log(m);
let thisScriptRes = new Map();
m.replace(stringRx, (whole, k, v) => {
v = JSON.parse(v.replace(/'/g, '"'));
thisScriptRes.set(k, v);
return "";
});
m.replace(numberArrayRx, (whole, k, v) => {
v = v.split(",").map(v => parseInt(v.trim()));
thisScriptRes.set(k, v);
return "";
});
res.push(thisScriptRes);
}
}
return res;
}