Skip to content

Commit d6effca

Browse files
Updates
1 parent 43e067c commit d6effca

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

app.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ document.addEventListener('DOMContentLoaded', () => {
66
const expressionInput = document.getElementById('expressionInput');
77
const copyLatexBtn = document.getElementById('copyLatexBtn');
88
const copyCSVBtn = document.getElementById('copyCSVBtn');
9-
const copyTextBtn = document.getElementById('copyTextBtn');
109
const copyHTMLBtn = document.getElementById('copyHTMLBtn');
1110
const errorMessage = document.getElementById('errorMessage');
1211
const truthTableContainer = document.getElementById('truthTableContainer');
@@ -77,11 +76,27 @@ document.addEventListener('DOMContentLoaded', () => {
7776
}
7877

7978
copyLatexBtn.addEventListener('click', () => {
80-
if (currentLatex) {
81-
navigator.clipboard.writeText(currentLatex);
79+
if (!currentLatex) return;
80+
if (navigator.clipboard && navigator.clipboard.writeText) {
81+
navigator.clipboard.writeText(currentLatex).catch(() => {
82+
fallbackCopy(currentLatex);
83+
});
84+
} else {
85+
fallbackCopy(currentLatex);
8286
}
8387
});
8488

89+
function fallbackCopy(text) {
90+
const ta = document.createElement('textarea');
91+
ta.value = text;
92+
ta.style.position = 'fixed';
93+
ta.style.opacity = '0';
94+
document.body.appendChild(ta);
95+
ta.select();
96+
document.execCommand('copy');
97+
document.body.removeChild(ta);
98+
}
99+
85100
// Copy as CSV (comma-separated)
86101
copyCSVBtn.addEventListener('click', () => {
87102
if (!currentVisualizer) return;
@@ -94,18 +109,6 @@ document.addEventListener('DOMContentLoaded', () => {
94109
navigator.clipboard.writeText(csv);
95110
});
96111

97-
// Copy as text table (tab-separated — pastes as table in Google Docs / Word)
98-
copyTextBtn.addEventListener('click', () => {
99-
if (!currentVisualizer) return;
100-
const vars = currentVisualizer.variables;
101-
const table = currentVisualizer.truthTable;
102-
let text = vars.map(v => v.toUpperCase()).join('\t') + '\tOutput\n';
103-
table.forEach(row => {
104-
text += vars.map(v => String(row[v])).join('\t') + '\t' + row.output + '\n';
105-
});
106-
navigator.clipboard.writeText(text);
107-
});
108-
109112
// Copy rendered HTML table (preserves formatting when pasting into rich-text editors)
110113
copyHTMLBtn.addEventListener('click', () => {
111114
const tableEl = truthTableContainer.querySelector('table');

index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ <h3>XNOR</h3>
7676

7777
<div id="truthTableTab" class="tab-content" style="display:none;">
7878
<div class="table-buttons">
79-
<button id="copyCSVBtn">Copy as CSV</button>
80-
<button id="copyTextBtn">Copy as Text Table</button>
8179
<button id="copyHTMLBtn">Copy Table</button>
80+
<button id="copyCSVBtn">Copy as CSV</button>
8281
</div>
8382
<div id="truthTableContainer"></div>
8483
</div>

0 commit comments

Comments
 (0)