Update main.py
Browse files
main.py
CHANGED
@@ -90,29 +90,11 @@ def proxy(path):
|
|
90 |
|
91 |
# Check if response is HTML and filter content if needed
|
92 |
content_type = resp.headers.get('Content-Type', '')
|
93 |
-
if 'text/html' in content_type
|
94 |
-
# Try to determine the correct encoding
|
95 |
-
encoding = resp.encoding or 'utf-8'
|
96 |
-
try:
|
97 |
-
html_content = resp.content.decode(encoding, errors='ignore')
|
98 |
-
except UnicodeDecodeError:
|
99 |
-
html_content = resp.content.decode('utf-8', errors='ignore')
|
100 |
# Parse HTML content
|
|
|
101 |
soup = BeautifulSoup(html_content, 'html.parser')
|
102 |
|
103 |
-
# Ensure basic HTML structure exists
|
104 |
-
if not soup.html:
|
105 |
-
html_tag = soup.new_tag('html')
|
106 |
-
soup.append(html_tag)
|
107 |
-
|
108 |
-
if not soup.html.head:
|
109 |
-
head_tag = soup.new_tag('head')
|
110 |
-
soup.html.insert(0, head_tag)
|
111 |
-
|
112 |
-
if not soup.html.body:
|
113 |
-
body_tag = soup.new_tag('body')
|
114 |
-
soup.html.append(body_tag)
|
115 |
-
|
116 |
# Filter out "Полная версия ETKA"
|
117 |
for element in soup.find_all(string=re.compile('Полная версия ETKA')):
|
118 |
# Replace the text with empty string
|
@@ -154,115 +136,6 @@ def proxy(path):
|
|
154 |
button['style'] = 'display: inline-block; margin: 10px; padding: 8px 15px; background-color: #4a90e2; border: none; border-radius: 4px; text-decoration: none; color: white; font-weight: 500; transition: all 0.3s ease; box-shadow: 0 2px 4px rgba(0,0,0,0.1);'
|
155 |
img.insert_after(button)
|
156 |
|
157 |
-
# Add theme toggle button
|
158 |
-
theme_toggle = soup.new_tag('button')
|
159 |
-
theme_toggle['id'] = 'themeToggle'
|
160 |
-
theme_toggle['style'] = 'position: fixed; top: 20px; right: 20px; padding: 10px; border-radius: 50%; width: 40px; height: 40px; border: none; cursor: pointer; z-index: 1000; transition: all 0.3s ease; display: flex; align-items: center; justify-content: center;'
|
161 |
-
theme_toggle.string = '🌓'
|
162 |
-
if soup.body:
|
163 |
-
soup.body.insert(0, theme_toggle)
|
164 |
-
|
165 |
-
# Add theme styles
|
166 |
-
style_tag = soup.new_tag('style')
|
167 |
-
style_tag.string = '''
|
168 |
-
:root {
|
169 |
-
--bg-color: #ffffff;
|
170 |
-
--text-color: #333333;
|
171 |
-
--link-color: #4a90e2;
|
172 |
-
--border-color: #ddd;
|
173 |
-
--shadow-color: rgba(0,0,0,0.1);
|
174 |
-
--button-bg: #4a90e2;
|
175 |
-
--button-text: white;
|
176 |
-
--modal-bg: rgba(0,0,0,0.8);
|
177 |
-
}
|
178 |
-
|
179 |
-
[data-theme="dark"] {
|
180 |
-
--bg-color: #1a1a1a;
|
181 |
-
--text-color: #e0e0e0;
|
182 |
-
--link-color: #66b3ff;
|
183 |
-
--border-color: #404040;
|
184 |
-
--shadow-color: rgba(0,0,0,0.3);
|
185 |
-
--button-bg: #2d5a8c;
|
186 |
-
--button-text: #ffffff;
|
187 |
-
--modal-bg: rgba(0,0,0,0.9);
|
188 |
-
}
|
189 |
-
|
190 |
-
body {
|
191 |
-
background-color: var(--bg-color);
|
192 |
-
color: var(--text-color);
|
193 |
-
transition: all 0.3s ease;
|
194 |
-
}
|
195 |
-
|
196 |
-
a {
|
197 |
-
color: var(--link-color);
|
198 |
-
}
|
199 |
-
|
200 |
-
img {
|
201 |
-
border-color: var(--border-color) !important;
|
202 |
-
box-shadow: 0 2px 4px var(--shadow-color) !important;
|
203 |
-
}
|
204 |
-
|
205 |
-
.open-image-btn {
|
206 |
-
background-color: var(--button-bg) !important;
|
207 |
-
color: var(--button-text) !important;
|
208 |
-
}
|
209 |
-
|
210 |
-
#themeToggle {
|
211 |
-
background-color: var(--bg-color);
|
212 |
-
color: var(--text-color);
|
213 |
-
box-shadow: 0 2px 4px var(--shadow-color);
|
214 |
-
}
|
215 |
-
|
216 |
-
.modal {
|
217 |
-
background-color: var(--modal-bg);
|
218 |
-
}
|
219 |
-
|
220 |
-
.zoom-controls button {
|
221 |
-
background-color: var(--button-bg);
|
222 |
-
color: var(--button-text);
|
223 |
-
border: 1px solid var(--border-color);
|
224 |
-
}
|
225 |
-
'''
|
226 |
-
if soup.head:
|
227 |
-
soup.head.append(style_tag)
|
228 |
-
else:
|
229 |
-
head_tag = soup.new_tag('head')
|
230 |
-
head_tag.append(style_tag)
|
231 |
-
if soup.html:
|
232 |
-
soup.html.insert(0, head_tag)
|
233 |
-
else:
|
234 |
-
html_tag = soup.new_tag('html')
|
235 |
-
html_tag.append(head_tag)
|
236 |
-
soup.append(html_tag)
|
237 |
-
|
238 |
-
# Add JavaScript for theme toggle
|
239 |
-
script_tag = soup.new_tag('script')
|
240 |
-
script_tag.string = '''
|
241 |
-
document.addEventListener('DOMContentLoaded', function() {
|
242 |
-
const themeToggle = document.getElementById('themeToggle');
|
243 |
-
const savedTheme = localStorage.getItem('theme');
|
244 |
-
|
245 |
-
if (savedTheme === 'dark') {
|
246 |
-
document.documentElement.setAttribute('data-theme', 'dark');
|
247 |
-
}
|
248 |
-
|
249 |
-
themeToggle.addEventListener('click', function() {
|
250 |
-
const currentTheme = document.documentElement.getAttribute('data-theme');
|
251 |
-
const newTheme = currentTheme === 'dark' ? null : 'dark';
|
252 |
-
|
253 |
-
if (newTheme) {
|
254 |
-
document.documentElement.setAttribute('data-theme', newTheme);
|
255 |
-
localStorage.setItem('theme', newTheme);
|
256 |
-
} else {
|
257 |
-
document.documentElement.removeAttribute('data-theme');
|
258 |
-
localStorage.removeItem('theme');
|
259 |
-
}
|
260 |
-
});
|
261 |
-
});
|
262 |
-
'''
|
263 |
-
if soup.body:
|
264 |
-
soup.body.append(script_tag)
|
265 |
-
|
266 |
# Add modal container for fullscreen image view
|
267 |
modal_div = soup.new_tag('div')
|
268 |
modal_div['id'] = 'imageModal'
|
|
|
90 |
|
91 |
# Check if response is HTML and filter content if needed
|
92 |
content_type = resp.headers.get('Content-Type', '')
|
93 |
+
if 'text/html' in content_type:
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
# Parse HTML content
|
95 |
+
html_content = resp.content.decode('utf-8', errors='ignore')
|
96 |
soup = BeautifulSoup(html_content, 'html.parser')
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
# Filter out "Полная версия ETKA"
|
99 |
for element in soup.find_all(string=re.compile('Полная версия ETKA')):
|
100 |
# Replace the text with empty string
|
|
|
136 |
button['style'] = 'display: inline-block; margin: 10px; padding: 8px 15px; background-color: #4a90e2; border: none; border-radius: 4px; text-decoration: none; color: white; font-weight: 500; transition: all 0.3s ease; box-shadow: 0 2px 4px rgba(0,0,0,0.1);'
|
137 |
img.insert_after(button)
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
# Add modal container for fullscreen image view
|
140 |
modal_div = soup.new_tag('div')
|
141 |
modal_div['id'] = 'imageModal'
|