Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,34 +19,52 @@ with open('styles.css', 'r', encoding='utf-8') as file:
|
|
| 19 |
with open('scripts.js', 'r', encoding='utf-8') as file:
|
| 20 |
scripts = """
|
| 21 |
async () => {
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
observer.disconnect();
|
| 36 |
-
return;
|
| 37 |
}
|
| 38 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
-
});
|
| 41 |
-
|
| 42 |
-
observer.observe(document.body, { childList: true, subtree: true });
|
| 43 |
}
|
| 44 |
-
|
| 45 |
-
waitForElementById('cheatsheets_json', (root_element) => {
|
| 46 |
-
%s
|
| 47 |
-
});
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
""" % (file.read())
|
| 51 |
|
| 52 |
@tool
|
|
@@ -56,10 +74,6 @@ def json_string_to_poster(json_string:str)-> str:
|
|
| 56 |
json_string: stringified json data
|
| 57 |
"""
|
| 58 |
|
| 59 |
-
#html_template = cheatsheet_template.replace('%cheatsheet%', json_string)
|
| 60 |
-
|
| 61 |
-
#return html_template
|
| 62 |
-
|
| 63 |
return f"""
|
| 64 |
<div id="root"></div>
|
| 65 |
<div id="cheatsheets_json" style="display: none;">{repair_json(json_string)}</div>
|
|
|
|
| 19 |
with open('scripts.js', 'r', encoding='utf-8') as file:
|
| 20 |
scripts = """
|
| 21 |
async () => {
|
| 22 |
+
const handleCheatsheetsJsonChange = (root_element) => {
|
| 23 |
+
%s
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
function observeCheatsheetsJson() {
|
| 27 |
+
const cheatsheetsJsonElement = document.getElementById('cheatsheets_json');
|
| 28 |
+
|
| 29 |
+
if (cheatsheetsJsonElement) {
|
| 30 |
+
const observer = new MutationObserver((mutationsList) => {
|
| 31 |
+
for (const mutation of mutationsList) {
|
| 32 |
+
if (mutation.type === 'childList' || mutation.type === 'characterData') {
|
| 33 |
+
handleCheatsheetsJsonChange();
|
| 34 |
+
}
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
observer.observe(cheatsheetsJsonElement, {
|
| 39 |
+
childList: true,
|
| 40 |
+
characterData: true,
|
| 41 |
+
subtree: true,
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
handleCheatsheetsJsonChange();
|
| 45 |
+
} else {
|
| 46 |
+
const observer = new MutationObserver((mutationsList, observer) => {
|
| 47 |
+
for (const mutation of mutationsList) {
|
| 48 |
+
if (mutation.type === 'childList') {
|
| 49 |
+
const cheatsheetsJsonElement = document.getElementById('cheatsheets_json');
|
| 50 |
+
if (cheatsheetsJsonElement) {
|
| 51 |
+
observer.disconnect();
|
| 52 |
+
observeCheatsheetsJson();
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
});
|
| 57 |
+
|
| 58 |
+
observer.observe(document.body, {
|
| 59 |
+
childList: true,
|
| 60 |
+
subtree: true,
|
| 61 |
+
});
|
| 62 |
}
|
|
|
|
|
|
|
|
|
|
| 63 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
observeCheatsheetsJson();
|
| 66 |
+
|
| 67 |
+
}
|
| 68 |
""" % (file.read())
|
| 69 |
|
| 70 |
@tool
|
|
|
|
| 74 |
json_string: stringified json data
|
| 75 |
"""
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
return f"""
|
| 78 |
<div id="root"></div>
|
| 79 |
<div id="cheatsheets_json" style="display: none;">{repair_json(json_string)}</div>
|