MCPcopy Create free account
hub / github.com/explorerhq/sql-explorer / setUpCopyButtons

Function setUpCopyButtons

explorer/src/js/assistant.js:288–313  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

286}
287
288function setUpCopyButtons(){
289 document.querySelectorAll('#assistant_response pre').forEach(pre => {
290
291 const btn = document.createElement('i');
292 btn.classList.add('copy-btn');
293 btn.classList.add('bi-copy');
294 const msg = document.createElement('span');
295 msg.textContent = 'Copied!';
296 msg.style.display = 'none';
297 msg.style.marginLeft = '8px';
298 btn.appendChild(msg);
299 pre.appendChild(btn);
300
301 btn.addEventListener('click', function() {
302 const code = this.parentNode.firstElementChild.innerText;
303 navigator.clipboard.writeText(code).then(() => {
304 msg.style.display = 'inline';
305 setTimeout(() => {
306 msg.style.display = 'none';
307 }, 2000);
308 }).catch(err => {
309 console.error('Error in copying text: ', err);
310 });
311 });
312 });
313}

Callers 1

submitAssistantAskFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected