js.rs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. pub fn email_scripts() -> String {
  2. r#"
  3. <script>
  4. let numberingVisible = true;
  5. let blankLinesVisible = false;
  6. function applyNumberingVisibility() {{
  7. const purplenumbers = document.querySelectorAll('.purplenumber');
  8. purplenumbers.forEach(element => {{
  9. element.classList.toggle('transparent', !numberingVisible);
  10. }});
  11. }}
  12. function applyBlankLinesVisibility() {{
  13. const content = document.getElementById('content');
  14. if (blankLinesVisible) {{
  15. if (window.originalBrElements) {{
  16. window.originalBrElements.forEach(br => {{
  17. const parent = br.parent;
  18. if (parent) {{
  19. parent.insertBefore(br.element, parent.children[br.index]);
  20. }}
  21. }});
  22. window.originalBrElements = [];
  23. }}
  24. if (window.originalStyles) {{
  25. window.originalStyles.forEach(item => {{
  26. item.element.style.marginTop = item.styles.marginTop;
  27. item.element.style.marginBottom = item.styles.marginBottom;
  28. }});
  29. window.originalStyles = [];
  30. }}
  31. }} else {{
  32. const brElements = content.querySelectorAll('br');
  33. window.originalBrElements = [];
  34. brElements.forEach(br => {{
  35. const parent = br.parentNode;
  36. const index = Array.prototype.indexOf.call(parent.children, br);
  37. window.originalBrElements.push({{element: br, parent, index}});
  38. parent.removeChild(br);
  39. }});
  40. const allElements = document.querySelectorAll('*');
  41. window.originalStyles = [];
  42. allElements.forEach(element => {{
  43. window.originalStyles.push({{
  44. element: element,
  45. styles: {{
  46. marginTop: element.style.marginTop,
  47. marginBottom: element.style.marginBottom
  48. }}
  49. }});
  50. element.style.marginTop = '0';
  51. element.style.marginBottom = '0';
  52. }});
  53. }}
  54. }}
  55. function showElement(body_id, summary_id) {{
  56. const summaries = document.querySelectorAll('.message-meta');
  57. const innerElements = document.querySelectorAll('.email-body');
  58. const zoom_ins = document.querySelectorAll('.zoom_in');
  59. const zoom_outs = document.querySelectorAll('.zoom_out');
  60. summaries.forEach(summary => {{
  61. summary.style.display = 'none';
  62. }});
  63. innerElements.forEach(element => {{
  64. element.style.display = 'none';
  65. }});
  66. zoom_ins.forEach(element => {{
  67. element.style.display = 'none';
  68. }});
  69. zoom_outs.forEach(element => {{
  70. element.style.display = 'block';
  71. }});
  72. document.getElementById(body_id).style.display = 'block';
  73. document.getElementById(summary_id).style.display = 'block';
  74. window.scrollTo(0, 0);
  75. }}
  76. function showSummaries() {{
  77. const summaries = document.querySelectorAll('.message-meta');
  78. const innerElements = document.querySelectorAll('.email-body');
  79. const zoom_ins = document.querySelectorAll('.zoom_in');
  80. const zoom_outs = document.querySelectorAll('.zoom_out');
  81. summaries.forEach(summary => {{
  82. summary.style.display = 'block';
  83. }});
  84. innerElements.forEach(element => {{
  85. element.style.display = 'none';
  86. }});
  87. zoom_ins.forEach(element => {{
  88. element.style.display = 'block';
  89. }});
  90. zoom_outs.forEach(element => {{
  91. element.style.display = 'none';
  92. }});
  93. window.scrollTo(0, 0);
  94. }}
  95. function jumpToItem() {{
  96. const id = document.getElementById('textfield').value;
  97. if (id) {{
  98. window.location.href = '#' + id;
  99. }}
  100. }}
  101. function openNewWindow() {{
  102. const newWindow = window.open('', '', 'width=250,height=200');
  103. const popupContent = `
  104. <!DOCTYPE html>
  105. <html>
  106. <head>
  107. <title>Viewspecs</title>
  108. <style>
  109. .popup-content {{
  110. font-family: Arial, sans-serif;
  111. font-size: 14px;
  112. margin: 20px;
  113. }}
  114. .popup-content fieldset {{
  115. border: 1px solid #000;
  116. padding: 10px;
  117. }}
  118. .popup-content legend {{
  119. padding: 0 10px;
  120. font-weight: bold;
  121. }}
  122. .popup-content label {{
  123. display: block;
  124. margin-bottom: 5px;
  125. }}
  126. .popup-content input {{
  127. margin-right: 5px;
  128. }}
  129. .accept-button {{
  130. margin-top: 10px;
  131. padding: 5px 10px;
  132. font-size: 14px;
  133. cursor: pointer;
  134. }}
  135. </style>
  136. </head>
  137. <body>
  138. <div class="popup-content">
  139. <fieldset>
  140. <legend>Show</legend>
  141. <label> Blank lines (y/z)</label>
  142. <label> Numbering (m/n)</label>
  143. </fieldset>
  144. <button class="accept-button" onclick="window.close()">Accept</button>
  145. </div>
  146. </body>
  147. </html>
  148. `;
  149. newWindow.document.open();
  150. newWindow.document.write(popupContent);
  151. newWindow.document.close();
  152. }}
  153. document.addEventListener('DOMContentLoaded', function() {{
  154. const textfield = document.getElementById('textfield');
  155. textfield.addEventListener('keydown', function(event) {{
  156. if (event.key === 'Enter') {{
  157. jumpToItem();
  158. }}
  159. }});
  160. const jumpButton = document.querySelector('input[type="button"][value="Jump Item:"]');
  161. jumpButton.addEventListener('click', jumpToItem);
  162. // Apply stored states on load
  163. blankLinesVisible = JSON.parse(localStorage.getItem('blankLinesVisible') || 'true');
  164. numberingVisible = JSON.parse(localStorage.getItem('numberingVisible') || 'true');
  165. applyBlankLinesVisibility();
  166. applyNumberingVisibility();
  167. document.getElementById('numbering').addEventListener('change', function() {{
  168. numberingVisible = this.checked;
  169. applyNumberingVisibility();
  170. }});
  171. document.getElementById('blankLines').addEventListener('change', function() {{
  172. blankLinesVisible = this.checked;
  173. applyBlankLinesVisibility();
  174. }});
  175. }});
  176. // Keyboard shortcuts
  177. document.addEventListener('keydown', function(event) {{
  178. const numberingCheckbox = document.getElementById('numbering');
  179. const blankLinesCheckbox = document.getElementById('blankLines');
  180. if (event.key === 'm') {{
  181. numberingVisible = true;
  182. if (numberingCheckbox) numberingCheckbox.checked = true;
  183. applyNumberingVisibility();
  184. }}
  185. if (event.key === 'n') {{
  186. numberingVisible = false;
  187. if (numberingCheckbox) numberingCheckbox.checked = false;
  188. applyNumberingVisibility();
  189. }}
  190. if (event.key === 'y') {{
  191. blankLinesVisible = true;
  192. if (blankLinesCheckbox) blankLinesCheckbox.checked = true;
  193. applyBlankLinesVisibility();
  194. }}
  195. if (event.key === 'z') {{
  196. blankLinesVisible = false;
  197. if (blankLinesCheckbox) blankLinesCheckbox.checked = false;
  198. applyBlankLinesVisibility();
  199. }}
  200. }});
  201. </script>
  202. "#.to_string()
  203. }