MCPcopy Create free account
hub / github.com/Yorick-Ryu/deep-share / injectButton

Function injectButton

scripts/injectGptButton.js:61–159  ·  view source on GitHub ↗
(copyBtn)

Source from the content-addressed store, hash-verified

59 setTimeout(findAndInjectButtons, 500);
60
61 function injectButton(copyBtn) {
62 // Create the DOCX button
63 const docxButton = document.createElement('button');
64 docxButton.className = 'text-token-text-secondary hover:bg-token-bg-secondary rounded-lg deepshare-docx-btn';
65 docxButton.setAttribute('aria-label', chrome.i18n?.getMessage('docxButton') || 'Save as Word document');
66
67 const span = document.createElement('span');
68 span.className = 'touch:w-10 flex h-8 w-8 items-center justify-center';
69
70 // Re-use the SVG from injectDocxButton.js for style consistency
71 span.innerHTML = `
72 <svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" style="width: 20px; height: 20px;">
73 <path d="M16 18H4C3.45 18 3 17.55 3 17V3C3 2.45 3.45 2 4 2H12L17 7V17C17 17.55 16.55 18 16 18Z" stroke="currentColor" stroke-width="1.25" fill="none"/>
74 <path d="M12 2V7H17" stroke="currentColor" stroke-width="1.5" fill="none"/>
75 <path d="M6 10.5H14" stroke="currentColor" stroke-width="1.5"/>
76 <path d="M6 14H12" stroke="currentColor" stroke-width="1.5"/>
77 </svg>
78 `;
79 docxButton.appendChild(span);
80
81 // Insert after the copy button
82 copyBtn.insertAdjacentElement('afterend', docxButton);
83
84 // Add tooltip listeners
85 let tooltip = null;
86
87 docxButton.addEventListener('mouseenter', () => {
88 if (docxButton.hasAttribute('disabled')) return;
89
90 tooltip = document.createElement('div');
91 tooltip.className = 'deepshare-gpt-tooltip';
92 tooltip.textContent = docxButton.getAttribute('aria-label');
93 document.body.appendChild(tooltip);
94
95 const btnRect = docxButton.getBoundingClientRect();
96 const tooltipRect = tooltip.getBoundingClientRect();
97
98 let top = btnRect.bottom + 8;
99 let left = btnRect.left + (btnRect.width / 2) - (tooltipRect.width / 2);
100
101 if (left < 5) left = 5;
102 if (left + tooltipRect.width > window.innerWidth) {
103 left = window.innerWidth - tooltipRect.width - 5;
104 }
105
106 tooltip.style.top = `${top}px`;
107 tooltip.style.left = `${left}px`;
108 });
109
110 docxButton.addEventListener('mouseleave', () => {
111 if (tooltip) {
112 tooltip.remove();
113 tooltip = null;
114 }
115 });
116
117 // Add click handler
118 docxButton.addEventListener('click', async (e) => {

Callers 1

findAndInjectButtonsFunction · 0.70

Calls 8

hasAttributeMethod · 0.80
debugMethod · 0.80
setAttributeMethod · 0.45
appendChildMethod · 0.45
getAttributeMethod · 0.45
removeMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected