-
Notifications
You must be signed in to change notification settings - Fork 2
/
beta.ct
150 lines (122 loc) · 5.26 KB
/
beta.ct
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Shortener</title>
</head>
<body>
<form id="urlForm">
<label for="urlInput">Enter URL:</label>
<input type="text" id="urlInput" required>
<button type="button" onclick="handleSubmit()">Submit</button>
</form>
<input type="text" id="sidInput" readonly>
<div id="destinationResult"></div>
<script>
let requestCounter = 0;
function updateRequestCounter() {
// Display the number of processed requests
document.getElementById("requestCounter").innerText = `Number of Requests Processed: ${requestCounter}`;
}
async function sendReport(sidid) {
requestCounter++;
requestCounter++;
updateRequestCounter();
const reportEndpoint = `https://api.shrslink.xyz/report?sid=${sidid}`;
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) {
console.log('Report sent successfully');
} else {
console.error('Error sending report:', reportResponse.statusText);
}
} catch (error) {
console.error('Error sending report:', error.message);
}
}
// Step 1: Extract Shortcode from URL
function extractShortcode(url) {
const parts = url.split("/");
return parts[parts.length - 1];
}
// Step 2: Display Shortcode
async function displayShortcode(urlInputValue) {
const response = await fetch(`https://api.shrslink.xyz/v?shortid=${extractShortcode(urlInputValue)}&initial=true&referrer=`);
const data = await response.json();
document.getElementById("sidInput").value = data.sid;
await displayDestination();
}
// Step 3: Display Destination
async function displayDestination() {
const sidid = document.getElementById("sidInput").value;
const response = await fetch(`https://api.shrslink.xyz/get_link?sid=${sidid}`);
const data = await response.json();
const directurl = data.link_info.destination;
await createFromApi(directurl);
await sendReport(sidid);
}
// Step 4: Create from API
async function createFromApi(directurl) {
const apiUrl = await fetch(`https://api.shareus.io/easy_api?key=apikey&link=${directurl}`);
const response = await apiUrl.text();
await newShorten(response);
}
// Step 5: New Shorten
async function newShorten(newShortcode) {
const response = await fetch(`https://api.shrslink.xyz/v?shortid=${extractnewShortcode(newShortcode)}&initial=true&referrer=`);
const data = await response.json();
document.getElementById("sidInput").value = data.sid;
const sidid3 = document.getElementById("sidInput").value;
await displayNewDestination();
await sendReport(sidid3);
}
// Helper function to extract new Shortcode
function extractnewShortcode(response) {
// Assuming the shortcode is the last part of the URL after the last '/'
const parts = response.split("/");
return parts[parts.length - 1];
}
// Step 6: Display New Destination
async function displayNewDestination() {
const sid = document.getElementById("sidInput").value;
const response = await fetch(`https://api.shrslink.xyz/get_link?sid=${sid}`);
const data = await response.json();
const directurl = data.link_info.destination;
const destinationButton = document.createElement("a");
destinationButton.href = directurl;
destinationButton.classList.add("btn");
destinationButton.target = "_blank";
destinationButton.innerHTML = "Open link";
document.getElementById("destinationResult").innerHTML = "";
document.getElementById("destinationResult").appendChild(destinationButton);
}
// Function to handle form submission
function handleSubmit() {
const urlInputValue = document.getElementById("urlInput").value;
displayShortcode(urlInputValue);
}
</script>
</body>
</html>