@@ -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' ) ;
0 commit comments