diff options
143 files changed, 171 insertions, 682 deletions
diff --git a/contributing.md b/contributing.md index cb05eee7..6bca3178 100644 --- a/contributing.md +++ b/contributing.md @@ -19,8 +19,8 @@ Suggestions and pull requests are highly encouraged! Have a look at the [open is The simplest usage of `feature.add` is the following. This will be run instantly on all page-loads (but not on ajax loads): ```js +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init () { console.log('✨'); @@ -46,8 +46,8 @@ Here's an example using all of the possible `feature.add` options: import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function append(event: delegate.Event<MouseEvent, HTMLButtonElement>): void { event.delegateTarget.after('✨', <div className="rgh-jsx-element">Button clicked!</div>); diff --git a/package-lock.json b/package-lock.json index 67e933b9..73e44de6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7568,6 +7568,11 @@ "meow": "^5.0.0" } }, + "github-url-detection": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/github-url-detection/-/github-url-detection-1.0.0.tgz", + "integrity": "sha512-xtbyN8FNQStN3kuW3wGRJvtBfRLeNVoMtwJfA7wy8d09zDauiXlcObSBEpGKWRdMIG+gF6Hs24OAL4KuUoAhCg==" + }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", diff --git a/package.json b/package.json index 00c5838e..1c5a44f9 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "element-ready": "^4.1.1", "fit-textarea": "^2.0.0", "github-reserved-names": "^1.1.8", + "github-url-detection": "^1.0.0", "image-promise": "^7.0.0", "indent-textarea": "^2.0.1", "linkify-issues": "2.0.0-nolookbehind", diff --git a/source/features/action-used-by-link.tsx b/source/features/action-used-by-link.tsx index 553bddd9..0c2f1eba 100644 --- a/source/features/action-used-by-link.tsx +++ b/source/features/action-used-by-link.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import SearchIcon from 'octicon/search.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { const actionRepo = select('aside .octicon-repo')! diff --git a/source/features/add-tag-to-commits.tsx b/source/features/add-tag-to-commits.tsx index a13178b1..25ee53af 100644 --- a/source/features/add-tag-to-commits.tsx +++ b/source/features/add-tag-to-commits.tsx @@ -2,8 +2,8 @@ import React from 'dom-chef'; import cache from 'webext-storage-cache'; import select from 'select-dom'; import TagIcon from 'octicon/tag.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as api from '../libs/api'; import {getOwnerAndRepo, getRepoURL, getRepoGQL} from '../libs/utils'; diff --git a/source/features/batch-mark-files-as-viewed.tsx b/source/features/batch-mark-files-as-viewed.tsx index 2aaede49..05f018a4 100644 --- a/source/features/batch-mark-files-as-viewed.tsx +++ b/source/features/batch-mark-files-as-viewed.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; let previousFile: HTMLElement | undefined; diff --git a/source/features/batch-open-issues.tsx b/source/features/batch-open-issues.tsx index 10b5ade9..68c3b83c 100644 --- a/source/features/batch-open-issues.tsx +++ b/source/features/batch-open-issues.tsx @@ -2,8 +2,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; const confirmationRequiredCount = 10; diff --git a/source/features/bugs-tab.tsx b/source/features/bugs-tab.tsx index a2e52439..63e03eec 100644 --- a/source/features/bugs-tab.tsx +++ b/source/features/bugs-tab.tsx @@ -3,8 +3,8 @@ import cache from 'webext-storage-cache'; import select from 'select-dom'; import BugIcon from '@primer/octicons/build/svg/bug.svg'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as api from '../libs/api'; import SearchQuery from '../libs/search-query'; import {getRepoURL} from '../libs/utils'; diff --git a/source/features/bypass-checks.tsx b/source/features/bypass-checks.tsx index d4cb2f1f..300dbd0a 100644 --- a/source/features/bypass-checks.tsx +++ b/source/features/bypass-checks.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import fetchDom from '../libs/fetch-dom'; async function init(): Promise<void> { diff --git a/source/features/ci-link.tsx b/source/features/ci-link.tsx index 343e62fd..7ed6a78c 100644 --- a/source/features/ci-link.tsx +++ b/source/features/ci-link.tsx @@ -1,7 +1,7 @@ import './ci-link.css'; import oneTime from 'onetime'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import fetchDom from '../libs/fetch-dom'; import {getRepoURL} from '../libs/utils'; import {appendBefore} from '../libs/dom-utils'; diff --git a/source/features/clean-issue-filters.tsx b/source/features/clean-issue-filters.tsx index cbbee7c8..4df75658 100644 --- a/source/features/clean-issue-filters.tsx +++ b/source/features/clean-issue-filters.tsx @@ -1,8 +1,8 @@ import select from 'select-dom'; import cache from 'webext-storage-cache'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as api from '../libs/api'; import {getOwnerAndRepo, getRepoURL, getRepoGQL} from '../libs/utils'; diff --git a/source/features/clean-rich-text-editor.tsx b/source/features/clean-rich-text-editor.tsx index 24df9dd3..f69a8d86 100644 --- a/source/features/clean-rich-text-editor.tsx +++ b/source/features/clean-rich-text-editor.tsx @@ -1,7 +1,7 @@ import './clean-rich-text-editor.css'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function hideButtons(): void { document.body.classList.add('rgh-clean-rich-text-editor'); diff --git a/source/features/clean-sidebar.tsx b/source/features/clean-sidebar.tsx index f9927c46..0bf031ae 100644 --- a/source/features/clean-sidebar.tsx +++ b/source/features/clean-sidebar.tsx @@ -2,9 +2,8 @@ import './clean-sidebar.css'; import React from 'dom-chef'; import select from 'select-dom'; import oneTime from 'onetime'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; -import {isPR} from '../libs/page-detect'; import onReplacedElement from '../libs/on-replaced-element'; const canEditSidebar = oneTime((): boolean => select.exists('.sidebar-labels .octicon-gear')); @@ -74,7 +73,7 @@ function clean(): void { } // Reviewers - if (isPR()) { + if (pageDetect.isPR()) { cleanSection('[aria-label="Select reviewers"]'); } diff --git a/source/features/clear-pr-merge-commit-message.tsx b/source/features/clear-pr-merge-commit-message.tsx index cde6f6ea..529c0c89 100644 --- a/source/features/clear-pr-merge-commit-message.tsx +++ b/source/features/clear-pr-merge-commit-message.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import onPrMergePanelOpen from '../libs/on-pr-merge-panel-open'; function init(): void { diff --git a/source/features/clone-branch.tsx b/source/features/clone-branch.tsx index 3416afba..52d92335 100644 --- a/source/features/clone-branch.tsx +++ b/source/features/clone-branch.tsx @@ -3,9 +3,9 @@ import select from 'select-dom'; import gitBranch from 'octicon/git-branch.svg'; import delegate from 'delegate-it'; import * as textFieldEdit from 'text-field-edit'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import LoadingIcon from '../libs/icon-loading'; import {getRepoURL, getRepoGQL} from '../libs/utils'; import observeElement from '../libs/simplified-element-observer'; diff --git a/source/features/collapsible-content-button.tsx b/source/features/collapsible-content-button.tsx index 8fc7a629..ad7f176c 100644 --- a/source/features/collapsible-content-button.tsx +++ b/source/features/collapsible-content-button.tsx @@ -2,9 +2,9 @@ import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; import FoldDownIcon from 'octicon/fold-down.svg'; +import * as pageDetect from 'github-url-detection'; import * as textFieldEdit from 'text-field-edit'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; // Wraps string in at least 2 \n on each side, // as long as the field doesn't already have them. diff --git a/source/features/comments-time-machine-links.tsx b/source/features/comments-time-machine-links.tsx index 6e67e19f..0a5a3c7b 100644 --- a/source/features/comments-time-machine-links.tsx +++ b/source/features/comments-time-machine-links.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import ClockIcon from 'octicon/clock.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoURL} from '../libs/utils'; import {appendBefore} from '../libs/dom-utils'; diff --git a/source/features/conflict-marker.tsx b/source/features/conflict-marker.tsx index 7372c749..5d17d6ab 100644 --- a/source/features/conflict-marker.tsx +++ b/source/features/conflict-marker.tsx @@ -2,9 +2,9 @@ import './conflict-marker.css'; import React from 'dom-chef'; import select from 'select-dom'; import AlertIcon from 'octicon/alert.svg'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; interface PRConfig { number: string; diff --git a/source/features/copy-file.tsx b/source/features/copy-file.tsx index 61f16ef6..e65bc92a 100644 --- a/source/features/copy-file.tsx +++ b/source/features/copy-file.tsx @@ -1,9 +1,9 @@ import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import copyToClipboard from 'copy-text-to-clipboard'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function handleClick({delegateTarget: button}: delegate.Event<MouseEvent, HTMLButtonElement>): void { const file = button.closest('.Box, .js-gist-file-update-container')!; diff --git a/source/features/copy-on-y.tsx b/source/features/copy-on-y.tsx index 65a856aa..080d46b5 100644 --- a/source/features/copy-on-y.tsx +++ b/source/features/copy-on-y.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import copyToClipboard from 'copy-text-to-clipboard'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; const handler = ({key, target}: KeyboardEvent): void => { if (key === 'y' && (target as Element).nodeName !== 'INPUT') { diff --git a/source/features/create-release-shortcut.tsx b/source/features/create-release-shortcut.tsx index dd7512e1..f49babf1 100644 --- a/source/features/create-release-shortcut.tsx +++ b/source/features/create-release-shortcut.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { const createReleaseButton = select('a[href$="/releases/new"]:not([data-hotkey])'); diff --git a/source/features/cross-deleted-pr-branches.tsx b/source/features/cross-deleted-pr-branches.tsx index 911c6bb2..8a7cca50 100644 --- a/source/features/cross-deleted-pr-branches.tsx +++ b/source/features/cross-deleted-pr-branches.tsx @@ -1,8 +1,8 @@ import './cross-deleted-pr-branches.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {wrap} from '../libs/dom-utils'; function init(): void { diff --git a/source/features/cycle-lists-with-keyboard-shortcuts.tsx b/source/features/cycle-lists-with-keyboard-shortcuts.tsx index 8ef95fc5..36746d87 100644 --- a/source/features/cycle-lists-with-keyboard-shortcuts.tsx +++ b/source/features/cycle-lists-with-keyboard-shortcuts.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { let selectableItems: HTMLElement[] = []; diff --git a/source/features/deep-reblame.tsx b/source/features/deep-reblame.tsx index 5fe1b5fc..2276b5a8 100644 --- a/source/features/deep-reblame.tsx +++ b/source/features/deep-reblame.tsx @@ -4,9 +4,9 @@ import React from 'dom-chef'; import select from 'select-dom'; import VersionIcon from 'octicon/versions.svg'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import LoadingIcon from '../libs/icon-loading'; import {getRepoGQL, getReference, looseParseInt, getCleanPathname} from '../libs/utils'; diff --git a/source/features/default-branch-button.tsx b/source/features/default-branch-button.tsx index 4fd40e56..bc69c079 100644 --- a/source/features/default-branch-button.tsx +++ b/source/features/default-branch-button.tsx @@ -1,9 +1,8 @@ import React from 'dom-chef'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import ChevronLeftIcon from 'octicon/chevron-left.svg'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; -import {isRepoRoot} from '../libs/page-detect'; import {groupButtons} from '../libs/group-buttons'; import getDefaultBranch from '../libs/get-default-branch'; import {getRepoURL, getCurrentBranch, replaceBranch} from '../libs/utils'; @@ -18,7 +17,7 @@ async function init(): Promise<false | void> { } let url; - if (isRepoRoot()) { + if (pageDetect.isRepoRoot()) { url = `/${getRepoURL()}`; } else { url = replaceBranch(currentBranch, defaultBranch); diff --git a/source/features/deprioritize-marketplace-link.tsx b/source/features/deprioritize-marketplace-link.tsx index 72543465..9457a870 100644 --- a/source/features/deprioritize-marketplace-link.tsx +++ b/source/features/deprioritize-marketplace-link.tsx @@ -2,8 +2,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import elementReady from 'element-ready'; import domLoaded from 'dom-loaded'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; async function init(): Promise<void> { const marketPlaceLink = (await elementReady('.Header-link[href="/marketplace"]')); diff --git a/source/features/dim-bots.tsx b/source/features/dim-bots.tsx index 3bf985b8..441b476b 100644 --- a/source/features/dim-bots.tsx +++ b/source/features/dim-bots.tsx @@ -1,7 +1,7 @@ import './dim-bots.css'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { const bots = select.all([ diff --git a/source/features/discussion-links-on-repo-lists.tsx b/source/features/discussion-links-on-repo-lists.tsx index 57c69659..7dd47cee 100644 --- a/source/features/discussion-links-on-repo-lists.tsx +++ b/source/features/discussion-links-on-repo-lists.tsx @@ -1,9 +1,9 @@ import React from 'dom-chef'; import select from 'select-dom'; import IssueIcon from 'octicon/issue-opened.svg'; +import * as pageDetect from 'github-url-detection'; import PullRequestIcon from 'octicon/git-pull-request.svg'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import observeElement from '../libs/simplified-element-observer'; function init(): void { diff --git a/source/features/download-folder-button.tsx b/source/features/download-folder-button.tsx index 7ae172ee..a691dd2b 100644 --- a/source/features/download-folder-button.tsx +++ b/source/features/download-folder-button.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { const buttonGroup = select('.file-navigation .BtnGroup.float-right'); diff --git a/source/features/edit-comments-faster.tsx b/source/features/edit-comments-faster.tsx index 7f9b3a86..04615b0b 100644 --- a/source/features/edit-comments-faster.tsx +++ b/source/features/edit-comments-faster.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import PencilIcon from 'octicon/pencil.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { const menuItems = select.all('details .js-comment-edit-button:not(.rgh-edit-comment)'); diff --git a/source/features/edit-files-faster.tsx b/source/features/edit-files-faster.tsx index 135ccbb7..036bec52 100644 --- a/source/features/edit-files-faster.tsx +++ b/source/features/edit-files-faster.tsx @@ -2,8 +2,8 @@ import './edit-files-faster.css'; import React from 'dom-chef'; import select from 'select-dom'; import PencilIcon from 'octicon/pencil.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {wrap} from '../libs/dom-utils'; import getDefaultBranch from '../libs/get-default-branch'; import onFileListUpdate from '../libs/on-file-list-update'; diff --git a/source/features/edit-readme.tsx b/source/features/edit-readme.tsx index bee12891..b36b4770 100644 --- a/source/features/edit-readme.tsx +++ b/source/features/edit-readme.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import PencilIcon from 'octicon/pencil.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import getDefaultBranch from '../libs/get-default-branch'; async function init(): Promise<void | false> { diff --git a/source/features/embed-gist-inline.tsx b/source/features/embed-gist-inline.tsx index fa5e32a2..8399e10e 100644 --- a/source/features/embed-gist-inline.tsx +++ b/source/features/embed-gist-inline.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import domify from 'doma'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {isFirefox} from '../libs/utils'; const isGist = (link: HTMLAnchorElement): boolean => diff --git a/source/features/embed-gist-via-iframe.tsx b/source/features/embed-gist-via-iframe.tsx index d147c4e6..997fa637 100644 --- a/source/features/embed-gist-via-iframe.tsx +++ b/source/features/embed-gist-via-iframe.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { const embedViaScript = select<HTMLButtonElement>('.file-navigation-option [value^="<script"]')!; diff --git a/source/features/expand-all-collapsed-code.tsx b/source/features/expand-all-collapsed-code.tsx index faa35285..bdcdd8af 100644 --- a/source/features/expand-all-collapsed-code.tsx +++ b/source/features/expand-all-collapsed-code.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; const expanderSelector = '.js-expand.directional-expander'; diff --git a/source/features/expand-all-hidden-comments.tsx b/source/features/expand-all-hidden-comments.tsx index 18abdb14..3d3291a3 100644 --- a/source/features/expand-all-hidden-comments.tsx +++ b/source/features/expand-all-hidden-comments.tsx @@ -1,6 +1,6 @@ import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {looseParseInt} from '../libs/utils'; /* diff --git a/source/features/extend-diff-expander.tsx b/source/features/extend-diff-expander.tsx index da67a219..b2a1b881 100644 --- a/source/features/extend-diff-expander.tsx +++ b/source/features/extend-diff-expander.tsx @@ -1,8 +1,8 @@ import './extend-diff-expander.css'; import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function expandDiff(event: delegate.Event): void { // Skip if the user clicked directly on the icon diff --git a/source/features/extend-discussion-status-filters.tsx b/source/features/extend-discussion-status-filters.tsx index 53ddc0e3..7b4f0f9a 100644 --- a/source/features/extend-discussion-status-filters.tsx +++ b/source/features/extend-discussion-status-filters.tsx @@ -2,8 +2,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import CheckIcon from 'octicon/check.svg'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import SearchQuery from '../libs/search-query'; function addMergeLink(): void { diff --git a/source/features/faster-pr-diff-options.tsx b/source/features/faster-pr-diff-options.tsx index c26ed653..a3c897af 100644 --- a/source/features/faster-pr-diff-options.tsx +++ b/source/features/faster-pr-diff-options.tsx @@ -3,8 +3,8 @@ import select from 'select-dom'; import DiffIcon from 'octicon/diff.svg'; import BookIcon from 'octicon/book.svg'; import CheckIcon from 'octicon/check.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function createDiffStyleToggle(): DocumentFragment { const parameters = new URLSearchParams(location.search); diff --git a/source/features/file-finder-buffer.tsx b/source/features/file-finder-buffer.tsx index 744f475e..af7d5eee 100644 --- a/source/features/file-finder-buffer.tsx +++ b/source/features/file-finder-buffer.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import onetime from 'onetime'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; const getBufferField = onetime((): HTMLInputElement => ( <input diff --git a/source/features/filter-comments-by-you.tsx b/source/features/filter-comments-by-you.tsx index 569b4c23..1047bf13 100644 --- a/source/features/filter-comments-by-you.tsx +++ b/source/features/filter-comments-by-you.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getUsername} from '../libs/utils'; import SearchQuery from '../libs/search-query'; diff --git a/source/features/fit-textareas.tsx b/source/features/fit-textareas.tsx index abae22de..1a1d2891 100644 --- a/source/features/fit-textareas.tsx +++ b/source/features/fit-textareas.tsx @@ -2,8 +2,8 @@ import './fit-textareas.css'; import select from 'select-dom'; import fitTextarea from 'fit-textarea'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import onPrMergePanelOpen from '../libs/on-pr-merge-panel-open'; function inputListener(event: Event): void { diff --git a/source/features/fix-view-file-link-in-pr.tsx b/source/features/fix-view-file-link-in-pr.tsx index 567e6883..ef962a9a 100644 --- a/source/features/fix-view-file-link-in-pr.tsx +++ b/source/features/fix-view-file-link-in-pr.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function handleMenuOpening(event: delegate.Event): void { const dropdown = event.delegateTarget.nextElementSibling!; diff --git a/source/features/follow-file-renames.tsx b/source/features/follow-file-renames.tsx index 0245cd88..f035aa90 100644 --- a/source/features/follow-file-renames.tsx +++ b/source/features/follow-file-renames.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as api from '../libs/api'; import {getCleanPathname} from '../libs/utils'; diff --git a/source/features/forked-to.tsx b/source/features/forked-to.tsx index 730ef8f5..1c02803b 100644 --- a/source/features/forked-to.tsx +++ b/source/features/forked-to.tsx @@ -2,14 +2,15 @@ import './forked-to.css'; import React from 'dom-chef'; import cache from 'webext-storage-cache'; import select from 'select-dom'; +import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; + import ForkIcon from 'octicon/repo-forked.svg'; import CheckIcon from 'octicon/check.svg'; -import elementReady from 'element-ready'; import LinkExternalIcon from 'octicon/link-external.svg'; + import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import fetchDom from '../libs/fetch-dom'; -import {isForkedRepo} from '../libs/page-detect'; import {getRepoURL, getUsername, getForkedRepo} from '../libs/utils'; const getForkSourceRepo = (): string => getForkedRepo() ?? getRepoURL(); @@ -89,7 +90,7 @@ async function init(): Promise<void | false> { // Only fetch/update forks when we see a fork (on the current page or in the cache). // This avoids having to `updateCache` for every single repo you visit. - if (forks || (hasOrganizations && isForkedRepo())) { + if (forks || (hasOrganizations && pageDetect.isForkedRepo())) { await updateCache(); } else { return false; diff --git a/source/features/format-discussion-titles.tsx b/source/features/format-discussion-titles.tsx index 201b78af..8a896cfb 100644 --- a/source/features/format-discussion-titles.tsx +++ b/source/features/format-discussion-titles.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import observeElement from '../libs/simplified-element-observer'; import * as domFormatters from '../libs/dom-formatters'; diff --git a/source/features/global-discussion-list-filters.tsx b/source/features/global-discussion-list-filters.tsx index 312afcff..0cd5d7fa 100644 --- a/source/features/global-discussion-list-filters.tsx +++ b/source/features/global-discussion-list-filters.tsx @@ -1,8 +1,8 @@ import './global-discussion-list-filters.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getUsername} from '../libs/utils'; import SearchQuery from '../libs/search-query'; diff --git a/source/features/go-to-action-from-file.tsx b/source/features/go-to-action-from-file.tsx index 5b290c9c..87a881df 100644 --- a/source/features/go-to-action-from-file.tsx +++ b/source/features/go-to-action-from-file.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoURL, getRepoPath} from '../libs/utils'; const isWorkflowFile = (): boolean => pageDetect.isSingleFile() && /\/\.github\/workflows\/.+\.ya?ml$/.test(getRepoPath()!); diff --git a/source/features/hidden-review-comments-indicator.tsx b/source/features/hidden-review-comments-indicator.tsx index e3837f55..ace269f9 100644 --- a/source/features/hidden-review-comments-indicator.tsx +++ b/source/features/hidden-review-comments-indicator.tsx @@ -4,8 +4,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import CommentIcon from 'octicon/comment.svg'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import anchorScroll from '../libs/anchor-scroll'; import onPrFileLoad from '../libs/on-pr-file-load'; diff --git a/source/features/hide-comments-faster.tsx b/source/features/hide-comments-faster.tsx index 10b0f4f6..f065453f 100644 --- a/source/features/hide-comments-faster.tsx +++ b/source/features/hide-comments-faster.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function generateSubmenu(hideButton: Element): void { if (hideButton.closest('.rgh-hide-comments-faster-details')) { diff --git a/source/features/hide-disabled-milestone-sorter.tsx b/source/features/hide-disabled-milestone-sorter.tsx index 2b2040ee..95bb0b0e 100644 --- a/source/features/hide-disabled-milestone-sorter.tsx +++ b/source/features/hide-disabled-milestone-sorter.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import observeElement from '../libs/simplified-element-observer'; function hide(): void { diff --git a/source/features/hide-empty-meta.tsx b/source/features/hide-empty-meta.tsx index dee0f680..3b31dfcc 100644 --- a/source/features/hide-empty-meta.tsx +++ b/source/features/hide-empty-meta.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { // Hide if it’s not editable by the current user diff --git a/source/features/hide-inactive-deployments.tsx b/source/features/hide-inactive-deployments.tsx index a6612176..17eb6879 100644 --- a/source/features/hide-inactive-deployments.tsx +++ b/source/features/hide-inactive-deployments.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import onNewComments from '../libs/on-new-comments'; function init(): void { diff --git a/source/features/hide-issue-list-autocomplete.tsx b/source/features/hide-issue-list-autocomplete.tsx index baf73d40..594304c2 100644 --- a/source/features/hide-issue-list-autocomplete.tsx +++ b/source/features/hide-issue-list-autocomplete.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { select('.subnav-search')!.setAttribute('autocomplete', 'off'); diff --git a/source/features/hide-own-stars.tsx b/source/features/hide-own-stars.tsx index b0d595b4..f3b5a7bb 100644 --- a/source/features/hide-own-stars.tsx +++ b/source/features/hide-own-stars.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getUsername} from '../libs/utils'; async function init(): Promise<void> { diff --git a/source/features/hide-useless-comments.tsx b/source/features/hide-useless-comments.tsx index fec02aa9..07556acc 100644 --- a/source/features/hide-useless-comments.tsx +++ b/source/features/hide-useless-comments.tsx @@ -2,8 +2,8 @@ import './hide-useless-comments.css'; import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { let uselessCount = 0; diff --git a/source/features/hide-useless-newsfeed-events.tsx b/source/features/hide-useless-newsfeed-events.tsx index b3a295fc..13b750f6 100644 --- a/source/features/hide-useless-newsfeed-events.tsx +++ b/source/features/hide-useless-newsfeed-events.tsx @@ -1,6 +1,6 @@ import './hide-useless-newsfeed-events.css'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { document.body.classList.add('rgh-no-useless-events'); diff --git a/source/features/hide-watch-and-fork-count.tsx b/source/features/hide-watch-and-fork-count.tsx index ab85b645..38874c03 100644 --- a/source/features/hide-watch-and-fork-count.tsx +++ b/source/features/hide-watch-and-fork-count.tsx @@ -1,6 +1,6 @@ import './hide-watch-and-fork-count.css'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { document.body.classList.add('rgh-hide-watch-and-fork-count'); diff --git a/source/features/hide-zero-packages.tsx b/source/features/hide-zero-packages.tsx index e71ba82e..750c111f 100644 --- a/source/features/hide-zero-packages.tsx +++ b/source/features/hide-zero-packages.tsx @@ -1,6 +1,6 @@ import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; async function init(): Promise<void> { const packagesCounter = await elementReady([ diff --git a/source/features/highest-rated-comment.tsx b/source/features/highest-rated-comment.tsx index 1c872048..bec1b2c2 100644 --- a/source/features/highest-rated-comment.tsx +++ b/source/features/highest-rated-comment.tsx @@ -2,8 +2,8 @@ import './highest-rated-comment.css'; import React from 'dom-chef'; import select from 'select-dom'; import ArrowDownIcon from 'octicon/arrow-down.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {looseParseInt} from '../libs/utils'; // `.js-timeline-item` gets the nearest comment excluding the very first comment (OP post) diff --git a/source/features/highlight-collaborators-and-own-discussions.tsx b/source/features/highlight-collaborators-and-own-discussions.tsx index 2f7bdb54..998480f9 100644 --- a/source/features/highlight-collaborators-and-own-discussions.tsx +++ b/source/features/highlight-collaborators-and-own-discussions.tsx @@ -1,7 +1,7 @@ import './highlight-collaborators-and-own-discussions.css'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoURL, getUsername} from '../libs/utils'; import fetchDom from '../libs/fetch-dom'; diff --git a/source/features/html-preview-link.tsx b/source/features/html-preview-link.tsx index 6780b9c0..7160627a 100644 --- a/source/features/html-preview-link.tsx +++ b/source/features/html-preview-link.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; const isSingleHTMLFile = (): boolean => pageDetect.isSingleFile() && (location.pathname.endsWith('.html') || location.pathname.endsWith('.htm')); diff --git a/source/features/indented-code-wrapping.tsx b/source/features/indented-code-wrapping.tsx index 4aae2035..f399623e 100644 --- a/source/features/indented-code-wrapping.tsx +++ b/source/features/indented-code-wrapping.tsx @@ -1,7 +1,7 @@ import './indented-code-wrapping.css'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import onPrFileLoad from '../libs/on-pr-file-load'; import onNewComments from '../libs/on-new-comments'; diff --git a/source/features/infinite-scroll.tsx b/source/features/infinite-scroll.tsx index 6ffb2cc7..7b58d774 100644 --- a/source/features/infinite-scroll.tsx +++ b/source/features/infinite-scroll.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; import debounce from 'debounce-fn'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; let button: HTMLButtonElement | undefined; diff --git a/source/features/latest-tag-button.tsx b/source/features/latest-tag-button.tsx index 2e73d2a9..281e8d8c 100644 --- a/source/features/latest-tag-button.tsx +++ b/source/features/latest-tag-button.tsx @@ -4,11 +4,10 @@ import cache from 'webext-storage-cache'; import select from 'select-dom'; import TagIcon from 'octicon/tag.svg'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import fetchDom from '../libs/fetch-dom'; -import {isRepoRoot} from '../libs/page-detect'; import getDefaultBranch from '../libs/get-default-branch'; import {getRepoURL, getCurrentBranch, replaceBranch, getRepoGQL, getLatestVersionTag} from '../libs/utils'; @@ -92,7 +91,7 @@ async function init(): Promise<false | void> { const currentBranch = getCurrentBranch(); let href: string; - if (isRepoRoot()) { + if (pageDetect.isRepoRoot()) { href = `/${getRepoURL()}/tree/${latestTag}`; } else { href = replaceBranch(currentBranch, latestTag); diff --git a/source/features/link-to-file-in-file-history.tsx b/source/features/link-to-file-in-file-history.tsx index 0f763fb5..f7fe9120 100644 --- a/source/features/link-to-file-in-file-history.tsx +++ b/source/features/link-to-file-in-file-history.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import FileIcon from 'octicon/file.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {groupSiblings} from '../libs/group-buttons'; function init(): void | false { diff --git a/source/features/link-to-prior-blame-line.tsx b/source/features/link-to-prior-blame-line.tsx index ad087b5b..b15ab005 100644 --- a/source/features/link-to-prior-blame-line.tsx +++ b/source/features/link-to-prior-blame-line.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { for (const link of select.all<HTMLAnchorElement>('.reblame-link')) { diff --git a/source/features/linkify-branch-references.tsx b/source/features/linkify-branch-references.tsx index 72c41b53..2bbdf1c0 100644 --- a/source/features/linkify-branch-references.tsx +++ b/source/features/linkify-branch-references.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoURL} from '../libs/utils'; import {wrap} from '../libs/dom-utils'; diff --git a/source/features/linkify-code.tsx b/source/features/linkify-code.tsx index 29ae677e..e65cb15d 100644 --- a/source/features/linkify-code.tsx +++ b/source/features/linkify-code.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {linkifiedURLClass, linkifyURLs, linkifyIssues} from '../libs/dom-formatters'; function init(): false | void { diff --git a/source/features/linkify-commit-sha.tsx b/source/features/linkify-commit-sha.tsx index 99928822..f4d73cd7 100644 --- a/source/features/linkify-commit-sha.tsx +++ b/source/features/linkify-commit-sha.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import {wrap} from '../libs/dom-utils'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { const element = select('.sha.user-select-contain'); diff --git a/source/features/linkify-labels-on-dashboard.tsx b/source/features/linkify-labels-on-dashboard.tsx index ae04c836..b8914aa8 100644 --- a/source/features/linkify-labels-on-dashboard.tsx +++ b/source/features/linkify-labels-on-dashboard.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {wrap} from '../libs/dom-utils'; async function init(): Promise<void> { diff --git a/source/features/linkify-notification-repository-header.tsx b/source/features/linkify-notification-repository-header.tsx index 4af32884..21c4885b 100644 --- a/source/features/linkify-notification-repository-header.tsx +++ b/source/features/linkify-notification-repository-header.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { for (const header of select.all('.js-notifications-group h6')) { diff --git a/source/features/linkify-symbolic-links.tsx b/source/features/linkify-symbolic-links.tsx index 1c6810b2..6bf38163 100644 --- a/source/features/linkify-symbolic-links.tsx +++ b/source/features/linkify-symbolic-links.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import {wrap} from '../libs/dom-utils'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void | false { const mode = select('.file-mode'); diff --git a/source/features/list-prs-for-file.tsx b/source/features/list-prs-for-file.tsx index 8f2304b7..085a75b8 100644 --- a/source/features/list-prs-for-file.tsx +++ b/source/features/list-prs-for-file.tsx @@ -1,12 +1,11 @@ import React from 'dom-chef'; import select from 'select-dom'; import cache from 'webext-storage-cache'; +import * as pageDetect from 'github-url-detection'; import PullRequestIcon from 'octicon/git-pull-request.svg'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoURL, getRepoGQL} from '../libs/utils'; -import {isEditingFile} from '../libs/page-detect'; import getDefaultBranch from '../libs/get-default-branch'; function getPRUrl(prNumber: number): string { @@ -58,7 +57,7 @@ async function init(): Promise<void> { const [prNumber] = prs; // First one or only one - if (isEditingFile()) { + if (pageDetect.isEditingFile()) { select('.file')!.after( <div className="form-warning p-3 mb-3 mx-lg-3"> { diff --git a/source/features/mark-merge-commits-in-list.tsx b/source/features/mark-merge-commits-in-list.tsx index 4c53a4b9..896b3510 100644 --- a/source/features/mark-merge-commits-in-list.tsx +++ b/source/features/mark-merge-commits-in-list.tsx @@ -1,10 +1,10 @@ import './mark-merge-commits-in-list.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import PullRequestIcon from 'octicon/git-pull-request.svg'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoGQL} from '../libs/utils'; const filterMergeCommits = async (commits: string[]): Promise<string[]> => { diff --git a/source/features/mark-private-orgs.tsx b/source/features/mark-private-orgs.tsx index 18a91384..37c01c98 100644 --- a/source/features/mark-private-orgs.tsx +++ b/source/features/mark-private-orgs.tsx @@ -3,9 +3,9 @@ import React from 'dom-chef'; import cache from 'webext-storage-cache'; import select from 'select-dom'; import EyeClosedIcon from 'octicon/eye-closed.svg'; +import * as pageDetect from 'github-url-detection'; import {getUsername} from '../libs/utils'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as api from '../libs/api'; const getPublicOrganizationsNames = cache.function(async (username: string): Promise<string[]> => { diff --git a/source/features/mark-unread.tsx b/source/features/mark-unread.tsx index e35bdf7e..ec0456e8 100644 --- a/source/features/mark-unread.tsx +++ b/source/features/mark-unread.tsx @@ -4,6 +4,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; + import XIcon from 'octicon/x.svg'; import InfoIcon from 'octicon/info.svg'; import CheckIcon from 'octicon/check.svg'; @@ -11,8 +13,8 @@ import MergeIcon from 'octicon/git-merge.svg'; import IssueOpenedIcon from 'octicon/issue-opened.svg'; import IssueClosedIcon from 'octicon/issue-closed.svg'; import PullRequestIcon from 'octicon/git-pull-request.svg'; + import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import onReplacedElement from '../libs/on-replaced-element'; import {getUsername, getRepoURL, logError} from '../libs/utils'; diff --git a/source/features/minimize-upload-bar.tsx b/source/features/minimize-upload-bar.tsx index f94000e4..1a7b777b 100644 --- a/source/features/minimize-upload-bar.tsx +++ b/source/features/minimize-upload-bar.tsx @@ -3,8 +3,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import CloudUploadIcon from 'octicon/cloud-upload.svg'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function addButton(): void { for (const toolbarButton of select.all('md-ref')) { diff --git a/source/features/more-dropdown.tsx b/source/features/more-dropdown.tsx index a735873c..94315cd6 100644 --- a/source/features/more-dropdown.tsx +++ b/source/features/more-dropdown.tsx @@ -2,14 +2,15 @@ import './more-dropdown.css'; import React from 'dom-chef'; import select from 'select-dom'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; + import DiffIcon from 'octicon/diff.svg'; import BranchIcon from 'octicon/git-branch.svg'; import HistoryIcon from 'octicon/history.svg'; import PackageIcon from 'octicon/package.svg'; + import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoURL, getReference} from '../libs/utils'; -import {isEnterprise} from '../libs/page-detect'; import {appendBefore} from '../libs/dom-utils'; const repoUrl = getRepoURL(); @@ -48,7 +49,7 @@ async function init(): Promise<void> { <DiffIcon/> Compare </a>, - isEnterprise() ? '' : ( + pageDetect.isEnterprise() ? '' : ( <a href={`/${repoUrl}/network/dependencies`} className="rgh-reponav-more dropdown-item"> <PackageIcon/> Dependencies </a> diff --git a/source/features/open-all-notifications.tsx b/source/features/open-all-notifications.tsx index 6efa8706..26089f50 100644 --- a/source/features/open-all-notifications.tsx +++ b/source/features/open-all-notifications.tsx @@ -3,8 +3,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import LinkExternalIcon from 'octicon/link-external.svg'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; const confirmationRequiredCount = 10; diff --git a/source/features/open-ci-details-in-new-tab.tsx b/source/features/open-ci-details-in-new-tab.tsx index f3c6acfd..2cdad6f6 100644 --- a/source/features/open-ci-details-in-new-tab.tsx +++ b/source/features/open-ci-details-in-new-tab.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { const CIDetailsLinks = select.all('a.status-actions'); diff --git a/source/features/open-issue-to-latest-comment.tsx b/source/features/open-issue-to-latest-comment.tsx index 88c22fa1..65a9eff4 100644 --- a/source/features/open-issue-to-latest-comment.tsx +++ b/source/features/open-issue-to-latest-comment.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { for (const link of select.all<HTMLAnchorElement>('.js-issue-row a[aria-label*="comment"], .js-pinned-issue-list-item a[aria-label*="comment"]')) { diff --git a/source/features/parse-backticks.tsx b/source/features/parse-backticks.tsx index dd1a701b..7cd3deaa 100644 --- a/source/features/parse-backticks.tsx +++ b/source/features/parse-backticks.tsx @@ -1,7 +1,7 @@ import './parse-backticks.css'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {parseBackticks} from '../libs/dom-formatters'; function init(): void { diff --git a/source/features/patch-diff-links.tsx b/source/features/patch-diff-links.tsx index c82618cd..4771be49 100644 --- a/source/features/patch-diff-links.tsx +++ b/source/features/patch-diff-links.tsx @@ -1,14 +1,13 @@ import './patch-diff-links.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; -import {isPRCommit} from '../libs/page-detect'; function init(): void { let commitUrl = location.pathname.replace(/\/$/, ''); - if (isPRCommit()) { + if (pageDetect.isPRCommit()) { commitUrl = commitUrl.replace(/\/pull\/\d+\/commits/, '/commit'); } diff --git a/source/features/pinned-issues-update-time.tsx b/source/features/pinned-issues-update-time.tsx index 1dee9eae..ca756d01 100644 --- a/source/features/pinned-issues-update-time.tsx +++ b/source/features/pinned-issues-update-time.tsx @@ -2,9 +2,9 @@ import React from 'dom-chef'; import cache from 'webext-storage-cache'; import select from 'select-dom'; import ClockIcon from 'octicon/clock.svg'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoGQL, getRepoURL, looseParseInt} from '../libs/utils'; interface IssueInfo { diff --git a/source/features/pr-branch-auto-delete.tsx b/source/features/pr-branch-auto-delete.tsx index 1facd486..fc16c7b3 100644 --- a/source/features/pr-branch-auto-delete.tsx +++ b/source/features/pr-branch-auto-delete.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import observeElement from '../libs/simplified-element-observer'; function init(): void { diff --git a/source/features/pr-branches.tsx b/source/features/pr-branches.tsx index 396d1026..462fe653 100644 --- a/source/features/pr-branches.tsx +++ b/source/features/pr-branches.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import PullRequestIcon from 'octicon/git-pull-request.svg'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as api from '../libs/api'; import getDefaultBranch from '../libs/get-default-branch'; import {getOwnerAndRepo, getRepoGQL} from '../libs/utils'; diff --git a/source/features/pr-commit-lines-changed.tsx b/source/features/pr-commit-lines-changed.tsx index dbf3ea57..b399afc6 100644 --- a/source/features/pr-commit-lines-changed.tsx +++ b/source/features/pr-commit-lines-changed.tsx @@ -2,9 +2,9 @@ import React from 'dom-chef'; import cache from 'webext-storage-cache'; import select from 'select-dom'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoGQL, pluralize} from '../libs/utils'; const getCommitChanges = cache.function(async (commit: string): Promise<[number, number]> => { diff --git a/source/features/pr-filters.tsx b/source/features/pr-filters.tsx index 6dc1e8c1..8def9604 100644 --- a/source/features/pr-filters.tsx +++ b/source/features/pr-filters.tsx @@ -4,8 +4,8 @@ import delegate from 'delegate-it'; import cache from 'webext-storage-cache'; import CheckIcon from 'octicon/check.svg'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as api from '../libs/api'; import {getRepoGQL, getRepoURL} from '../libs/utils'; diff --git a/source/features/preserve-file-finder-term.tsx b/source/features/preserve-file-finder-term.tsx index 74baff20..0d583c8d 100644 --- a/source/features/preserve-file-finder-term.tsx +++ b/source/features/preserve-file-finder-term.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function unloadHandler(): void { const inputElement = select<HTMLInputElement>('#tree-finder-field'); diff --git a/source/features/preserve-whitespace-option-in-nav.tsx b/source/features/preserve-whitespace-option-in-nav.tsx index 8ac96542..c224e7fd 100644 --- a/source/features/preserve-whitespace-option-in-nav.tsx +++ b/source/features/preserve-whitespace-option-in-nav.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): false | void { if (new URLSearchParams(location.search).get('w') !== '1') { diff --git a/source/features/preview-hidden-comments.tsx b/source/features/preview-hidden-comments.tsx index 3c307a87..441aacd9 100644 --- a/source/features/preview-hidden-comments.tsx +++ b/source/features/preview-hidden-comments.tsx @@ -1,8 +1,8 @@ import './preview-hidden-comments.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; const allowedReasons = ['resolved', 'outdated', 'off-topic']; diff --git a/source/features/previous-next-commit-buttons.tsx b/source/features/previous-next-commit-buttons.tsx index 206ac676..b78fb3a6 100644 --- a/source/features/previous-next-commit-buttons.tsx +++ b/source/features/previous-next-commit-buttons.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): false | void { const originalPreviousNext = select('.commit .BtnGroup.float-right'); diff --git a/source/features/profile-gists-link.tsx b/source/features/profile-gists-link.tsx index 65b87f97..5f124862 100644 --- a/source/features/profile-gists-link.tsx +++ b/source/features/profile-gists-link.tsx @@ -3,11 +3,10 @@ import React from 'dom-chef'; import cache from 'webext-storage-cache'; import select from 'select-dom'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getCleanPathname} from '../libs/utils'; -import {isEnterprise} from '../libs/page-detect'; const getGistCount = cache.function(async (username: string): Promise<number> => { const {user} = await api.v4(` @@ -26,7 +25,7 @@ async function init(): Promise<false | void> { await elementReady('.UnderlineNav-body + *'); const username = getCleanPathname(); - const href = isEnterprise() ? `/gist/${username}` : `https://gist.github.com/${username}`; + const href = pageDetect.isEnterprise() ? `/gist/${username}` : `https://gist.github.com/${username}`; const link = <a href={href} className="UnderlineNav-item" role="tab" aria-selected="false">Gists </a>; select('.UnderlineNav-body')!.append(link); diff --git a/source/features/pull-request-hotkey.tsx b/source/features/pull-request-hotkey.tsx index efe7994d..850dbc9d 100644 --- a/source/features/pull-request-hotkey.tsx +++ b/source/features/pull-request-hotkey.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { const tabs = select.all('.tabnav-pr .tabnav-tab'); diff --git a/source/features/quick-mention.tsx b/source/features/quick-mention.tsx index 9484e773..0d1c2340 100644 --- a/source/features/quick-mention.tsx +++ b/source/features/quick-mention.tsx @@ -3,9 +3,9 @@ import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; import ReplyIcon from 'octicon/reply.svg'; +import * as pageDetect from 'github-url-detection'; import * as textFieldEdit from 'text-field-edit'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getUsername} from '../libs/utils'; import onNewComments from '../libs/on-new-comments'; diff --git a/source/features/quick-review-buttons.tsx b/source/features/quick-review-buttons.tsx index 92912dc3..033b8fc9 100644 --- a/source/features/quick-review-buttons.tsx +++ b/source/features/quick-review-buttons.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): false | void { const form = select('[action$="/reviews"]')!; diff --git a/source/features/raw-file-link.tsx b/source/features/raw-file-link.tsx index 3b8b3369..037c5b9f 100644 --- a/source/features/raw-file-link.tsx +++ b/source/features/raw-file-link.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function handleMenuOpening(event: delegate.Event): void { const dropdown = event.delegateTarget.nextElementSibling!; diff --git a/source/features/reactions-avatars.tsx b/source/features/reactions-avatars.tsx index c405da40..4cfeeb48 100644 --- a/source/features/reactions-avatars.tsx +++ b/source/features/reactions-avatars.tsx @@ -1,8 +1,8 @@ import './reactions-avatars.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getUsername, flatZip, isFirefox} from '../libs/utils'; import onReplacedElement from '../libs/on-replaced-element'; diff --git a/source/features/recently-pushed-branches-enhancements.tsx b/source/features/recently-pushed-branches-enhancements.tsx index b5d10d9a..4bfaa9a9 100644 --- a/source/features/recently-pushed-branches-enhancements.tsx +++ b/source/features/recently-pushed-branches-enhancements.tsx @@ -1,10 +1,9 @@ import './recently-pushed-branches-enhancements.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoURL} from '../libs/utils'; -import {isRepoRoot} from '../libs/page-detect'; const fragmentURL = `/${getRepoURL()}/show_partial?partial=tree%2Frecently_touched_branches_list`; const selector = `[data-url='${fragmentURL}' i], [src='${fragmentURL}' i]`; @@ -20,7 +19,7 @@ function removeDuplicateList(): void { } async function getWidget(): Promise<HTMLElement | false> { - if (isRepoRoot()) { + if (pageDetect.isRepoRoot()) { return select(selector)!; } diff --git a/source/features/release-download-count.tsx b/source/features/release-download-count.tsx index a39c59b8..a2d454ff 100644 --- a/source/features/release-download-count.tsx +++ b/source/features/release-download-count.tsx @@ -1,9 +1,9 @@ import './release-download-count.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import CloudDownloadIcon from 'octicon/cloud-download.svg'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as api from '../libs/api'; import {getRepoGQL} from '../libs/utils'; diff --git a/source/features/releases-tab.tsx b/source/features/releases-tab.tsx index 8a409ad2..c68981f9 100644 --- a/source/features/releases-tab.tsx +++ b/source/features/releases-tab.tsx @@ -3,18 +3,17 @@ import React from 'dom-chef'; import select from 'select-dom'; import elementReady from 'element-ready'; import TagIcon from 'octicon/tag.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as api from '../libs/api'; import {appendBefore} from '../libs/dom-utils'; import {getRepoURL, getRepoGQL, looseParseInt} from '../libs/utils'; -import {isRepoRoot, isReleasesOrTags} from '../libs/page-detect'; const repoUrl = getRepoURL(); const cacheKey = `releases-count:${repoUrl}`; function parseCountFromDom(): number | false { - if (isRepoRoot()) { + if (pageDetect.isRepoRoot()) { const releasesCountElement = select('.numbers-summary a[href$="/releases"] .num'); return Number(releasesCountElement ? looseParseInt(releasesCountElement.textContent!) : 0); } @@ -42,7 +41,7 @@ const getReleaseCount = cache.function(async () => parseCountFromDom() ?? fetchF async function init(): Promise<false | void> { // Always prefer the information in the DOM - if (isRepoRoot()) { + if (pageDetect.isRepoRoot()) { await cache.delete(cacheKey); } @@ -63,7 +62,7 @@ async function init(): Promise<false | void> { appendBefore('.reponav', '.reponav-dropdown, [data-selected-links^="repo_settings"]', releasesTab); // Update "selected" tab mark - if (isReleasesOrTags()) { + if (pageDetect.isReleasesOrTags()) { const selected = select('.reponav-item.selected'); if (selected) { selected.classList.remove('js-selected-navigation-item', 'selected'); diff --git a/source/features/remove-checks-tab.tsx b/source/features/remove-checks-tab.tsx index 6e5b8171..f35224aa 100644 --- a/source/features/remove-checks-tab.tsx +++ b/source/features/remove-checks-tab.tsx @@ -3,8 +3,8 @@ */ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): false | void { // If there's a settings tab, the current user can enable checks, diff --git a/source/features/remove-projects-tab.tsx b/source/features/remove-projects-tab.tsx index 0f083577..94179707 100644 --- a/source/features/remove-projects-tab.tsx +++ b/source/features/remove-projects-tab.tsx @@ -2,18 +2,17 @@ import React from 'dom-chef'; import select from 'select-dom'; import onetime from 'onetime'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; -import {isUserProfile, isOwnOrganizationProfile, isOrganizationProfile} from '../libs/page-detect'; const addNewProjectLink = onetime(() => { - if (isUserProfile()) { + if (pageDetect.isUserProfile()) { // The link already exists on our profile, // and we can't create projects on others' profiles return; } - if (isOrganizationProfile() && !isOwnOrganizationProfile()) { + if (pageDetect.isOrganizationProfile() && !pageDetect.isOwnOrganizationProfile()) { // We can only add projects to our organizations return; } diff --git a/source/features/remove-upload-files-button.tsx b/source/features/remove-upload-files-button.tsx index 09e1893a..aac65a97 100644 --- a/source/features/remove-upload-files-button.tsx +++ b/source/features/remove-upload-files-button.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoURL} from '../libs/utils'; function init(): false | void { diff --git a/source/features/repo-age.tsx b/source/features/repo-age.tsx index ffedcd55..3cd5092d 100644 --- a/source/features/repo-age.tsx +++ b/source/features/repo-age.tsx @@ -4,8 +4,8 @@ import cache from 'webext-storage-cache'; import select from 'select-dom'; import RepoIcon from 'octicon/repo.svg'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import fetchDom from '../libs/fetch-dom'; import {getRepoURL, looseParseInt} from '../libs/utils'; diff --git a/source/features/repo-wide-file-finder.tsx b/source/features/repo-wide-file-finder.tsx index acfb4681..f1fe5a9a 100644 --- a/source/features/repo-wide-file-finder.tsx +++ b/source/features/repo-wide-file-finder.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoURL} from '../libs/utils'; import getDefaultBranch from '../libs/get-default-branch'; diff --git a/source/features/resolve-conflicts.tsx b/source/features/resolve-conflicts.tsx index b5320e6f..4b08a052 100644 --- a/source/features/resolve-conflicts.tsx +++ b/source/features/resolve-conflicts.tsx @@ -1,8 +1,8 @@ import './resolve-conflicts.css'; import React from 'dom-chef'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; async function init(): Promise<void> { await elementReady('.CodeMirror', { diff --git a/source/features/revert-file.tsx b/source/features/revert-file.tsx index 45d4299a..4423dcd1 100644 --- a/source/features/revert-file.tsx +++ b/source/features/revert-file.tsx @@ -2,9 +2,9 @@ import React from 'dom-chef'; import select from 'select-dom'; import onetime from 'onetime'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import fetchDom from '../libs/fetch-dom'; import postForm from '../libs/post-form'; import {getDiscussionNumber, getRepoGQL, getRepoURL, getCurrentBranch} from '../libs/utils'; diff --git a/source/features/separate-draft-pr-button.tsx b/source/features/separate-draft-pr-button.tsx index 1ff47aa0..c5cc79ac 100644 --- a/source/features/separate-draft-pr-button.tsx +++ b/source/features/separate-draft-pr-button.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void | false { const previewForm = select('.new-pr-form'); diff --git a/source/features/shorten-links.tsx b/source/features/shorten-links.tsx index cf02dfa7..44a67404 100644 --- a/source/features/shorten-links.tsx +++ b/source/features/shorten-links.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; import {applyToLink} from 'shorten-repo-url'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {linkifiedURLClass} from '../libs/dom-formatters'; function init(): void { diff --git a/source/features/show-followers-you-know.tsx b/source/features/show-followers-you-know.tsx index db94cc85..c5f031e6 100644 --- a/source/features/show-followers-you-know.tsx +++ b/source/features/show-followers-you-know.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import {getCleanPathname} from '../libs/utils'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import fetchDom from '../libs/fetch-dom'; const fetchStargazers = async (): Promise<HTMLImageElement[]> => { diff --git a/source/features/show-names.tsx b/source/features/show-names.tsx index 3d92f366..270d9ce6 100644 --- a/source/features/show-names.tsx +++ b/source/features/show-names.tsx @@ -1,9 +1,9 @@ import './show-names.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getUsername, compareNames} from '../libs/utils'; async function init(): Promise<false | void> { diff --git a/source/features/show-open-prs-of-forks.tsx b/source/features/show-open-prs-of-forks.tsx index 9cd656f9..beb0d466 100644 --- a/source/features/show-open-prs-of-forks.tsx +++ b/source/features/show-open-prs-of-forks.tsx @@ -2,10 +2,9 @@ import React from 'dom-chef'; import cache from 'webext-storage-cache'; import select from 'select-dom'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; -import {isForkedRepo, isRepoWithAccess} from '../libs/page-detect'; import {getForkedRepo, getUsername, pluralize} from '../libs/utils'; function getLinkCopy(count: number): string { @@ -43,7 +42,7 @@ const countPRs = cache.function(async (forkedRepo: string): Promise<[number, num async function getPRs(): Promise<[number, string] | []> { await elementReady('.repohead + *'); // Wait for the tab bar to be loaded - if (!isRepoWithAccess()) { + if (!pageDetect.isRepoWithAccess()) { return []; } @@ -89,7 +88,7 @@ features.add({ pageDetect.isRepo ], exclude: [ - () => !isForkedRepo() + () => !pageDetect.isForkedRepo() ], waitForDomReady: false, init: initHeadHint @@ -98,7 +97,7 @@ features.add({ pageDetect.isRepoSettings ], exclude: [ - () => !isForkedRepo() + () => !pageDetect.isForkedRepo() ], waitForDomReady: false, init: initDeleteHint diff --git a/source/features/show-user-top-repositories.tsx b/source/features/show-user-top-repositories.tsx index bd217f96..5a71bf1e 100644 --- a/source/features/show-user-top-repositories.tsx +++ b/source/features/show-user-top-repositories.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getCleanPathname} from '../libs/utils'; function buildUrl(queryField: string): URL { diff --git a/source/features/show-whitespace.tsx b/source/features/show-whitespace.tsx index 18b9aa80..56ca145b 100644 --- a/source/features/show-whitespace.tsx +++ b/source/features/show-whitespace.tsx @@ -1,8 +1,8 @@ import './show-whitespace.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import getTextNodes from '../libs/get-text-nodes'; import onPrFileLoad from '../libs/on-pr-file-load'; import onNewComments from '../libs/on-new-comments'; diff --git a/source/features/sort-issues-by-update-time.tsx b/source/features/sort-issues-by-update-time.tsx index 66f23c85..4e6117c5 100644 --- a/source/features/sort-issues-by-update-time.tsx +++ b/source/features/sort-issues-by-update-time.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import SearchQuery from '../libs/search-query'; function init(): void { diff --git a/source/features/sort-milestones-by-closest-due-date.tsx b/source/features/sort-milestones-by-closest-due-date.tsx index f9807cc8..a935368c 100644 --- a/source/features/sort-milestones-by-closest-due-date.tsx +++ b/source/features/sort-milestones-by-closest-due-date.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { for (const a of select.all<HTMLAnchorElement>('a[href$="/milestones"], a[href*="/milestones?"]')) { diff --git a/source/features/split-issue-pr-search-results.tsx b/source/features/split-issue-pr-search-results.tsx index b0c52716..84b29f31 100644 --- a/source/features/split-issue-pr-search-results.tsx +++ b/source/features/split-issue-pr-search-results.tsx @@ -1,8 +1,8 @@ import './split-issue-pr-search-results.css'; import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import SearchQuery from '../libs/search-query'; function cleanLinks(): void { diff --git a/source/features/star-repo-hotkey.tsx b/source/features/star-repo-hotkey.tsx index 3c07ca63..f4a33b8b 100644 --- a/source/features/star-repo-hotkey.tsx +++ b/source/features/star-repo-hotkey.tsx @@ -1,6 +1,6 @@ import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; function init(): void { // There are two buttons: unstar and star diff --git a/source/features/sticky-discussion-sidebar.tsx b/source/features/sticky-discussion-sidebar.tsx index 854a132e..abbf7738 100644 --- a/source/features/sticky-discussion-sidebar.tsx +++ b/source/features/sticky-discussion-sidebar.tsx @@ -1,8 +1,8 @@ import './sticky-discussion-sidebar.css'; import select from 'select-dom'; import debounce from 'debounce-fn'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import onReplacedElement from '../libs/on-replaced-element'; const sideBarSelector = '#partial-discussion-sidebar, .discussion-sidebar'; diff --git a/source/features/submit-review-as-single-comment.tsx b/source/features/submit-review-as-single-comment.tsx index e023bf4d..ee7865ad 100644 --- a/source/features/submit-review-as-single-comment.tsx +++ b/source/features/submit-review-as-single-comment.tsx @@ -2,9 +2,9 @@ import React from 'dom-chef'; import select from 'select-dom'; import onetime from 'onetime'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import * as textFieldEdit from 'text-field-edit'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {observeOneMutation} from '../libs/simplified-element-observer'; import {logError} from '../libs/utils'; import oneEvent from '../libs/one-event'; diff --git a/source/features/suggest-commit-title-limit.tsx b/source/features/suggest-commit-title-limit.tsx index fd2d54d8..469dced3 100644 --- a/source/features/suggest-commit-title-limit.tsx +++ b/source/features/suggest-commit-title-limit.tsx @@ -1,8 +1,8 @@ import './suggest-commit-title-limit.css'; import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import onPrMergePanelOpen from '../libs/on-pr-merge-panel-open'; const fieldSelector = [ diff --git a/source/features/swap-branches-on-compare.tsx b/source/features/swap-branches-on-compare.tsx index f9e16c70..c6851ce1 100644 --- a/source/features/swap-branches-on-compare.tsx +++ b/source/features/swap-branches-on-compare.tsx @@ -1,8 +1,8 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import {wrap} from '../libs/dom-utils'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoPath, getRepoURL} from '../libs/utils'; function init(): void { diff --git a/source/features/sync-pr-commit-title.tsx b/source/features/sync-pr-commit-title.tsx index 55207fb0..e2341122 100644 --- a/source/features/sync-pr-commit-title.tsx +++ b/source/features/sync-pr-commit-title.tsx @@ -2,8 +2,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; import * as textFieldEdit from 'text-field-edit'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {logError} from '../libs/utils'; import onPrMergePanelOpen from '../libs/on-pr-merge-panel-open'; diff --git a/source/features/tag-changelog-link.tsx b/source/features/tag-changelog-link.tsx index cce68c6a..1bff0b9f 100644 --- a/source/features/tag-changelog-link.tsx +++ b/source/features/tag-changelog-link.tsx @@ -1,11 +1,10 @@ import React from 'dom-chef'; import select from 'select-dom'; import DiffIcon from 'octicon/diff.svg'; +import * as pageDetect from 'github-url-detection'; import tinyVersionCompare from 'tiny-version-compare'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import fetchDom from '../libs/fetch-dom'; -import {isSingleTagPage} from '../libs/page-detect'; import {getRepoPath, getRepoURL, parseTag} from '../libs/utils'; type TagDetails = { @@ -22,7 +21,7 @@ async function getNextPage(): Promise<DocumentFragment> { return fetchDom(nextPageLink.href); } - if (isSingleTagPage()) { + if (pageDetect.isSingleTagPage()) { const [, tag = ''] = getRepoPath()!.split('releases/tag/', 2); // Already URL-encoded return fetchDom(`/${getRepoURL()}/tags?after=${tag}`); } diff --git a/source/features/tags-dropdown.tsx b/source/features/tags-dropdown.tsx index c88d7efd..e3724af0 100644 --- a/source/features/tags-dropdown.tsx +++ b/source/features/tags-dropdown.tsx @@ -2,8 +2,8 @@ import './tags-dropdown.css'; import React from 'dom-chef'; import select from 'select-dom'; import OctofaceIcon from 'octicon/octoface.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getRepoURL} from '../libs/utils'; function init(): false | void { diff --git a/source/features/toggle-everything-with-alt.tsx b/source/features/toggle-everything-with-alt.tsx index fc0d9f5f..2eaa63ea 100644 --- a/source/features/toggle-everything-with-alt.tsx +++ b/source/features/toggle-everything-with-alt.tsx @@ -1,8 +1,8 @@ import mem from 'mem'; import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import anchorScroll from '../libs/anchor-scroll'; type EventHandler = (event: delegate.Event<MouseEvent, HTMLElement>) => void; diff --git a/source/features/toggle-files-button.tsx b/source/features/toggle-files-button.tsx index 5cf9342e..e1133640 100644 --- a/source/features/toggle-files-button.tsx +++ b/source/features/toggle-files-button.tsx @@ -2,9 +2,9 @@ import './toggle-files-button.css'; import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import ChevronDownIcon from 'octicon/chevron-down.svg'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import observeElement from '../libs/simplified-element-observer'; function addButton(): void { diff --git a/source/features/trending-menu-item.tsx b/source/features/trending-menu-item.tsx index cb4547b2..83f43307 100644 --- a/source/features/trending-menu-item.tsx +++ b/source/features/trending-menu-item.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; async function init(): Promise<false | void> { const exploreLink = await elementReady('.Header-link[href="/explore"]'); diff --git a/source/features/unwrap-useless-dropdowns.tsx b/source/features/unwrap-useless-dropdowns.tsx index 51140f10..a429c14e 100644 --- a/source/features/unwrap-useless-dropdowns.tsx +++ b/source/features/unwrap-useless-dropdowns.tsx @@ -1,7 +1,7 @@ import select from 'select-dom'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; // Replace dropdown while keeping its sizing/positioning classes function replaceDropdownInPlace(dropdown: Element, form: Element): void { diff --git a/source/features/update-pr-from-base-branch.tsx b/source/features/update-pr-from-base-branch.tsx index 5ab5c9d4..945c962c 100644 --- a/source/features/update-pr-from-base-branch.tsx +++ b/source/features/update-pr-from-base-branch.tsx @@ -2,8 +2,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import AlertIcon from 'octicon/alert.svg'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as api from '../libs/api'; import observeElement from '../libs/simplified-element-observer'; import {getRepoURL, getDiscussionNumber} from '../libs/utils'; diff --git a/source/features/useful-not-found-page.tsx b/source/features/useful-not-found-page.tsx index b2ce781b..711f2954 100644 --- a/source/features/useful-not-found-page.tsx +++ b/source/features/useful-not-found-page.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getCleanPathname} from '../libs/utils'; import getDefaultBranch from '../libs/get-default-branch'; diff --git a/source/features/user-profile-follower-badge.tsx b/source/features/user-profile-follower-badge.tsx index 06a23d34..89e913f4 100644 --- a/source/features/user-profile-follower-badge.tsx +++ b/source/features/user-profile-follower-badge.tsx @@ -2,9 +2,9 @@ import './user-profile-follower-badge.css'; import React from 'dom-chef'; import cache from 'webext-storage-cache'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import {getUsername, getCleanPathname} from '../libs/utils'; const doesUserFollow = cache.function(async (userA: string, userB: string): Promise<boolean> => { diff --git a/source/features/view-markdown-source.tsx b/source/features/view-markdown-source.tsx index 4e6611b4..824b2580 100644 --- a/source/features/view-markdown-source.tsx +++ b/source/features/view-markdown-source.tsx @@ -4,8 +4,8 @@ import select from 'select-dom'; import delegate from 'delegate-it'; import CodeIcon from 'octicon/code.svg'; import FileIcon from 'octicon/file.svg'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import fetchDom from '../libs/fetch-dom'; const buttonBodyMap = new WeakMap<Element, Element | Promise<Element>>(); diff --git a/source/features/wait-for-build.tsx b/source/features/wait-for-build.tsx index da61fb03..234870ce 100644 --- a/source/features/wait-for-build.tsx +++ b/source/features/wait-for-build.tsx @@ -4,8 +4,8 @@ import select from 'select-dom'; import onetime from 'onetime'; import InfoIcon from 'octicon/info.svg'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import * as prCiStatus from '../libs/pr-ci-status'; import onPrMergePanelOpen from '../libs/on-pr-merge-panel-open'; diff --git a/source/features/warn-pr-from-master.tsx b/source/features/warn-pr-from-master.tsx index 8a66cb1c..30a615db 100644 --- a/source/features/warn-pr-from-master.tsx +++ b/source/features/warn-pr-from-master.tsx @@ -1,7 +1,7 @@ import React from 'dom-chef'; import select from 'select-dom'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; import getDefaultBranch from '../libs/get-default-branch'; async function init(): Promise<false | void> { diff --git a/source/features/warning-for-disallow-edits.tsx b/source/features/warning-for-disallow-edits.tsx index d57ae9e9..3dacfd6e 100644 --- a/source/features/warning-for-disallow-edits.tsx +++ b/source/features/warning-for-disallow-edits.tsx @@ -3,8 +3,8 @@ import React from 'dom-chef'; import select from 'select-dom'; import oneTime from 'onetime'; import delegate from 'delegate-it'; +import * as pageDetect from 'github-url-detection'; import features from '../libs/features'; -import * as pageDetect from '../libs/page-detect'; const getWarning = oneTime(() => ( <div className="flash flash-error mt-3 rgh-warning-for-disallow-edits"> diff --git a/source/libs/features.tsx b/source/libs/features.tsx index 7debe3ad..5c98801e 100644 --- a/source/libs/features.tsx +++ b/source/libs/features.tsx @@ -3,10 +3,10 @@ import select from 'select-dom'; import domLoaded from 'dom-loaded'; import {Promisable} from 'type-fest'; import elementReady from 'element-ready'; +import * as pageDetect from 'github-url-detection'; import {logError} from './utils'; import onNewComments from './on-new-comments'; import onNewsfeedLoad from './on-newsfeed-load'; -import * as pageDetect from './page-detect'; import optionsStorage, {RGHOptions} from '../options-storage'; type BooleanFunction = () => boolean; diff --git a/source/libs/page-detect.ts b/source/libs/page-detect.ts deleted file mode 100644 index 10339105..00000000 --- a/source/libs/page-detect.ts +++ /dev/null @@ -1,411 +0,0 @@ -/* The tested var might not be a string */ - -import select from 'select-dom'; -import reservedNames from 'github-reserved-names/reserved-names.json'; -import {getUsername, getCleanPathname, getRepoPath, getOwnerAndRepo} from './utils'; - -const skip = 'skip'; // To be used only to skip tests of combined functions, i.e. isPageA() || isPageB() -const domBased = 'skip'; // To be used only to skip tests that are DOM-based rather than URL-based - -export const is404 = (): boolean => document.title === 'Page not found · GitHub'; -export const _is404 = domBased; // They're specified in page-detect.ts - -export const is500 = (): boolean => document.title === 'Server Error · GitHub' || document.title === 'Unicorn! · GitHub' || document.title === '504 Gateway Time-out'; -export const _is500 = domBased; // They're specified in page-detect.ts - -export const isBlame = (): boolean => String(getRepoPath()).startsWith('blame/'); -export const _isBlame = [ - 'https://github.com/sindresorhus/refined-github/blame/master/package.json' -]; - -export const isCommit = (): boolean => isSingleCommit() || isPRCommit(); -export const _isCommit = [ - 'https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f', - 'https://github.com/sindresorhus/refined-github/commit/5b614', - 'https://github.com/sindresorhus/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85', - 'https://github.com/sindresorhus/refined-github/pull/148/commits/00196' -]; - -export const isCommitList = (): boolean => isRepoCommitList() || isPRCommitList(); -export const _isCommitList = skip; - -export const isRepoCommitList = (): boolean => String(getRepoPath()).startsWith('commits'); -export const _isRepoCommitList = [ - 'https://github.com/sindresorhus/refined-github/commits/master?page=2', - 'https://github.com/sindresorhus/refined-github/commits/test-branch', - 'https://github.com/sindresorhus/refined-github/commits/0.13.0', - 'https://github.com/sindresorhus/refined-github/commits/230c2', - 'https://github.com/sindresorhus/refined-github/commits/230c2935fc5aea9a681174ddbeba6255ca040d63', - 'https://github.com/sindresorhus/refined-github/commits?author=fregante', - 'https://github.com/sindresorhus/runs/commits/' -]; - -export const isCompare = (): boolean => String(getRepoPath()).startsWith('compare'); -export const _isCompare = [ - 'https://github.com/sindresorhus/refined-github/compare', - 'https://github.com/sindresorhus/refined-github/compare/', - 'https://github.com/sindresorhus/refined-github/compare/master...branch-name', - 'https://github.com/sindresorhus/refined-github/compare/master...branch-name?quick_pull=1', - 'https://github.com/sindresorhus/refined-github/compare/branch-1...branch-2?quick_pull=1', - 'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1' -]; - -export const isDashboard = (): boolean => !isGist() && /^$|^(orgs\/[^/]+\/)?dashboard(\/|$)/.test(getCleanPathname()); -export const _isDashboard = [ - 'https://github.com/', - 'https://github.com', - 'https://github.com/orgs/test/dashboard', - 'https://github.com/dashboard/index/2', - 'https://github.com/dashboard', - 'https://github.com/orgs/edit/dashboard', - 'https://github.big-corp.com/', - 'https://not-github.com/', - 'https://my-little-hub.com/', - 'https://github.com/?tab=repositories' // Gotcha for `isUserProfileRepoTab` -]; - -export const isEnterprise = (): boolean => location.hostname !== 'github.com' && location.hostname !== 'gist.github.com'; -export const _isEnterprise = [ - 'https://github.big-corp.com/', - 'https://not-github.com/', - 'https://my-little-hub.com/', - 'https://my-little-hub.com/gist' -]; - -export const isGist = (): boolean => location.hostname.startsWith('gist.') || location.pathname.split('/', 2)[1] === 'gist'; -export const _isGist = [ - 'https://gist.github.com', - 'http://gist.github.com', - 'https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064', - 'https://my-little-hub.com/gist' -]; - -export const isGlobalDiscussionList = (): boolean => ['issues', 'pulls'].includes(location.pathname.split('/', 2)[1]); -export const _isGlobalDiscussionList = [ - 'https://github.com/issues', - 'https://github.com/issues?q=is%3Apr+is%3Aopen', - 'https://github.com/issues/assigned', - 'https://github.com/issues/mentioned', - 'https://github.com/pulls', - 'https://github.com/pulls?q=issues', - 'https://github.com/pulls/assigned', - 'https://github.com/pulls/mentioned', - 'https://github.com/pulls/review-requested' -]; - -export const isGlobalSearchResults = (): boolean => location.pathname === '/search' && new URLSearchParams(location.search).get('q') !== null; -export const _isGlobalSearchResults = [ - 'https://github.com/search?q=refined-github&ref=opensearch' -]; - -export const isIssue = (): boolean => /^issues\/\d+/.test(getRepoPath()!) && document.title !== 'GitHub · Where software is built'; // The title check excludes deleted issues -export const _isIssue = [ - 'https://github.com/sindresorhus/refined-github/issues/146' -]; - -export const isDiscussionList = (): boolean => isGlobalDiscussionList() || isRepoDiscussionList(); -export const _isDiscussionList = skip; - -export const isLabelList = (): boolean => getRepoPath() === 'labels'; -export const _isLabelList = [ - 'https://github.com/sindresorhus/refined-github/labels' -]; - -export const isMilestone = (): boolean => /^milestone\/\d+/.test(getRepoPath()!); -export const _isMilestone = [ - 'https://github.com/sindresorhus/refined-github/milestone/12' -]; - -export const isMilestoneList = (): boolean => getRepoPath() === 'milestones'; -export const _isMilestoneList = [ - 'https://github.com/sindresorhus/refined-github/milestones' -]; - -export const isNewIssue = (): boolean => getRepoPath() === 'issues/new'; -export const _isNewIssue = [ - 'https://github.com/sindresorhus/refined-github/issues/new' -]; - -export const isNewRelease = (): boolean => getRepoPath() === 'releases/new'; -export const _isNewRelease = [ - 'https://github.com/sindresorhus/refined-github/releases/new' -]; - -export const isNotifications = (): boolean => getCleanPathname() === 'notifications'; -export const _isNotifications = [ - 'https://github.com/notifications' -]; - -export const isOrganizationProfile = (): boolean => select.exists('meta[name="hovercard-subject-tag"][content^="organization"]'); -export const _isOrganizationProfile = domBased; // Safe for `nowAndonAjaxedPages` because this element is in the <head> - -export const isOrganizationDiscussion = (): boolean => /^orgs\/[^/]+\/teams\/[^/]+($|\/discussions)/.test(getCleanPathname()); -export const _isOrganizationDiscussion = [ - 'https://github.com/orgs/refined-github/teams/core-team/discussions?pinned=1', - 'https://github.com/orgs/refined-github/teams/core-team/discussions/1', - 'https://github.com/orgs/refined-github/teams/core-team' -]; - -export const isOwnUserProfile = (): boolean => getCleanPathname() === getUsername(); -export const _isOwnUserProfile = domBased; - -// If there's a Report Abuse link, we're not part of the org -export const isOwnOrganizationProfile = (): boolean => isOrganizationProfile() && !select.exists('[href*="contact/report-abuse?report="]'); -export const _isOwnOrganizationProfile = domBased; - -export const isProject = (): boolean => /^projects\/\d+/.test(getRepoPath()!); -export const _isProject = [ - 'https://github.com/sindresorhus/refined-github/projects/3' -]; - -export const isPR = (): boolean => /^pull\/\d+/.test(getRepoPath()!); -export const _isPR = [ - 'https://github.com/sindresorhus/refined-github/pull/148', - 'https://github.com/sindresorhus/refined-github/pull/148/commits', - 'https://github.com/sindresorhus/refined-github/pull/148/files', - 'https://github.com/sindresorhus/refined-github/pull/148/conflicts', - 'https://github.com/sindresorhus/refined-github/pull/148/commits/00196', - 'https://github.com/sindresorhus/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85' -]; - -export const isConflict = (): boolean => /^pull\/\d+\/conflicts/.test(getRepoPath()!); -export const _isConflict = [ - 'https://github.com/sindresorhus/refined-github/pull/148/conflicts' -]; - -/** - * Do not use this detection if you're looking for PRs, they may appear mixed with issues in search. Use `isDiscussionList` - */ -export const isPRList = (): boolean => location.pathname === '/pulls' || getRepoPath() === 'pulls'; -export const _isPRList = [ - 'https://github.com/pulls', - 'https://github.com/pulls?q=issues', - 'https://github.com/sindresorhus/refined-github/pulls', - 'https://github.com/sindresorhus/refined-github/pulls/', - 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr', - 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed' -]; - -export const isPRCommit = (): boolean => /^pull\/\d+\/commits\/[\da-f]{5,40}/.test(getRepoPath()!); -export const _isPRCommit = [ - 'https://github.com/sindresorhus/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85', - 'https://github.com/sindresorhus/refined-github/pull/148/commits/00196' -]; - -export const isPRConversation = (): boolean => /^pull\/\d+$/.test(getRepoPath()!); -export const _isPRConversation = [ - 'https://github.com/sindresorhus/refined-github/pull/148' -]; - -export const isPRCommitList = (): boolean => /^pull\/\d+\/commits$/.test(getRepoPath()!); -export const _isPRCommitList = [ - 'https://github.com/sindresorhus/refined-github/pull/148/commits' -]; - -export const isPRFiles = (): boolean => /^pull\/\d+\/files/.test(getRepoPath()!); -export const _isPRFiles = [ - 'https://github.com/sindresorhus/refined-github/pull/148/files' -]; - -export const isQuickPR = (): boolean => isCompare() && /[?&]quick_pull=1(&|$)/.test(location.search); -export const _isQuickPR = [ - 'https://github.com/sindresorhus/refined-github/compare/master...branch-name?quick_pull=1', - 'https://github.com/sindresorhus/refined-github/compare/branch-1...branch-2?quick_pull=1', - 'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1' -]; - -export const isReleasesOrTags = (): boolean => /^tags$|^releases($|\/tag)/.test(getRepoPath()!); -export const _isReleasesOrTags = [ - 'https://github.com/sindresorhus/refined-github/releases', - 'https://github.com/sindresorhus/refined-github/tags', - 'https://github.com/sindresorhus/refined-github/releases/tag/v1.0.0-beta.4', - 'https://github.com/sindresorhus/refined-github/releases/tag/0.2.1' -]; - -export const isEditingFile = (): boolean => String(getRepoPath()).startsWith('edit'); -export const _isEditingFile = [ - 'https://github.com/sindresorhus/refined-github/edit/master/readme.md', - 'https://github.com/sindresorhus/refined-github/edit/ghe-injection/source/background.ts' -]; - -export const isRepo = (): boolean => /^[^/]+\/[^/]+/.test(getCleanPathname()) && - !reservedNames.includes(getOwnerAndRepo().ownerName!) && - !isDashboard() && - !isGist() && - !isRepoSearch(); -export const _isRepo = [ - // Some of these are here simply as "gotchas" to other detections - 'https://github.com/sindresorhus/refined-github/blame/master/package.json', - 'https://github.com/sindresorhus/refined-github/issues/146', - 'https://github.com/sindresorhus/notifications/', - 'https://github.com/sindresorhus/refined-github/pull/148', - 'https://github.com/sindresorhus/refined-github/milestones/new', // Gotcha for isRepoTaxonomyDiscussionList - 'https://github.com/sindresorhus/refined-github/milestones/1/edit', // Gotcha for isRepoTaxonomyDiscussionList - 'https://github.com/sindresorhus/refined-github/issues/new/choose', // Gotcha for isRepoIssueList - 'https://github.com/sindresorhus/refined-github/issues/templates/edit' // Gotcha for isRepoIssueList -]; -export const _isRepoSkipNegatives = true; - -export const isRepoTaxonomyDiscussionList = (): boolean => /^labels\/.+|^milestones\/\d+(?!\/edit)/.test(getRepoPath()!); -export const _isRepoTaxonomyDiscussionList = [ - 'https://github.com/sindresorhus/refined-github/labels/Priority%3A%20critical', - 'https://github.com/sindresorhus/refined-github/milestones/1' -]; - -export const isRepoDiscussionList = (): boolean => - isRepoPRList() || - isRepoIssueList() || - isRepoTaxonomyDiscussionList(); -export const _isRepoDiscussionList = skip; - -export const isRepoPRList = (): boolean => String(getRepoPath()).startsWith('pulls'); -export const _isRepoPRList = [ - 'https://github.com/sindresorhus/refined-github/pulls', - 'https://github.com/sindresorhus/refined-github/pulls/', - 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr', - 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed' -]; - -// `issues/fregante` is a list but `issues/1`, `issues/new`, `issues/new/choose`, `issues/templates/edit` aren’t -export const isRepoIssueList = (): boolean => - String(getRepoPath()).startsWith('issues') && - !/^issues\/(\d+|new|templates)($|\/)/.test(getRepoPath()!); -export const _isRepoIssueList = [ - 'http://github.com/sindresorhus/ava/issues', - 'https://github.com/sindresorhus/refined-github/issues', - 'https://github.com/sindresorhus/refined-github/issues/fregante', - 'https://github.com/sindresorhus/refined-github/issues/newton', - 'https://github.com/sindresorhus/refined-github/issues/wptemplates', - 'https://github.com/sindresorhus/refined-github/issues?q=is%3Aclosed+sort%3Aupdated-desc' -]; - -export const isRepoRoot = (): boolean => /^(tree\/[^/]+)?$/.test(getRepoPath()!); -export const _isRepoRoot = [ - // Some tests are here only as "gotchas" for other tests that may misidentify their pages - 'https://github.com/sindresorhus/edit', - 'https://github.com/sindresorhus/search', - 'https://github.com/sindresorhus/refined-github', - 'https://github.com/sindresorhus/refined-github/', - 'https://github.com/sindresorhus/notifications/', - 'https://github.com/sindresorhus/refined-github/tree/native-copy-buttons', - 'https://github.com/sindresorhus/refined-github/tree/native-copy-buttons/', - 'https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6', - 'https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6/', - 'https://github.com/sindresorhus/refined-github/tree/57bf4', - 'https://github.com/sindresorhus/refined-github?files=1', - 'https://github.com/sindresorhus/refined-github/tree/master?files=1', - 'https://github.com/sindresorhus/branches' -]; - -// This can't use `getRepoPath` to avoid infinite recursion. -// `getRepoPath` depends on `isRepo` and `isRepo` depends on `isRepoSearch` -export const isRepoSearch = (): boolean => location.pathname.slice(1).split('/')[2] === 'search'; -export const _isRepoSearch = [ - 'https://github.com/sindresorhus/refined-github/search?q=diff', - 'https://github.com/sindresorhus/refined-github/search?q=diff&unscoped_q=diff&type=Issues', - 'https://github.com/sindresorhus/refined-github/search' -]; - -export const isRepoSettings = (): boolean => String(getRepoPath()).startsWith('settings'); -export const _isRepoSettings = [ - 'https://github.com/sindresorhus/refined-github/settings', - 'https://github.com/sindresorhus/refined-github/settings/branches' -]; - -export const isRepoTree = (): boolean => isRepoRoot() || String(getRepoPath()).startsWith('tree/'); -export const _isRepoTree = [ - ..._isRepoRoot, - 'https://github.com/sindresorhus/refined-github/tree/master/distribution', - 'https://github.com/sindresorhus/refined-github/tree/0.13.0/distribution', - 'https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/distribution' -]; - -export const isRepoWithAccess = (): boolean => isRepo() && select.exists('.reponav-item[href$="/settings"]'); -export const _isRepoWithAccess = domBased; - -export const isSingleCommit = (): boolean => /^commit\/[\da-f]{5,40}/.test(getRepoPath()!); -export const _isSingleCommit = [ - 'https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f', - 'https://github.com/sindresorhus/refined-github/commit/5b614' -]; - -export const isSingleFile = (): boolean => String(getRepoPath()).startsWith('blob/'); -export const _isSingleFile = [ - 'https://github.com/sindresorhus/refined-github/blob/master/.gitattributes', - 'https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css', - 'https://github.com/sindresorhus/refined-github/blob/master/edit.txt' -]; - -export const isFileFinder = (): boolean => String(getRepoPath()).startsWith('find/'); -export const _isFileFinder = [ - 'https://github.com/sindresorhus/refined-github/find/master' -]; - -export const isForkedRepo = (): boolean => select.exists('meta[name="octolytics-dimension-repository_is_fork"][content="true"]'); -export const _isForkedRepo = domBased; - -export const isSingleGist = (): boolean => isGist() && /^\/(gist\/)?[^/]+\/[\da-f]{32}$/.test(location.pathname); -export const _isSingleGist = [ - 'https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064' -]; - -export const isTrending = (): boolean => location.pathname === '/trending' || location.pathname.startsWith('/trending/'); -export const _isTrending = [ - 'https://github.com/trending', - 'https://github.com/trending/developers', - 'https://github.com/trending/unknown' -]; - -export const isBranches = (): boolean => getRepoPath()?.startsWith('branches') ?? false; -export const _isBranches = [ - 'https://github.com/sindresorhus/refined-github/branches' -]; - -export const isUserProfile = (): boolean => select.exists('.user-profile-nav'); -export const _isUserProfile = domBased; - -export const isUserProfileRepoTab = (): boolean => - isUserProfile() && - new URLSearchParams(location.search).get('tab') === 'repositories'; -export const _isUserProfileRepoTab = domBased; - -export const isSingleTagPage = (): boolean => /^(releases\/tag)/.test(getRepoPath()!); -export const _isSingleTagPage = [ - 'https://github.com/sindresorhus/refined-github/releases/tag/v1.0.0-beta.4', - 'https://github.com/sindresorhus/refined-github/releases/tag/0.2.1' -]; - -export const _hasComments = skip; -export const hasComments = (): boolean => - isPR() || - isIssue() || - isCommit() || - isOrganizationDiscussion(); - -export const _hasRichTextEditor = skip; -export const hasRichTextEditor = (): boolean => - hasComments() || - isNewIssue() || - isCompare(); - -export const _hasCode = skip; -export const hasCode = (): boolean => // Static code, not the editor - hasComments() || - isRepoTree() || // Readme files - isSingleFile() || - isGist() || - isCompare() || - isBlame(); - -export const isActionPage = (): boolean => location.pathname.startsWith('/marketplace/actions/'); -export const _isActionPage = [ - 'https://github.com/marketplace/actions/urlchecker-action', - 'https://github.com/marketplace/actions/github-action-for-assignee-to-reviewer', - 'https://github.com/marketplace/actions/hugo-actions' -]; - -export const isActionJobRun = (): boolean => String(getRepoPath()).startsWith('runs/'); -export const _isActionJobRun = [ - 'https://github.com/sindresorhus/refined-github/runs/639481849' -]; - diff --git a/source/libs/utils.ts b/source/libs/utils.ts index dc1aeb35..a4629fca 100644 --- a/source/libs/utils.ts +++ b/source/libs/utils.ts @@ -1,8 +1,8 @@ import select from 'select-dom'; import onetime from 'onetime'; import stripIndent from 'strip-indent'; -import {isRepo, isPR, isIssue} from './page-detect'; import compareVersions from 'tiny-version-compare'; +import {isRepo, isPR, isIssue} from 'github-url-detection'; export function logError(id: FeatureID, error: Error | string, ...extras: unknown[]): void { if (error instanceof TypeError && error.message === 'Object(...)(...) is null') { diff --git a/source/options.tsx b/source/options.tsx index 016a53d8..903d9085 100644 --- a/source/options.tsx +++ b/source/options.tsx @@ -5,8 +5,8 @@ import cache from 'webext-storage-cache'; import select from 'select-dom'; import fitTextarea from 'fit-textarea'; import {applyToLink} from 'shorten-repo-url'; -import {getAllOptions} from './options-storage'; import * as indentTextarea from 'indent-textarea'; +import {getAllOptions} from './options-storage'; import * as domFormatters from './libs/dom-formatters'; function parseDescription(description: string): DocumentFragment { diff --git a/test/page-detect.ts b/test/page-detect.ts deleted file mode 100644 index ef481ad2..00000000 --- a/test/page-detect.ts +++ /dev/null @@ -1,99 +0,0 @@ -import test from 'ava'; -import stripIndent from 'strip-indent'; -import './fixtures/globals'; -import * as pageDetect from '../source/libs/page-detect'; - -const allUrls = new Set<string>(); -for (const imported of Object.values(pageDetect)) { - if (Array.isArray(imported)) { - for (const url of imported) { - allUrls.add(url); - } - } -} - -for (const [key, detect] of Object.entries(pageDetect)) { - if (key.startsWith('_') || typeof detect !== 'function') { - continue; - } - - const testsKey = '_' + key; - // @ts-ignore `import-all` has no index signature https://github.com/Microsoft/TypeScript/issues/16248 - const validURLs = pageDetect[testsKey] as string[] | string; - - if (validURLs === 'skip') { - continue; - } - - test(key, t => { - t.true(Array.isArray(validURLs), `The function \`${key}\` doesn’t have any tests. Export an array of valid URLs as \`${testsKey}\``); - }); - - let i = 0; - for (const url of validURLs) { - test(`${key} ${++i}`, t => { - location.href = url; - t.true(detect(), stripIndent(` - Is this URL \`${key}\`? - ${url.replace('https://github.com', '')} - - • Yes? The \`${key}\` test is wrong and should be fixed. - • No? Remove it from the \`_${key}\` array. - `)); - }); - } - - // @ts-ignore `import-all` has no index signature https://github.com/Microsoft/TypeScript/issues/16248 - if (pageDetect[testsKey + 'SkipNegatives']) { - continue; - } - - for (const url of allUrls) { - if (!validURLs.includes(url)) { - test(`${key} ${++i}`, t => { - location.href = url; - t.false(detect(), stripIndent(` - Is this URL \`${key}\`? - ${url.replace('https://github.com', '')} - - • Yes? Add it to the \`_${key}\` array. - • No? The \`${key}\` test is wrong and should be fixed. - `)); - }); - } - } -} - -test('is404', t => { - document.title = 'Page not found · GitHub'; - t.true(pageDetect.is404()); - - document.title = 'examples/404: Page not found examples'; - t.false(pageDetect.is404()); - - document.title = 'Dashboard'; - t.false(pageDetect.is404()); - - document.title = 'Page not found · Issue #266 · sintaxi/surge · GitHub'; - t.false(pageDetect.is404()); -}); - -test('is500', t => { - document.title = 'Server Error · GitHub'; - t.true(pageDetect.is500()); - - document.title = 'Unicorn! · GitHub'; - t.true(pageDetect.is500()); - - document.title = 'examples/500: Server Error examples'; - t.false(pageDetect.is500()); - - document.title = 'sindresorhus/unicorn: You can’t tell what doesn’t exist'; - t.false(pageDetect.is500()); - - document.title = 'Dashboard'; - t.false(pageDetect.is500()); - - document.title = 'Server Error · Issue #266 · sintaxi/surge · GitHub'; - t.false(pageDetect.is500()); -}); |