11import  {  ConfigProvider  }  from  "../config" ; 
22import  {  renderGitpodUrl  }  from  "../utils" ; 
3+ import  {  isVisible  }  from  "../utils" ; 
34
45export  interface  Injector  { 
56
@@ -67,6 +68,48 @@ export abstract class InjectorBase implements Injector {
6768    } 
6869} 
6970
71+ function  openInGitpod ( e : MouseEvent  |  KeyboardEvent ,  inNewTab : boolean )  { 
72+     const  currentUrl  =  window . location . href ; 
73+     window . open ( `https://gitpod.io/#${ currentUrl }  ,  inNewTab  ? '_blank'  : '_self' ) ; 
74+     e . preventDefault ( ) ; 
75+     e . stopPropagation ( ) ; 
76+ } 
77+ 
78+ export  async  function  rewritePeriodKeybindGitHub ( )  { 
79+     const  configProvider  =  await  ConfigProvider . create ( ) ; 
80+     const  config  =  configProvider . getConfig ( ) ; 
81+ 
82+     if  ( config . rewritePeriodKeybind )  { 
83+         document . querySelectorAll ( '.js-github-dev-shortcut, .js-github-dev-new-tab-shortcut' ) . forEach ( ( elem )  =>  { 
84+             const  new_element  =  elem . cloneNode ( true )  as  HTMLElement ; 
85+             elem . parentNode ?. replaceChild ( new_element ,  elem ) ; 
86+             new_element . addEventListener ( 'click' ,  ( e )  =>  { 
87+                 if  ( new_element  &&  isVisible ( new_element )  &&  ! confirm ( 'Are you sure you want to open gitpod.io?' ) )  { 
88+                     return ; 
89+                 } 
90+                 openInGitpod ( e ,  elem . classList . contains ( 'js-github-dev-new-tab-shortcut' )  ||  config . openAsPopup ) ; 
91+             } ) ; 
92+         } ) ; 
93+     } 
94+ } 
95+ 
96+ export  async  function  rewritePeriodKeybindGitLab ( )  { 
97+     const  configProvider  =  await  ConfigProvider . create ( ) ; 
98+     const  config  =  configProvider . getConfig ( ) ; 
99+ 
100+     if  ( config . rewritePeriodKeybind )  { 
101+         const  unbindMousetrapScript  =  document . createElement ( 'script' ) ; 
102+         unbindMousetrapScript . innerHTML = 'window.Mousetrap.unbind(".");' ; 
103+         document . head . appendChild ( unbindMousetrapScript ) ; 
104+ 
105+         document . onkeydown  =  ( e : KeyboardEvent )  =>  { 
106+             if  ( e . code  ===  'Period' )  { 
107+                 openInGitpod ( e ,  e . shiftKey  ||  config . openAsPopup ) ; 
108+             } 
109+         } ; 
110+     } 
111+ } 
112+ 
70113export  const  checkIsBtnUpToDate  =  ( button : HTMLElement  |  null ,  currentUrl : string ) : boolean  =>  { 
71114    return  ! ! button  &&  button  instanceof  HTMLAnchorElement  &&  button . href  ===  currentUrl ; 
72115} ; 
0 commit comments