|
@@ -150,6 +150,13 @@ const JS_SCRIPT_VIEWSPECS: &str = r##"
|
|
|
const jumpButton = document.querySelector('input[type="button"][value="Jump Item:"]');
|
|
|
jumpButton.addEventListener('click', jumpToItem);
|
|
|
});
|
|
|
+ function refreshPage() {
|
|
|
+ // Save the current scroll position and checkbox states to localStorage
|
|
|
+ localStorage.setItem('scrollPosition', window.scrollY);
|
|
|
+ localStorage.setItem('blankLinesChecked', blankLinesChecked);
|
|
|
+ localStorage.setItem('numberingChecked', numberingChecked);
|
|
|
+ location.reload();
|
|
|
+ }
|
|
|
|
|
|
function openNewWindow() {
|
|
|
const popupJs = `
|
|
@@ -160,10 +167,73 @@ const JS_SCRIPT_VIEWSPECS: &str = r##"
|
|
|
element.classList.toggle('transparent', !numberingCheckbox.checked);
|
|
|
});
|
|
|
}
|
|
|
+ function toggleBlankLines() {
|
|
|
+ const blankLinesCheckbox = document.getElementById('blankLines');
|
|
|
+ const content = window.opener.document.getElementById('content');
|
|
|
+
|
|
|
+ if (blankLinesCheckbox.checked) {
|
|
|
+ // Restore original <br> elements
|
|
|
+ window.opener.originalBrElements.forEach(br => {
|
|
|
+ const parent = br.parentNode;
|
|
|
+ parent.insertBefore(br.element, parent.children[br.index]);
|
|
|
+ });
|
|
|
+ window.opener.originalBrElements = [];
|
|
|
+
|
|
|
+ // Restore original margins
|
|
|
+ window.opener.originalStyles.forEach(item => {
|
|
|
+ item.element.style.marginTop = item.styles.marginTop;
|
|
|
+ item.element.style.marginBottom = item.styles.marginBottom;
|
|
|
+ });
|
|
|
+ window.opener.originalStyles = [];
|
|
|
+ } else {
|
|
|
+ // Remove all <br> elements
|
|
|
+ const brElements = content.querySelectorAll('br');
|
|
|
+ window.opener.originalBrElements = [];
|
|
|
+ brElements.forEach(br => {
|
|
|
+ const parent = br.parentNode;
|
|
|
+ const index = Array.prototype.indexOf.call(parent.children, br);
|
|
|
+ window.opener.originalBrElements.push({element: br, parent, index});
|
|
|
+ parent.removeChild(br);
|
|
|
+ });
|
|
|
+
|
|
|
+ // Set margins to 0 and store original styles
|
|
|
+ const allElements = window.opener.document.querySelectorAll('*');
|
|
|
+ window.opener.originalStyles = [];
|
|
|
+ allElements.forEach(element => {
|
|
|
+ window.opener.originalStyles.push({
|
|
|
+ element: element,
|
|
|
+ styles: {
|
|
|
+ marginTop: element.style.marginTop,
|
|
|
+ marginBottom: element.style.marginBottom
|
|
|
+ }
|
|
|
+ });
|
|
|
+ element.style.marginTop = '0';
|
|
|
+ element.style.marginBottom = '0';
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update the main page state
|
|
|
+ window.opener.blankLinesChecked = blankLinesCheckbox.checked;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ function saveStateAndClose() {
|
|
|
+ // Save the state of checkboxes to localStorage
|
|
|
+ localStorage.setItem('blankLinesChecked', document.getElementById('blankLines').checked);
|
|
|
+ localStorage.setItem('numberingChecked', document.getElementById('numbering').checked);
|
|
|
+
|
|
|
+ window.opener.refreshPage();
|
|
|
+ }
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
const numberingCheckbox = document.getElementById('numbering');
|
|
|
numberingCheckbox.addEventListener('change', toggleNumbering);
|
|
|
+
|
|
|
+ const blankLinesCheckbox = document.getElementById('blankLines');
|
|
|
+ blankLinesCheckbox.addEventListener('change', toggleBlankLines);
|
|
|
+
|
|
|
+ //esure the checkbox is iniatially ticked
|
|
|
+ blankLinesCheckbox.checked = true;
|
|
|
});
|
|
|
`;
|
|
|
|
|
@@ -202,6 +272,10 @@ const JS_SCRIPT_VIEWSPECS: &str = r##"
|
|
|
.transparent {
|
|
|
color: transparent !important;
|
|
|
}
|
|
|
+ .compress-blank-lines * {
|
|
|
+ padding: 0;
|
|
|
+ margin: 0;
|
|
|
+ }
|
|
|
</style>
|
|
|
</head>
|
|
|
<body>
|