mabuseif commited on
Commit
dfd2cfc
·
verified ·
1 Parent(s): 665bf18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -15
app.py CHANGED
@@ -140,7 +140,7 @@ def parse_metadata_hash(metadata_html):
140
  def verification_js():
141
  return """
142
  <script>
143
- function extractCitationData() {
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
- if (citationLink) {
154
- citationOutput.value = citationLink.outerHTML;
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
- # Capture the extracted data
361
- citation_html = st.text_input("Citation HTML (auto-filled)", key="citation_output", label_visibility="collapsed")
362
- hash_html = st.text_input("Hash HTML (auto-filled)", key="hash_output", label_visibility="collapsed")
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