-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpython.js
64 lines (58 loc) · 2.23 KB
/
python.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
async function convertPyToJs(code) {
const sanitizedCode = code.replaceAll('"', '\"');
const response = await fetch("https://api.extendsclass.com/convert/python/es6", {
method: "POST",
headers: { "Content-Type": "text/plain;charset=UTF-8", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", },
referrer: "https://extendsclass.com/",
referrerPolicy: "strict-origin-when-cross-origin",
body: sanitizedCode,
mode: "cors",
credentials: "omit",
});
if (response.ok) {
const data = await response.json();
return data.stdout
} else { console.error("Error fetching data:", response.status, response.statusText); }
}
async function loadDataFromFile(onlinePath) {
var response = await fetch(onlinePath, {
"headers": {
"accept": "*/*",
"accept-language": "fr,en;q=0.9,hmn;q=0.8,nl;q=0.7",
"content-type": "text/plain;charset=UTF-8",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site"
},
"referrerPolicy": "strict-origin-when-cross-origin",
"method": "GET",
"mode": "cors",
"credentials": "omit"
});
if (response.ok) {
const data = await response.text();
return data
} else { console.error("Error fetching data:", response.status, response.statusText); }
}
async function loadPYFromFile(path) {
var path = '/python/' + path
var data = await loadDataFromFile(path)
return await convertPyToJs(data)
}
function fixJS(code) {
code = code.replace(/from\s+'(\w+)'/g, "from 'https://ic-hat.geoloup.com/$1.js'");
code = code.replace(/apifrdrr.(\w+)\(\)/g, " await bhuy3huygyufwyuge.$1()");
return code;
}
async function ImportPY(filepath) {
var myText = await loadPYFromFile(filepath);
var myText = fixJS(myText)
const blob = new Blob([myText], { type: 'text/javascript' });
const blobUrl = URL.createObjectURL(blob);
const scriptElement = document.createElement('script');
scriptElement.type = 'module'
scriptElement.async = true
scriptElement.src = blobUrl;
document.head.appendChild(scriptElement);
}
ImportPY('convert.py')