Skip to content

Commit

Permalink
Disable view-markdown-source where it already exists (#4837)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Oct 1, 2021
1 parent 0313dc8 commit e518fef
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions source/features/view-markdown-source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,43 @@ import {CodeIcon, FileIcon} from '@primer/octicons-react';
import features from '.';

async function init(): Promise<void> {
const isPlain = new URLSearchParams(location.search).get('plain') === '1';
if (select.exists('[href^="?plain=1"]')) {
throw new Error('GitHub has implemented this feature. Please report this issue here https://github.com/sindresorhus/refined-github/pull/4837');
}

select('#raw-url')!.closest('.d-flex')!.prepend(
<div className="BtnGroup rgh-view-markdown-source mr-1">
<div className="BtnGroup rgh-view-markdown-source">
<a
href="?plain=1"
data-pjax="#repo-content-pjax-container"
className="btn btn-sm BtnGroup-item tooltipped tooltipped-nw"
aria-label="Display the source"
aria-label="Display the source blob"
role="button"
data-view-component="true"
className="source tooltipped tooltipped tooltipped-n btn-sm btn BtnGroup-item"
>
<CodeIcon/>
</a>
<a
href={location.pathname}
data-pjax="#repo-content-pjax-container"
className="btn btn-sm BtnGroup-item tooltipped tooltipped-nw"
aria-label="Display the rendered file"
aria-label="Display the rendered blob"
role="button"
data-view-component="true"
className="rendered tooltipped tooltipped tooltipped-n btn-sm btn BtnGroup-item"
>
<FileIcon/>
</a>
</div>,
);

const isPlain = new URLSearchParams(location.search).get('plain') === '1';
select('.rgh-view-markdown-source')!.children[isPlain ? 0 : 1].classList.add('selected');
}

void features.add(__filebasename, {
include: [
() => pageDetect.isSingleFile() && /\.(mdx?|mkdn?|mdwn|mdown|markdown|litcoffee|rst)$/.test(location.pathname),
pageDetect.isSingleFile,
],
asLongAs: [
() => /\.(mdx|mdwn|litcoffee|rst)$/.test(location.pathname),
],
deduplicate: '.rgh-view-markdown-source', // #3945
init,
Expand Down

0 comments on commit e518fef

Please sign in to comment.