Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
153 lines (132 loc) · 5.54 KB
/
Copy pathindex.html
File metadata and controls
153 lines (132 loc) · 5.54 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
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
151
152
153
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>UV Proxy Demo</title>
<script>console.log("🔍 Attempting to load Ultraviolet scripts…");</script>
<!-- Load UV runtime + config (client-side encoder) -->
<script
src="https://cdn.jsdelivr.net/npm/@titaniumnetwork-dev/ultraviolet/dist/uv.bundle.js"
onload="console.log('✅ uv.bundle.js loaded')"
onerror="console.error('❌ Failed to load uv.bundle.js')">
</script>
<script
src="https://cdn.jsdelivr.net/npm/@titaniumnetwork-dev/ultraviolet/dist/uv.config.js"
onload="console.log('✅ uv.config.js loaded')"
onerror="console.error('❌ Failed to load uv.config.js')">
</script>
<script>
window.addEventListener("DOMContentLoaded", () => {
console.log("📦 DOM ready — checking __uv$config...");
if (typeof __uv$config !== "undefined") {
console.log("✅ __uv$config detected:", __uv$config);
} else {
console.error("❌ __uv$config missing! Ultraviolet config failed.");
}
});
</script>
</head>
<body>
<div id="proxy-content">Loading…</div>
<script>
// Wait until UV config is defined
window.addEventListener("load", () => {
if (typeof __uv$config === "undefined") {
console.error("Ultraviolet config failed to load!");
document.getElementById("proxy-content").innerText =
"Error: Ultraviolet config not found.";
return;
}
// Your deployed UV server base
const UV_SERVER = "https://ultraviolet-app-ebon-nu.vercel.app";
const TARGET_ORIGIN = "https://coldnova.xyz"; // site you want to proxy
const contentDiv = document.getElementById("proxy-content");
let currentPath = "/";
// Encode a full URL to route through UV server
function uvEncode(url) {
try {
const encoded = UV_SERVER + __uv$config.prefix + __uv$config.encodeUrl(url);
console.log("🔗 Encoding URL:", url, "→", encoded);
return encoded;
} catch (err) {
console.error("❌ uvEncode failed for", url, err);
return url;
}
}
async function fetchAndRender(path) {
currentPath = path;
const proxiedUrl = uvEncode(TARGET_ORIGIN + path);
console.log("🌐 Fetching proxied URL:", proxiedUrl);
try {
const resp = await fetch(proxiedUrl, { credentials: "omit" });
console.log("📥 Response status:", resp.status);
if (!resp.ok) throw new Error("Failed to fetch via UV server");
let html = await resp.text();
console.log("📄 Fetched HTML length:", html.length);
const { bodyHTML, headElements } = rewriteDocument(html, TARGET_ORIGIN);
contentDiv.innerHTML = bodyHTML;
updateHead(headElements);
interceptLinks();
} catch (e) {
console.error("❌ fetchAndRender error:", e);
contentDiv.innerHTML = `<div style="color:red;padding:2em;">Failed to load: ${e.message}</div>`;
}
}
function rewriteDocument(html, baseUrl) {
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
const nodes = doc.querySelectorAll("[href], [src], iframe, embed, object");
console.log("🔧 Rewriting", nodes.length, "nodes");
nodes.forEach((el) => {
const tag = el.tagName.toLowerCase();
if (el.hasAttribute("href")) {
const newHref = new URL(el.getAttribute("href"), baseUrl).href;
el.setAttribute("href", uvEncode(newHref));
}
if (el.hasAttribute("src")) {
const newSrc = new URL(el.getAttribute("src"), baseUrl).href;
el.setAttribute("src", uvEncode(newSrc));
}
if (tag === "embed" && el.getAttribute("src")) {
const originalSrc = new URL(el.getAttribute("src"), baseUrl).href;
const div = document.createElement("div");
div.className = "embed-container";
div.dataset.src = uvEncode(originalSrc);
div.textContent = `Embed proxied: ${originalSrc}`;
el.replaceWith(div);
}
});
return {
bodyHTML: doc.body.innerHTML,
headElements: [...doc.head.children],
};
}
function updateHead(newHeadElements) {
const head = document.head;
head.querySelectorAll("[data-proxy-head]").forEach((el) => el.remove());
newHeadElements.forEach((el) => {
const clone = el.cloneNode(true);
clone.setAttribute("data-proxy-head", "");
if (clone.href) clone.href = uvEncode(clone.href);
if (clone.src) clone.src = uvEncode(clone.src);
head.appendChild(clone);
});
console.log("🧩 Updated head with", newHeadElements.length, "elements");
}
function interceptLinks() {
contentDiv.querySelectorAll("a[href]").forEach((a) => {
a.addEventListener("click", (e) => {
e.preventDefault();
let href = a.getAttribute("href");
if (!href) return;
console.log("🖱️ Intercepted link click:", href);
fetchAndRender(new URL(href, TARGET_ORIGIN).pathname);
});
});
}
// Initial load
fetchAndRender("/");
});
</script>
</body>
</html>