123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- pub fn email_scripts() -> String {
- r#"
- <script>
- let numberingVisible = true;
- let blankLinesVisible = false;
- function applyNumberingVisibility() {{
- const purplenumbers = document.querySelectorAll('.purplenumber');
- purplenumbers.forEach(element => {{
- element.classList.toggle('transparent', !numberingVisible);
- }});
- }}
- function applyBlankLinesVisibility() {{
- const content = document.getElementById('content');
- if (blankLinesVisible) {{
- if (window.originalBrElements) {{
- window.originalBrElements.forEach(br => {{
- const parent = br.parent;
- if (parent) {{
- parent.insertBefore(br.element, parent.children[br.index]);
- }}
- }});
- window.originalBrElements = [];
- }}
- if (window.originalStyles) {{
- window.originalStyles.forEach(item => {{
- item.element.style.marginTop = item.styles.marginTop;
- item.element.style.marginBottom = item.styles.marginBottom;
- }});
- window.originalStyles = [];
- }}
- }} else {{
- const brElements = content.querySelectorAll('br');
- window.originalBrElements = [];
- brElements.forEach(br => {{
- const parent = br.parentNode;
- const index = Array.prototype.indexOf.call(parent.children, br);
- window.originalBrElements.push({{element: br, parent, index}});
- parent.removeChild(br);
- }});
- const allElements = document.querySelectorAll('*');
- window.originalStyles = [];
- allElements.forEach(element => {{
- window.originalStyles.push({{
- element: element,
- styles: {{
- marginTop: element.style.marginTop,
- marginBottom: element.style.marginBottom
- }}
- }});
- element.style.marginTop = '0';
- element.style.marginBottom = '0';
- }});
- }}
- }}
- function showElement(body_id, summary_id) {{
- const summaries = document.querySelectorAll('.message-meta');
- const innerElements = document.querySelectorAll('.email-body');
- const zoom_ins = document.querySelectorAll('.zoom_in');
- const zoom_outs = document.querySelectorAll('.zoom_out');
- summaries.forEach(summary => {{
- summary.style.display = 'none';
- }});
- innerElements.forEach(element => {{
- element.style.display = 'none';
- }});
- zoom_ins.forEach(element => {{
- element.style.display = 'none';
- }});
- zoom_outs.forEach(element => {{
- element.style.display = 'block';
- }});
- document.getElementById(body_id).style.display = 'block';
- document.getElementById(summary_id).style.display = 'block';
- window.scrollTo(0, 0);
- }}
- function showSummaries() {{
- const summaries = document.querySelectorAll('.message-meta');
- const innerElements = document.querySelectorAll('.email-body');
- const zoom_ins = document.querySelectorAll('.zoom_in');
- const zoom_outs = document.querySelectorAll('.zoom_out');
- summaries.forEach(summary => {{
- summary.style.display = 'block';
- }});
- innerElements.forEach(element => {{
- element.style.display = 'none';
- }});
- zoom_ins.forEach(element => {{
- element.style.display = 'block';
- }});
- zoom_outs.forEach(element => {{
- element.style.display = 'none';
- }});
- window.scrollTo(0, 0);
- }}
- function jumpToItem() {{
- const id = document.getElementById('textfield').value;
- if (id) {{
- window.location.href = '#' + id;
- }}
- }}
- function openNewWindow() {{
- const newWindow = window.open('', '', 'width=250,height=200');
- const popupContent = `
- <!DOCTYPE html>
- <html>
- <head>
- <title>Viewspecs</title>
- <style>
- .popup-content {{
- font-family: Arial, sans-serif;
- font-size: 14px;
- margin: 20px;
- }}
- .popup-content fieldset {{
- border: 1px solid #000;
- padding: 10px;
- }}
- .popup-content legend {{
- padding: 0 10px;
- font-weight: bold;
- }}
- .popup-content label {{
- display: block;
- margin-bottom: 5px;
- }}
- .popup-content input {{
- margin-right: 5px;
- }}
- .accept-button {{
- margin-top: 10px;
- padding: 5px 10px;
- font-size: 14px;
- cursor: pointer;
- }}
- </style>
- </head>
- <body>
- <div class="popup-content">
- <fieldset>
- <legend>Show</legend>
- <label> Blank lines (y/z)</label>
- <label> Numbering (m/n)</label>
- </fieldset>
- <button class="accept-button" onclick="window.close()">Accept</button>
- </div>
- </body>
- </html>
- `;
- newWindow.document.open();
- newWindow.document.write(popupContent);
- newWindow.document.close();
- }}
- document.addEventListener('DOMContentLoaded', function() {{
- const textfield = document.getElementById('textfield');
- textfield.addEventListener('keydown', function(event) {{
- if (event.key === 'Enter') {{
- jumpToItem();
- }}
- }});
- const jumpButton = document.querySelector('input[type="button"][value="Jump Item:"]');
- jumpButton.addEventListener('click', jumpToItem);
- // Apply stored states on load
- blankLinesVisible = JSON.parse(localStorage.getItem('blankLinesVisible') || 'true');
- numberingVisible = JSON.parse(localStorage.getItem('numberingVisible') || 'true');
- applyBlankLinesVisibility();
- applyNumberingVisibility();
- document.getElementById('numbering').addEventListener('change', function() {{
- numberingVisible = this.checked;
- applyNumberingVisibility();
- }});
- document.getElementById('blankLines').addEventListener('change', function() {{
- blankLinesVisible = this.checked;
- applyBlankLinesVisibility();
- }});
- }});
- // Keyboard shortcuts
- document.addEventListener('keydown', function(event) {{
- const numberingCheckbox = document.getElementById('numbering');
- const blankLinesCheckbox = document.getElementById('blankLines');
- if (event.key === 'm') {{
- numberingVisible = true;
- if (numberingCheckbox) numberingCheckbox.checked = true;
- applyNumberingVisibility();
- }}
- if (event.key === 'n') {{
- numberingVisible = false;
- if (numberingCheckbox) numberingCheckbox.checked = false;
- applyNumberingVisibility();
- }}
- if (event.key === 'y') {{
- blankLinesVisible = true;
- if (blankLinesCheckbox) blankLinesCheckbox.checked = true;
- applyBlankLinesVisibility();
- }}
- if (event.key === 'z') {{
- blankLinesVisible = false;
- if (blankLinesCheckbox) blankLinesCheckbox.checked = false;
- applyBlankLinesVisibility();
- }}
- }});
- </script>
- "#.to_string()
- }
|