-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
95 lines (84 loc) · 3.52 KB
/
Copy pathindex.html
File metadata and controls
95 lines (84 loc) · 3.52 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script>
// Runtime asset URL rewriter to prepend basename to root-relative paths
(function() {
const base = '/rcts/c4gtwebsite';
// 1. Intercept setAttribute
const originalSetAttribute = Element.prototype.setAttribute;
Element.prototype.setAttribute = function(name, value) {
if (typeof value === 'string' && value.startsWith('/') && !value.startsWith(base) && !value.startsWith('//')) {
if (name === 'src' || name === 'href') {
value = base + value;
}
}
return originalSetAttribute.call(this, name, value);
};
// 2. Intercept HTMLImageElement.src
const originalSrcDescriptor = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, 'src');
if (originalSrcDescriptor && originalSrcDescriptor.set) {
Object.defineProperty(HTMLImageElement.prototype, 'src', {
get: function() {
return originalSrcDescriptor.get.call(this);
},
set: function(value) {
if (typeof value === 'string' && value.startsWith('/') && !value.startsWith(base) && !value.startsWith('//')) {
value = base + value;
}
originalSrcDescriptor.set.call(this, value);
}
});
}
// 3. Intercept CSSStyleDeclaration.backgroundImage
const originalBgImageDescriptor = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, 'backgroundImage');
if (originalBgImageDescriptor && originalBgImageDescriptor.set) {
Object.defineProperty(CSSStyleDeclaration.prototype, 'backgroundImage', {
get: function() {
return originalBgImageDescriptor.get.call(this);
},
set: function(value) {
if (typeof value === 'string' && value.includes('url(')) {
value = value.replace(/url\((['"]?)([^)]*)\1\)/g, function(match, quote, path) {
if (path.startsWith('/') && !path.startsWith(base) && !path.startsWith('//')) {
return 'url(' + quote + base + path + quote + ')';
}
return match;
});
}
originalBgImageDescriptor.set.call(this, value);
}
});
}
// 4. Intercept fetch
if (typeof window !== 'undefined' && window.fetch) {
const originalFetch = window.fetch;
window.fetch = function(input, init) {
if (typeof input === 'string' && input.startsWith('/') && !input.startsWith(base) && !input.startsWith('//')) {
input = base + input;
}
return originalFetch.call(this, input, init);
};
}
})();
</script>
<!-- Favicon -->
<link rel="icon" type="image/png" href="/logo.png" />
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Raleway:wght@500;600;700&family=Nunito+Sans:wght@400;500;600&display=swap"
rel="stylesheet"
/>
<!-- Responsive -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Browser Tab Title -->
<title>Code for GoodTech</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>