File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments