-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
60 lines (53 loc) · 2.19 KB
/
index.html
File metadata and controls
60 lines (53 loc) · 2.19 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Result page</title>
</head>
<body>
<div id="content"></div>
<script>
// Parses URL parameters and updates the page accordingly.
function updatePageContentFromUrlParameters() {
// Decode the 'content' parameter from hex to readable text and update the page content.
const contentParameter = getDecodedUrlParameter('content', true);
updatePageContent(contentParameter);
// Extract and set the 'title' parameter as the page title if it exists.
const pageTitle = getDecodedUrlParameter('title', false);
if (pageTitle) {
document.title = pageTitle;
}
}
// Retrieves and decodes a specified URL parameter.
// 'isTitle' is a boolean indicating whether decoding is for the title (true) or content (false).
function getDecodedUrlParameter(paramName, encoded = false) {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const paramValue = urlParams.get(paramName);
if (!paramValue) return null;
return encoded ? hex2a(paramValue) : decodeURIComponent(paramValue);
}
// Decodes a hex string to a UTF-8 string.
function hex2a(hexx) {
var hex = hexx.toString();//force conversion
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
// Updates the page content with the decoded string or shows an example if no content is provided.
function updatePageContent(decodedContent) {
const contentElement = document.getElementById('content');
if (decodedContent) {
contentElement.innerHTML = decodedContent;
} else {
const exampleUrl = `${window.location.origin}${window.location.pathname}?title=Custom%20title&content=48656c6c6f2c2074686973206973206578616d706c6520636f6e74656e74`;
contentElement.innerHTML = 'No content provided. Click here for an example: <a href="' + exampleUrl + '">' + exampleUrl + '</a>';
}
}
// Initialize page content update when the page loads.
window.onload = updatePageContentFromUrlParameters;
</script>
</body>
</html>