-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from PlayGuitar-CoderQ/feature/keyboard-shortcuts
Feature/keyboard shortcuts
- Loading branch information
Showing
8 changed files
with
113 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function toGithub1s () { | ||
if (!window) { | ||
return; | ||
} | ||
|
||
window.open(`${`https://github1s.com${window.location.pathname}`}`); | ||
} | ||
|
||
export { | ||
toGithub1s | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useEffect, useMemo } from 'react'; | ||
import registerKeyDownListen from '../register/keydownListen'; | ||
|
||
const useGitHub = () => { | ||
|
||
useEffect(() => { | ||
registerKeyDownListen(); | ||
}, []) | ||
|
||
const isCodePage = useMemo<boolean>(() => { | ||
const url = window.location.href; | ||
const fileNavigation = document.querySelectorAll('.file-navigation'); | ||
const isHasBlob = url.includes('/blob/'); | ||
const isHasTree = url.includes('/tree/'); | ||
|
||
return fileNavigation.length > 0 || isHasBlob || isHasTree; | ||
}, []) | ||
|
||
return { | ||
isCodePage, | ||
} | ||
} | ||
|
||
export { | ||
useGitHub | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { keyCodeEnums } from '../../enum/commandEnum'; | ||
import { toGithub1s } from '../event'; | ||
|
||
const keyCodeEventMap: Record<string, Function> = { | ||
[keyCodeEnums.comma]: toGithub1s | ||
} | ||
|
||
const keyDownListen = () => { | ||
window.addEventListener("keydown", function (e) { | ||
keyCodeEventMap[e.code](); | ||
}) | ||
} | ||
|
||
export default keyDownListen; |
35 changes: 35 additions & 0 deletions
35
src/contents/views/Github/components/OnlineEditBtn/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { FC } from 'react'; | ||
|
||
interface OnlineEditBtnProps { | ||
onClick?: () => void; | ||
title: string; | ||
} | ||
|
||
const OnlineEditBtn: FC<OnlineEditBtnProps> = props => { | ||
const { onClick, title } = props; | ||
|
||
return ( | ||
<button | ||
onClick={onClick} | ||
style={{ | ||
color: 'white', | ||
colorScheme: 'dark', | ||
fontWeight: 'bold', | ||
padding: '5px 10px', | ||
lineHeight: '20px', | ||
cursor: 'pointer', | ||
fontSize: '14px', | ||
background: 'rgb(52, 125, 57)', | ||
position: 'fixed', | ||
right: '100px', | ||
bottom: '100px', | ||
border: '1px solid rgba(205, 217, 229, 0.1)', | ||
borderRadius: '6px', | ||
}} | ||
> | ||
{title} | ||
</button> | ||
) | ||
} | ||
|
||
export default OnlineEditBtn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { PlasmoContentScript } from 'plasmo' | ||
|
||
import { useGitHub } from '../../hooks/useGitHub'; | ||
|
||
import OnlineEditBtn from './components/OnlineEditBtn'; | ||
|
||
export const config: PlasmoContentScript = { | ||
matches: ['https://github.com/*/*'], | ||
} | ||
|
||
|
||
export default function FunctionPage() { | ||
const { isCodePage } = useGitHub(); | ||
|
||
|
||
return ( | ||
<> | ||
{isCodePage && <OnlineEditBtn title='在线编辑' />} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// | ||
export enum keyCodeEnums { | ||
/** 逗号的 code */ | ||
comma = "Comma" | ||
} |