Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,10 +18,45 @@ with open('index.html', 'r', encoding='utf-8') as file:
|
|
| 18 |
|
| 19 |
scripts = """
|
| 20 |
async () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
console.log('Running script');
|
| 22 |
const json_obj = JSON.parse(document.getElementById("root").innerHTML);
|
| 23 |
console.log(json_obj)
|
| 24 |
document.getElementById("root").innerHTML += 'Hello!'
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
"""
|
| 27 |
|
|
|
|
| 18 |
|
| 19 |
scripts = """
|
| 20 |
async () => {
|
| 21 |
+
function waitForElementById(id, callback) {
|
| 22 |
+
// Проверяем, существует ли элемент уже на странице
|
| 23 |
+
const element = document.getElementById(id);
|
| 24 |
+
if (element) {
|
| 25 |
+
callback(element);
|
| 26 |
+
return;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// Создаем наблюдатель за изменениями в DOM
|
| 30 |
+
const observer = new MutationObserver((mutationsList, observer) => {
|
| 31 |
+
// Проверяем каждый мутацию
|
| 32 |
+
for (let mutation of mutationsList) {
|
| 33 |
+
if (mutation.type === 'childList') {
|
| 34 |
+
// Проверяем, появился ли нужный элемент
|
| 35 |
+
const element = document.getElementById(id);
|
| 36 |
+
if (element) {
|
| 37 |
+
// Вызываем callback и прекращаем наблюдение
|
| 38 |
+
callback(element);
|
| 39 |
+
observer.disconnect();
|
| 40 |
+
return;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
});
|
| 45 |
+
|
| 46 |
+
// Начинаем наблюдение за изменениями в DOM
|
| 47 |
+
observer.observe(document.body, { childList: true, subtree: true });
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
waitForElementById('root', (element) => {
|
| 52 |
+
console.log('Элемент найден:', element);
|
| 53 |
console.log('Running script');
|
| 54 |
const json_obj = JSON.parse(document.getElementById("root").innerHTML);
|
| 55 |
console.log(json_obj)
|
| 56 |
document.getElementById("root").innerHTML += 'Hello!'
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
|
| 60 |
}
|
| 61 |
"""
|
| 62 |
|