AstraOS commited on
Commit
6636e90
·
verified ·
1 Parent(s): d1b2d13

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +67 -90
index.html CHANGED
@@ -2,125 +2,102 @@
2
  <html lang="en">
3
  <head>
4
  <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>Custom Embed for Gamma Site</title>
7
  <style>
8
  html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
9
  #custom-iframe { width: 100%; height: 100%; border: none; }
10
  </style>
11
  </head>
12
  <body>
13
- <iframe id="custom-iframe" sandbox="allow-scripts allow-same-origin"></iframe>
14
  <script>
15
  (async function() {
16
  const targetUrl = 'https://akshay-365-9vx6m3k.gamma.site/';
17
  const proxyUrl = `https://embed-proxy-prod.gamma-app.workers.dev/?alt_url=${targetUrl}`;
18
 
19
  try {
20
- console.log('Fetching proxy URL:', proxyUrl);
21
- const res = await fetch(proxyUrl, { mode: 'cors' });
22
- if (!res.ok) {
23
- const errorText = await res.text().catch(() => 'No response text');
24
- throw new Error(`Fetch failed with status ${res.status}: ${errorText}`);
25
- }
 
 
 
26
  let html = await res.text();
27
- console.log('Fetched HTML length:', html.length);
28
 
29
- // Injection payload: custom script to hide elements
30
- const scriptContent = `
31
- (function() {
32
- try {
33
- console.log('Custom embed script loaded in iframe');
34
-
35
- const SELECTORS = [
36
- '.css-1c6hcbi',
37
- '.chakra-button__group.css-1ayoy1w'
38
- ];
39
-
40
- function hideTargets(root = document) {
41
- // Make sure root is an Element or Document before calling querySelectorAll
42
- if (root.querySelectorAll) {
43
- SELECTORS.forEach(selector => {
44
- root.querySelectorAll(selector).forEach(el => {
45
- console.log('Hiding element:', el);
46
- el.style.display = 'none';
47
- });
48
- });
49
  }
50
- }
51
 
52
- function setupObserver() {
53
- if (!document.body) {
54
- console.warn('Body not ready, retrying in 100ms...');
55
- return setTimeout(setupObserver, 100);
56
- }
57
-
58
- hideTargets();
59
-
60
- const observer = new MutationObserver(mutations => {
61
- for (const mutation of mutations) {
62
- if (mutation.type === 'childList') {
63
- mutation.addedNodes.forEach(node => {
64
- if (node.nodeType === Node.ELEMENT_NODE) {
65
- hideTargets(node);
66
- }
67
- });
68
- } else if (mutation.type === 'attributes') {
69
- if (mutation.target.matches(SELECTORS.join(','))) {
70
- console.log('Hiding updated element:', mutation.target);
71
- mutation.target.style.display = 'none';
72
  }
73
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  }
75
- });
76
-
77
- observer.observe(document.body, {
78
- childList: true,
79
- subtree: true,
80
- attributes: true,
81
- attributeFilter: ['class']
82
- });
83
-
84
- console.log('MutationObserver set up!');
85
- }
86
 
87
- if (document.readyState === 'complete' || document.readyState === 'interactive') {
88
- setupObserver();
89
- } else {
90
- document.addEventListener('DOMContentLoaded', setupObserver);
91
- }
92
- } catch (err) {
93
- console.error('Error in injected script:', err);
94
- }
95
- })();
96
- `;
97
-
98
- const injection = `<script>${scriptContent}<\/script>`;
99
-
100
- // Inject script into <head> to avoid breaking body scripts
101
- if (html.includes('</head>')) {
102
  html = html.replace(/<\/head>/i, injection + '</head>');
103
  } else {
104
- console.warn('No </head> tag found, prepending script');
105
  html = injection + html;
106
  }
107
 
108
- // Create Blob for same-origin iframe
109
  const blob = new Blob([html], { type: 'text/html' });
110
- const blobUrl = URL.createObjectURL(blob);
111
-
112
  const iframe = document.getElementById('custom-iframe');
113
- iframe.src = blobUrl;
114
-
115
- // Clean up Blob URL after load
116
- iframe.onload = () => {
117
- console.log('Iframe loaded');
118
- URL.revokeObjectURL(blobUrl);
119
- };
120
 
121
  } catch (err) {
122
- console.error('Error in fetch or injection:', err);
123
- document.body.innerHTML = `<p style="color:red;">Error loading content: ${err.message}</p>`;
124
  }
125
  })();
126
  </script>
 
2
  <html lang="en">
3
  <head>
4
  <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1"><!-- your own page remains responsive -->
6
+ <title>Responsive Gamma Embed</title>
7
  <style>
8
  html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
9
  #custom-iframe { width: 100%; height: 100%; border: none; }
10
  </style>
11
  </head>
12
  <body>
13
+ <iframe id="custom-iframe" sandbox="allow-scripts allow-same-origin allow-top-navigation-by-user-activation allow-popups"></iframe>
14
  <script>
15
  (async function() {
16
  const targetUrl = 'https://akshay-365-9vx6m3k.gamma.site/';
17
  const proxyUrl = `https://embed-proxy-prod.gamma-app.workers.dev/?alt_url=${targetUrl}`;
18
 
19
  try {
20
+ // forward your UA so SSR can pick mobile vs desktop
21
+ const res = await fetch(proxyUrl, {
22
+ mode: 'cors',
23
+ headers: {
24
+ 'Accept': 'text/html',
25
+ 'User-Agent': navigator.userAgent
26
+ }
27
+ });
28
+ if (!res.ok) throw new Error(`Status ${res.status}`);
29
  let html = await res.text();
 
30
 
31
+ // --- 1) Inject viewport meta if missing ---
32
+ if (!/<meta\s+name=["']viewport["']/i.test(html)) {
33
+ html = html.replace(
34
+ /<head([^>]*)>/i,
35
+ headTag => headTag +
36
+ '\n <meta name="viewport" content="width=device-width, initial-scale=1">\n'
37
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
 
39
 
40
+ // --- 2) Inject your hide-elements script ---
41
+ const scriptContent = `
42
+ (function() {
43
+ try {
44
+ const SELECTORS = [
45
+ '.css-1c6hcbi',
46
+ '.chakra-button__group.css-1ayoy1w'
47
+ ];
48
+ function hideTargets(root = document) {
49
+ if (root.querySelectorAll) {
50
+ SELECTORS.forEach(sel => {
51
+ root.querySelectorAll(sel).forEach(el => el.style.display = 'none');
52
+ });
 
 
 
 
 
 
 
53
  }
54
  }
55
+ function setup() {
56
+ if (!document.body) return setTimeout(setup, 100);
57
+ hideTargets();
58
+ new MutationObserver(muts => {
59
+ muts.forEach(m => {
60
+ if (m.type === 'childList') {
61
+ m.addedNodes.forEach(n => {
62
+ if (n.nodeType === Node.ELEMENT_NODE) hideTargets(n);
63
+ });
64
+ } else if (m.type === 'attributes' && m.target.matches(SELECTORS.join(','))) {
65
+ m.target.style.display = 'none';
66
+ }
67
+ });
68
+ }).observe(document.body, {
69
+ childList: true,
70
+ subtree: true,
71
+ attributes: true,
72
+ attributeFilter: ['class']
73
+ });
74
+ }
75
+ if (document.readyState !== 'loading') setup();
76
+ else document.addEventListener('DOMContentLoaded', setup);
77
+ } catch (e) {
78
+ console.error('Injected script error:', e);
79
  }
80
+ })();
81
+ `;
82
+ const injection = `<script>${scriptContent}<\/script>`;
 
 
 
 
 
 
 
 
83
 
84
+ // add before </head> so responsive CSS & your script both load early
85
+ if (html.match(/<\/head>/i)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  html = html.replace(/<\/head>/i, injection + '</head>');
87
  } else {
 
88
  html = injection + html;
89
  }
90
 
91
+ // serve via blob so same-origin + your script can run
92
  const blob = new Blob([html], { type: 'text/html' });
93
+ const url = URL.createObjectURL(blob);
 
94
  const iframe = document.getElementById('custom-iframe');
95
+ iframe.src = url;
96
+ iframe.onload = () => URL.revokeObjectURL(url);
 
 
 
 
 
97
 
98
  } catch (err) {
99
+ console.error('Embed error:', err);
100
+ document.body.innerHTML = `<p style="color:red;">Error loading embed: ${err.message}</p>`;
101
  }
102
  })();
103
  </script>