Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,7 +140,7 @@ def parse_metadata_hash(metadata_html):
|
|
| 140 |
def verification_js():
|
| 141 |
return """
|
| 142 |
<script>
|
| 143 |
-
function
|
| 144 |
const citationInput = document.getElementById('citation_input');
|
| 145 |
const hashInput = document.getElementById('hash_input');
|
| 146 |
const citationOutput = document.getElementById('citation_output');
|
|
@@ -150,19 +150,29 @@ def verification_js():
|
|
| 150 |
const citationLink = citationInput.getElementsByTagName('a')[0];
|
| 151 |
const hashLink = hashInput.getElementsByTagName('a')[0];
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
} else {
|
| 156 |
-
citationOutput.value = '';
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
if (hashLink) {
|
| 160 |
-
hashOutput.value = hashLink.outerHTML;
|
| 161 |
-
} else {
|
| 162 |
-
hashOutput.value = '';
|
| 163 |
-
}
|
| 164 |
}
|
| 165 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
</script>
|
| 167 |
"""
|
| 168 |
|
|
@@ -342,6 +352,12 @@ with tabs[1]:
|
|
| 342 |
</div>
|
| 343 |
""", unsafe_allow_html=True)
|
| 344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
# Input fields for citation and hash
|
| 346 |
st.markdown("""
|
| 347 |
<div>
|
|
@@ -357,9 +373,9 @@ with tabs[1]:
|
|
| 357 |
# Add JavaScript to capture pasted link data
|
| 358 |
components.html(verification_js(), height=0)
|
| 359 |
|
| 360 |
-
#
|
| 361 |
-
citation_html = st.
|
| 362 |
-
hash_html = st.
|
| 363 |
|
| 364 |
verify_button = st.button("Verify Citation", type="primary", use_container_width=True)
|
| 365 |
|
|
|
|
| 140 |
def verification_js():
|
| 141 |
return """
|
| 142 |
<script>
|
| 143 |
+
function updateOutputs() {
|
| 144 |
const citationInput = document.getElementById('citation_input');
|
| 145 |
const hashInput = document.getElementById('hash_input');
|
| 146 |
const citationOutput = document.getElementById('citation_output');
|
|
|
|
| 150 |
const citationLink = citationInput.getElementsByTagName('a')[0];
|
| 151 |
const hashLink = hashInput.getElementsByTagName('a')[0];
|
| 152 |
|
| 153 |
+
citationOutput.value = citationLink ? citationLink.outerHTML : '';
|
| 154 |
+
hashOutput.value = hashLink ? hashLink.outerHTML : '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
}
|
| 156 |
}
|
| 157 |
+
|
| 158 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 159 |
+
const citationInput = document.getElementById('citation_input');
|
| 160 |
+
const hashInput = document.getElementById('hash_input');
|
| 161 |
+
|
| 162 |
+
if (citationInput) {
|
| 163 |
+
citationInput.addEventListener('paste', function() {
|
| 164 |
+
setTimeout(updateOutputs, 100); // Delay to ensure paste is complete
|
| 165 |
+
});
|
| 166 |
+
citationInput.addEventListener('input', updateOutputs);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
if (hashInput) {
|
| 170 |
+
hashInput.addEventListener('paste', function() {
|
| 171 |
+
setTimeout(updateOutputs, 100); // Delay to ensure paste is complete
|
| 172 |
+
});
|
| 173 |
+
hashInput.addEventListener('input', updateOutputs);
|
| 174 |
+
}
|
| 175 |
+
});
|
| 176 |
</script>
|
| 177 |
"""
|
| 178 |
|
|
|
|
| 352 |
</div>
|
| 353 |
""", unsafe_allow_html=True)
|
| 354 |
|
| 355 |
+
# Initialize session state for storing extracted data
|
| 356 |
+
if 'citation_html' not in st.session_state:
|
| 357 |
+
st.session_state.citation_html = ''
|
| 358 |
+
if 'hash_html' not in st.session_state:
|
| 359 |
+
st.session_state.hash_html = ''
|
| 360 |
+
|
| 361 |
# Input fields for citation and hash
|
| 362 |
st.markdown("""
|
| 363 |
<div>
|
|
|
|
| 373 |
# Add JavaScript to capture pasted link data
|
| 374 |
components.html(verification_js(), height=0)
|
| 375 |
|
| 376 |
+
# Use session state to capture JavaScript output
|
| 377 |
+
citation_html = st.session_state.get('citation_output', '')
|
| 378 |
+
hash_html = st.session_state.get('hash_output', '')
|
| 379 |
|
| 380 |
verify_button = st.button("Verify Citation", type="primary", use_container_width=True)
|
| 381 |
|