Skip to content

Commit

Permalink
feat: support github file tree view (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Canepa authored Mar 21, 2023
1 parent 0420e57 commit f251986
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/ts/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ const fonts = [
{ name: 'Octicons Regular', path: 'fonts/octicons.woff2' },
];

const isGithubPage = () => /.*github.*/.test(window.location.hostname);

const isGithubTreeViewPage = () => {
if (!isGithubPage()) return false;

return !!document.querySelector('#repos-file-tree');
};

const isGithubFilesPage = () => {
if (!/.*github.*/.test(window.location.hostname)) {
return false;
}
if (!isGithubPage()) return false;

const pathname = window.location.pathname;
const filesPageUrlPattern = new RegExp(/^\/.+\/.+\/pull\/\d+\/files$/);
Expand All @@ -53,6 +59,16 @@ const getSelector = (hostname: string) => {
};
}

if (isGithubTreeViewPage()) {
return {
filenameSelector:
'div.PRIVATE_TreeView-item-content > span.PRIVATE_TreeView-item-content-text > span',
iconSelector:
'div.PRIVATE_TreeView-item-content > div.PRIVATE_TreeView-item-visual',
host: Host.GitHub,
};
}

return {
filenameSelector:
'tr.js-navigation-item > td.content > span, .files-list > a.list-item, div.js-navigation-item > div[role="rowheader"] > span',
Expand Down

0 comments on commit f251986

Please sign in to comment.