This repository was archived by the owner on Dec 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsecureFetch.js
More file actions
92 lines (81 loc) · 2.68 KB
/
secureFetch.js
File metadata and controls
92 lines (81 loc) · 2.68 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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Establish connection with Chrome runtime
var port = chrome.runtime.connect({ name: 'rproxport' });
// Function to be executed when window loads
async function onWindowLoad() {
// Find main script URL
let mainScriptUrl = findMainScriptUrl();
// Check if main script URL is found
if (mainScriptUrl !== '') {
// Fetch main script content
let response = await fetch(mainScriptUrl);
let text = await response.text();
// Check if main script content is valid
if (
'9c6d270f3803b30049faad6927e9b0cd3c6325b3a00ec8a20303049f386add4b' ==
(await sha256(text)) ||
text.includes('M 21 13 h -8 v 8 h -3 v -8 H 2 v -3 h 8 V 2 h 3 v 8 h 8 Z')
) {
// Send data to port
sendData(window.location.href);
}
} else {
// Check if certain input placeholder is found
let inputPlaceholder = findInputPlaceholder();
if (
inputPlaceholder ===
"click on 'Create new session ID' or 'Fill in existing session ID' from below"
) {
// Send data to port
sendData(window.location.href);
}
}
}
// Function to find main script URL
function findMainScriptUrl() {
let snapshot = document.evaluate(
'//script',
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
);
let mainScriptUrl = '';
let scriptPattern = /\/static\/js\/main\.[0-9a-z]{1,}\.js/i;
for (let i = 0; i < snapshot.snapshotLength; i++) {
let item = snapshot.snapshotItem(i);
if (
item.attributes.length > 0 &&
item.attributes.src !== null &&
item.attributes.src.value.match(scriptPattern) !== null
) {
mainScriptUrl = item.attributes.src.value;
break;
}
}
return mainScriptUrl;
}
// Function to calculate SHA-256 hash
async function sha256(input) {
const encodedInput = new TextEncoder().encode(input);
const hash = await window.crypto.subtle.digest('SHA-256', encodedInput);
return Array.from(new Uint8Array(hash))
.map((byte) => byte.toString(16).padStart(2, '0'))
.join('');
}
// Function to send data to port
function sendData(url) {
port.postMessage({
action: 'rprox',
data: { url: url },
});
}
// Function to call onWindowLoad with timeout
function callWindowLoadWithTimeout() {
setTimeout(onWindowLoad, 2000);
}
// Add event listener for window load
if (window.addEventListener) {
window.addEventListener('load', callWindowLoadWithTimeout, false);
} else if (window.attachEvent) {
window.attachEvent('onload', callWindowLoadWithTimeout);
}