Skip to content

Commit 04429f0

Browse files
committed
Testing Edit this page along with select and report feature
1 parent 34b73c7 commit 04429f0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

static/js/select-create-issue.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
document.addEventListener('mouseup', function (e) {
2+
const selection = window.getSelection().toString().trim();
3+
4+
// Prevent multiple buttons
5+
const existing = document.getElementById('report-issue-btn');
6+
if (existing) existing.remove();
7+
8+
if (selection.length > 0) {
9+
const reportBtn = document.createElement('button');
10+
reportBtn.innerText = 'Report Issue';
11+
reportBtn.id = 'report-issue-btn';
12+
Object.assign(reportBtn.style, {
13+
position: 'absolute',
14+
top: `${e.pageY}px`,
15+
left: `${e.pageX}px`,
16+
zIndex: 1000,
17+
background: '#f44336',
18+
color: 'white',
19+
border: 'none',
20+
borderRadius: '4px',
21+
padding: '6px 10px',
22+
cursor: 'pointer',
23+
});
24+
25+
document.body.appendChild(reportBtn);
26+
27+
reportBtn.onclick = () => {
28+
const pageUrl = window.location.href;
29+
const issueBody = `**Issue found on:** ${pageUrl}\n\n**Selected text:**\n\`\`\`\n${selection}\n\`\`\``;
30+
const issueUrl = `https://github.com/validatedpatterns/docs/issues/new?title=Content+Issue&body=${encodeURIComponent(issueBody)}`;
31+
window.open(issueUrl, '_blank');
32+
reportBtn.remove();
33+
};
34+
35+
// Hide the button if clicking elsewhere
36+
document.addEventListener('click', function removeButton(clickEvent) {
37+
if (clickEvent.target !== reportBtn) {
38+
reportBtn.remove();
39+
document.removeEventListener('click', removeButton);
40+
}
41+
});
42+
}
43+
});

0 commit comments

Comments
 (0)