mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
chore: deprecate copy file button
This commit is contained in:
parent
e6abbcf555
commit
bd6cf0a5b3
5 changed files with 3 additions and 77 deletions
|
|
@ -20,15 +20,12 @@ export const wikiLinks = {
|
|||
compressSingletonFolder: `${WIKI_HOME_LINK}/Compress-Singleton-Folder`,
|
||||
changeLog: `${WIKI_HOME_LINK}/Change-Log`,
|
||||
codeFolding: `${WIKI_HOME_LINK}/Code-folding`,
|
||||
copyFileButton: `${WIKI_HOME_LINK}/Copy-file-and-snippet`,
|
||||
copySnippet: `${WIKI_HOME_LINK}/Copy-file-and-snippet`,
|
||||
createAccessToken: `${WIKI_HOME_LINK}/Access-token-for-Gitako`,
|
||||
pjaxMode: `${WIKI_HOME_LINK}/Pjax-Mode`,
|
||||
}
|
||||
|
||||
const moreFields: SimpleConfigField<
|
||||
'copyFileButton' | 'copySnippetButton' | 'codeFolding' | 'pjaxMode'
|
||||
>[] =
|
||||
const moreFields: SimpleConfigField<'copySnippetButton' | 'codeFolding' | 'pjaxMode'>[] =
|
||||
platform === GitHub
|
||||
? [
|
||||
{
|
||||
|
|
@ -47,12 +44,6 @@ const moreFields: SimpleConfigField<
|
|||
onChange: checked => (checked ? 'native' : 'pjax-api'),
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'copyFileButton',
|
||||
label: 'Copy file button',
|
||||
wikiLink: wikiLinks.copyFileButton,
|
||||
tooltip: `Read more in Gitako's Wiki`,
|
||||
},
|
||||
{
|
||||
key: 'copySnippetButton',
|
||||
label: 'Copy snippet button',
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ import { Clippy, ClippyClassName } from 'components/Clippy'
|
|||
import * as React from 'react'
|
||||
import { $ } from 'utils/$'
|
||||
import { formatClass, parseIntFromElement } from 'utils/DOMHelper'
|
||||
import { renderReact, run } from 'utils/general'
|
||||
import { CopyFileButton, copyFileButtonClassName } from './CopyFileButton'
|
||||
import { renderReact } from 'utils/general'
|
||||
|
||||
const selectors = {
|
||||
globalNavigation: {
|
||||
|
|
@ -197,49 +196,6 @@ export function getCodeElement() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add copy file content buttons to button groups
|
||||
* click these buttons will copy file content to clipboard
|
||||
*/
|
||||
export function attachCopyFileBtn() {
|
||||
const removeButtons = () => {
|
||||
const buttons = document.querySelectorAll(formatClass(copyFileButtonClassName))
|
||||
buttons.forEach(button => {
|
||||
button.parentElement?.removeChild(button)
|
||||
})
|
||||
}
|
||||
|
||||
if (getCurrentPageType() === PAGE_TYPES.RAW_TEXT) {
|
||||
let buttonGroup: HTMLElement | null = null
|
||||
|
||||
if (!buttonGroup) {
|
||||
const rawUrlButtonSelector = '#raw-url'
|
||||
const $buttonGroup = document.querySelector(rawUrlButtonSelector)?.parentElement
|
||||
if ($buttonGroup) buttonGroup = $buttonGroup
|
||||
}
|
||||
|
||||
if (!buttonGroup) {
|
||||
const buttonGroupSelector = 'main .Box-header .BtnGroup'
|
||||
const buttonGroups = document.querySelectorAll(buttonGroupSelector)
|
||||
const $buttonGroup = buttonGroups[buttonGroups.length - 1]
|
||||
if ($buttonGroup) buttonGroup = $buttonGroup as HTMLElement
|
||||
}
|
||||
|
||||
run(async () => {
|
||||
if (!buttonGroup) raiseError(new Error(`No button groups found`))
|
||||
else if (!buttonGroup.lastElementChild) return
|
||||
else {
|
||||
removeButtons() // prevent duplicated buttons
|
||||
const button = await renderReact(React.createElement(CopyFileButton))
|
||||
if (button instanceof HTMLElement) buttonGroup.appendChild(button)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// return callback so that disabling after redirecting from file page to non-page works properly
|
||||
return removeButtons
|
||||
}
|
||||
|
||||
export function attachCopySnippet() {
|
||||
const readmeSelector = 'main div#readme'
|
||||
return $(readmeSelector, () => {
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
import { platform } from 'platforms'
|
||||
import * as React from 'react'
|
||||
import { useAfterRedirect } from 'utils/hooks/useFastRedirect'
|
||||
import * as DOMHelper from '../DOMHelper'
|
||||
import { GitHub } from '../index'
|
||||
|
||||
export function useGitHubAttachCopyFileButton(copyFileButton: boolean) {
|
||||
const attachCopyFileButton = React.useCallback(
|
||||
function attachCopyFileButton() {
|
||||
if (platform === GitHub && copyFileButton) DOMHelper.attachCopyFileBtn()
|
||||
},
|
||||
[copyFileButton],
|
||||
)
|
||||
React.useEffect(attachCopyFileButton, [attachCopyFileButton])
|
||||
useAfterRedirect(attachCopyFileButton)
|
||||
}
|
||||
|
|
@ -10,7 +10,6 @@ import * as DOMHelper from './DOMHelper'
|
|||
import { getCommitTreeData } from './getCommitTreeData'
|
||||
import { getPullRequestTreeData } from './getPullRequestTreeData'
|
||||
import { useEnterpriseStatBarStyleFix } from './hooks/useEnterpriseStatBarStyleFix'
|
||||
import { useGitHubAttachCopyFileButton } from './hooks/useGitHubAttachCopyFileButton'
|
||||
import { useGitHubAttachCopySnippetButton } from './hooks/useGitHubAttachCopySnippetButton'
|
||||
import { useGitHubCodeFold } from './hooks/useGitHubCodeFold'
|
||||
import * as URLHelper from './URLHelper'
|
||||
|
|
@ -196,8 +195,7 @@ export const GitHub: Platform = {
|
|||
return `https://github.com/login/oauth/authorize?${params}`
|
||||
},
|
||||
usePlatformHooks() {
|
||||
const { copyFileButton, copySnippetButton, codeFolding } = useConfigs().value
|
||||
useGitHubAttachCopyFileButton(copyFileButton)
|
||||
const { copySnippetButton, codeFolding } = useConfigs().value
|
||||
useGitHubAttachCopySnippetButton(copySnippetButton)
|
||||
useGitHubCodeFold(codeFolding)
|
||||
useEnterpriseStatBarStyleFix()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ export type Config = {
|
|||
focusSearchInputShortcut: string | undefined // shortcut for focusing search input
|
||||
accessToken: string | undefined
|
||||
compressSingletonFolder: boolean
|
||||
copyFileButton: boolean
|
||||
copySnippetButton: boolean
|
||||
intelligentToggle: boolean | null // `null` stands for intelligent, boolean for sidebar open state
|
||||
icons: 'rich' | 'dim' | 'native'
|
||||
|
|
@ -33,7 +32,6 @@ enum configKeys {
|
|||
focusSearchInputShortcut = 'focusSearchInputShortcut',
|
||||
accessToken = 'accessToken',
|
||||
compressSingletonFolder = 'compressSingletonFolder',
|
||||
copyFileButton = 'copyFileButton',
|
||||
copySnippetButton = 'copySnippetButton',
|
||||
intelligentToggle = 'intelligentToggle',
|
||||
icons = 'icons',
|
||||
|
|
@ -59,7 +57,6 @@ export const getDefaultConfigs: () => Config = () => ({
|
|||
focusSearchInputShortcut: undefined,
|
||||
accessToken: '',
|
||||
compressSingletonFolder: true,
|
||||
copyFileButton: !isInGitHub, // disable on github.com
|
||||
copySnippetButton: !isInGitHub, // disable on github.com
|
||||
intelligentToggle: null,
|
||||
icons: 'rich',
|
||||
|
|
|
|||
Loading…
Reference in a new issue