|
| 1 | +<script> |
| 2 | +(function () { |
| 3 | + document.addEventListener('mouseup', function (e) { |
| 4 | + const selection = window.getSelection().toString().trim(); |
| 5 | + |
| 6 | + // Avoid adding the button repeatedly |
| 7 | + const existing = document.getElementById('report-issue-btn'); |
| 8 | + if (existing) existing.remove(); |
| 9 | + |
| 10 | + if (selection.length > 0) { |
| 11 | + const reportBtn = document.createElement('button'); |
| 12 | + reportBtn.innerText = 'Report Issue'; |
| 13 | + reportBtn.id = 'report-issue-btn'; |
| 14 | + |
| 15 | + Object.assign(reportBtn.style, { |
| 16 | + position: 'absolute', |
| 17 | + top: `${e.pageY + 10}px`, |
| 18 | + left: `${e.pageX}px`, |
| 19 | + zIndex: 1000, |
| 20 | + background: '#e53935', |
| 21 | + color: '#fff', |
| 22 | + border: 'none', |
| 23 | + borderRadius: '4px', |
| 24 | + padding: '6px 10px', |
| 25 | + boxShadow: '0 2px 4px rgba(0,0,0,0.2)', |
| 26 | + fontSize: '14px', |
| 27 | + cursor: 'pointer', |
| 28 | + }); |
| 29 | + |
| 30 | + document.body.appendChild(reportBtn); |
| 31 | + |
| 32 | + reportBtn.addEventListener('click', () => { |
| 33 | + const pageUrl = window.location.href; |
| 34 | + const issueBody = `**Issue found on:** ${pageUrl}\n\n**Selected text:**\n\`\`\`\n${selection}\n\`\`\``; |
| 35 | + const issueUrl = `https://github.com/validatedpatterns/docs/issues/new?title=Content+Issue&body=${encodeURIComponent(issueBody)}`; |
| 36 | + window.open(issueUrl, '_blank'); |
| 37 | + reportBtn.remove(); |
| 38 | + }); |
| 39 | + |
| 40 | + document.addEventListener('click', function handler(ev) { |
| 41 | + if (ev.target !== reportBtn) { |
| 42 | + reportBtn.remove(); |
| 43 | + document.removeEventListener('click', handler); |
| 44 | + } |
| 45 | + }); |
| 46 | + } |
| 47 | + }); |
| 48 | +})(); |
| 49 | +</script> |
0 commit comments