|
32 | 32 | <script>
|
33 | 33 | (function() {
|
34 | 34 | try {
|
35 |
| - console.log('Script starting - checking localStorage availability'); |
36 | 35 | if (!window.localStorage) {
|
37 | 36 | console.error('localStorage is not available in this browser');
|
38 | 37 | return;
|
39 | 38 | }
|
40 | 39 |
|
41 |
| - // Function to initialize the storage functionality |
42 | 40 | function initializeStorage() {
|
43 |
| - console.log('Initializing storage functionality'); |
44 |
| - |
45 | 41 | const commentField = document.getElementById('vote-comment');
|
46 | 42 | if (!commentField) {
|
47 | 43 | console.error('Could not find comment field with ID vote-comment');
|
48 | 44 | return;
|
49 | 45 | }
|
50 |
| - console.log('Comment field found:', commentField); |
51 | 46 |
|
52 | 47 | const paperId = commentField.dataset.paperId;
|
53 | 48 | if (!paperId) {
|
54 | 49 | console.error('No paper ID found in data attributes');
|
55 | 50 | return;
|
56 | 51 | }
|
57 |
| - console.log('Paper ID:', paperId); |
58 | 52 |
|
59 | 53 | const storageKey = `vote_comment_${paperId}`;
|
60 |
| - console.log('Storage key:', storageKey); |
61 | 54 |
|
62 |
| - // Load saved comment if it exists |
63 | 55 | try {
|
64 | 56 | const savedComment = localStorage.getItem(storageKey);
|
65 |
| - console.log('Saved comment from storage:', savedComment); |
66 |
| - |
67 | 57 | if (savedComment) {
|
68 | 58 | commentField.value = savedComment;
|
69 |
| - console.log('Restored comment from storage'); |
70 | 59 | }
|
71 | 60 | } catch (e) {
|
72 | 61 | console.error('Error accessing localStorage:', e);
|
73 | 62 | }
|
74 | 63 |
|
75 |
| - // Save comment on input |
76 | 64 | commentField.addEventListener('input', function() {
|
77 | 65 | try {
|
78 |
| - console.log('Input detected, saving comment:', this.value); |
79 | 66 | localStorage.setItem(storageKey, this.value);
|
80 | 67 | } catch (e) {
|
81 | 68 | console.error('Error saving to localStorage:', e);
|
82 | 69 | }
|
83 | 70 | });
|
84 | 71 |
|
85 |
| - // Clear storage when form is submitted |
86 | 72 | const form = commentField.closest('form');
|
87 | 73 | if (form) {
|
88 | 74 | form.addEventListener('submit', function() {
|
89 | 75 | try {
|
90 |
| - console.log('Form submitted, clearing storage'); |
91 | 76 | localStorage.removeItem(storageKey);
|
92 | 77 | } catch (e) {
|
93 | 78 | console.error('Error clearing localStorage:', e);
|
|
98 | 83 | }
|
99 | 84 | }
|
100 | 85 |
|
101 |
| - // Try to initialize immediately if DOM is already loaded |
102 | 86 | if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
103 |
| - console.log('DOM already loaded, initializing immediately'); |
104 | 87 | initializeStorage();
|
105 | 88 | }
|
106 | 89 |
|
107 |
| - // Also set up the DOMContentLoaded listener as a backup |
108 |
| - document.addEventListener('DOMContentLoaded', function() { |
109 |
| - console.log('DOM Content Loaded event fired'); |
110 |
| - initializeStorage(); |
111 |
| - }); |
| 90 | + document.addEventListener('DOMContentLoaded', initializeStorage); |
112 | 91 |
|
113 | 92 | } catch (e) {
|
114 | 93 | console.error('Error in vote comment storage script:', e);
|
|
0 commit comments