-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
108 lines (93 loc) · 3.9 KB
/
main.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
let requestCounter = 0;
function updateRequestCounter() {
// Display the number of processed requests
document.getElementById("requestCounter").innerText = `Number of Requests Processed: ${requestCounter}`;
}
async function sendReport(sid) {
requestCounter++;
requestCounter++;
updateRequestCounter();
const reportEndpoint = `https://api.shrslink.xyz/report?sid=${sid}`;
const reportPayload = {
filled: 10,
total: 10
};
try {
const reportResponse = await fetch(reportEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Sec-Ch-Ua': '"Not_A Brand";v="8", "Chromium";v="120"',
'Accept': 'application/json, text/plain, */*',
'Sec-Ch-Ua-Mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.199 Safari/537.36',
'Sec-Ch-Ua-Platform': '"Windows"',
'Origin': 'https://shareus.io',
'Sec-Fetch-Site': 'cross-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
},
body: JSON.stringify(reportPayload),
});
if (reportResponse.ok) {
await displayShortcode();
console.log('Report sent successfully');
} else {
console.error('Error sending report:', reportResponse.statusText);
}
} catch (error) {
console.error('Error sending report:', error.message);
}
}
async function displayDestination() {
try {
const sid = document.getElementById("sidInput").value;
const response = await fetch(`https://api.shrslink.xyz/get_link?sid=${sid}`);
const data = await response.json();
const iframeSource = `https://shareus.io/${data.shortid}`;
await sendReport(sid);
// Display link_info in a table format
const iframe = document.createElement("iframe");
iframe.src = iframeSource;
iframe.style.width = "100%";
iframe.style.height = "400px"; // Set the desired height
const urloutput = document.createElement("span");
document.getElementById("urloutput").innerHTML = "";
document.getElementById("urloutput").appendChild(urloutput);
// Display the destination URL as a button
const destinationButton = document.createElement("a");
destinationButton.href = data.link_info.destination;
destinationButton.classList.add("btn");
destinationButton.target = "_blank";
destinationButton.innerHTML = "Open link";
document.getElementById("destinationResult").innerHTML = "";
document.getElementById("destinationResult").appendChild(destinationButton);
// Send report asynchronously
await sendReport(sid);
} catch (error) {
console.error("Error fetching link information from the API:", error.message);
}
}
async function displayShortcode() {
try {
const urlInputValue = "qgCIE8";
const response = await fetch(`https://api.shrslink.xyz/v?shortid=${extractShortcode(urlInputValue)}&initial=true&referrer=`);
const data = await response.json();
// Display the shortcode (sid) from the API response
document.getElementById("sidInput").value = data.sid;
// Trigger displayDestination function
await displayDestination();
} catch (error) {
console.error("Error fetching data from the API:", error.message);
}
}
function extractShortcode(url) {
// Assuming the shortcode is the last part of the URL after the last '/'
const parts = url.split("/");
return parts[parts.length - 1];
}
window.addEventListener('load', function() {
displayShortcode();
});