GithubHelp home page GithubHelp logo

refined-github / github-url-detection Goto Github PK

View Code? Open in Web Editor NEW
122.0 122.0 25.0 2.33 MB

Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.

Home Page: https://npm.im/github-url-detection

License: MIT License

TypeScript 100.00%

github-url-detection's Introduction

Refined GitHub

Browser extension that simplifies the GitHub interface and adds useful features

We use GitHub a lot and notice many annoyances we'd like to fix. So here be dragons.

Our hope is that GitHub will notice and implement some of these much-needed improvements. So if you like any of these improvements, please open a discussion on GitHub feedback or contact GitHub support about doing it.

GitHub Enterprise is also supported: How to enable it.

The GITHUB and REFINED GITHUB trademarks are owned by GitHub, Inc. and used under license.

Install

Chrome and other Chromium browsers

Firefox including Firefox Android

Safari on Mac, iOS and iPadOS

If you love Refined GitHub, consider sponsoring or hiring the maintainer @fregante


Highlights 🔥

Makes whitespace characters visible

Adds one-click merge conflict fixers

Shows how far behind a PR head branch is + tells you its base commit

Lets you hide every event except comments or unresolved comments in issues and PRs

Lets you subscribe to opening/closing events of issues in one click

Adds a link to the default branch on directory listings and files

Adds a button to discard all the changes to a file in a PR

Select notifications by type and status

Repositories

File management

Code

Writing comments

Reading comments

Conversations

Viewing pull requests

Editing pull requests

Commits

Tags and releases

Profiles

Newsfeed

  • Hides other inutile newsfeed events (commits, forks, new followers).
  • Automagically expands the newsfeed when you scroll down.

Notifications

Global

Netiquette

Fixes for GitHub shortcomings

Previously part of Refined GitHub

GitHub took inspiration from Refined GitHub and natively implemented dozens of its features, 🎉 so they've been removed from this extension. You can also see all the past features of Refined GitHub in a single list.

Customization

Most features can be disabled if they are JavaScript-based and you can override our CSS with your own in the extension options.

We're happy to receive suggestions and contributions, but be aware this is a highly opinionated project. There's a high bar for adding features. Users will always disagree with something. That being said, we're open to discussing things.

Links

github-url-detection's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

github-url-detection's Issues

Is `isProfile` supposed to include gist profiles?

export const isProfile = (url: URL | HTMLAnchorElement | Location = location): boolean => {
const pathname = getCleanPathname(url);
return pathname.length > 0 && !pathname.includes('/') && !pathname.includes('.') && !reservedNames.includes(pathname);
};

I am getting an error in RGH
profile-gists-link and show-user-top-repositories due to isProfile working on gists.
https://gist.github.com/yakov116

Add `isExplore`, `isSponsors`, `isTopics`, `isCollections`, `isExploreNewsletter`, and `isEvents`

Examples

isExplore('https://github.com/explore')                      // true
isSponsors('https://github.com/sponsors')                    // true
isSponsors('https://github.com/sponsors/accounts')           // true
isSponsors('https://github.com/sponsors/{profile}/waitlist') // true
isSponsors('https://github.com/sponsors/community')          // true
isTopics('https://github.com/topics')                        // true
isTopics('https://github.com/topics/{topic}')                // true
isCollections('https://github.com/collections')              // true
isCollections('https://github.com/collections/{collection}') // true
isEvents('https://github.com/events')                        // true
isEvents('https://github.com/events/{event}')                // true
isExploreNewsletter('https://github.com/explore/email')      // true

Are you willing to submit a pull request?

Yes

Potentially use new `route-pattern` meta tag

I see a new meta tag that we could use in some situations. I don't think we should actually drop our own URL-based detections, but we can use these to disambiguate some situations

isRepoHome

<meta name="route-pattern" content="/:user_id/:repository">

isIssueList

<meta name="route-pattern" content="/:user_id/:repository/issues(.:format)">

isRepoTree

<meta name="route-pattern" content="/:user_id/:repository/tree/*name(/*path)">

Fix auto-deployment

It's unclear what the problem is, but npm publish throws for some reason. Help wanted to debug this.

npm notice 📦  [email protected]
npm notice === Tarball Contents === 
npm notice 1.1kB  license         
npm notice 11.8kB cjs/index.js    
npm notice 11.5kB esm/index.js    
npm notice 22B    esm/package.json
npm notice 1.7kB  package.json    
npm notice 2.8kB  readme.md       
npm notice 5.2kB  cjs/index.d.ts  
npm notice 5.2kB  esm/index.d.ts  
npm notice === Tarball Details === 
npm notice name:          github-url-detection                    
npm notice version:       1.2.1                                   
npm notice package size:  7.1 kB                                  
npm notice unpacked size: 39.4 kB                                 
npm notice shasum:        6f51c2edac9a387c670b71c28f0144026fa708b9
npm notice integrity:     sha512-KB+69+slQ+NTG[...]BjP0a3QJ2oEXA==
npm notice total files:   8                                       
npm notice 
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://registry.npmjs.org/github-url-detection - Not found
npm ERR! 404 
npm ERR! 404  '[email protected]' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

https://github.com/fregante/github-url-detection/actions/runs/137623208/workflow

`canUserEditRepo` is broken?

refined-github/refined-github#3783 added this line

// Hide empty meta if it’s not editable by the current user
// TODO: once it's fixed, use https://github.com/fregante/github-url-detection/blob/4840d85d31d59bfe71e884ef42c482fbfff2d955/index.ts#L490
if (!select.exists('.repository-content [aria-label="Edit repository metadata"]')) {

Implying that canUserEditRepo is broken. Needs to be checked on multiple pages to make sure it works and where it doesn't.

cc @cheap-glitch since you wrote that comment you might have more details.

Add `isUserTheRepositoryCollaborator`

I noticed there are duplicate separators for checking write access in Refined GitHub:

Maybe add a isUserTheRepositoryCollaborator (candidate name) method to check for the existence of .lock-toggle-link or canUserEditRepo().

The problem is that this only works on hasComments()...

`isOrganizationRepo` is broken due to new search

I don't see any tags in the head to determine this anymore. I think the earliest indicator is #repository-container-header .author[data-hovercard-type="organization"]

.AppHeader-context-full [data-hovercard-type="organization"]

Re-include `isRepoSearch` in `isRepo`

As described in refined-github/refined-github#5739 (comment)

  1. Drop isRepoSearch exclusion from isRepo
  2. Add hasRepoHeader (isRepo && !isRepoSearch)
  3. Ensure that other detections aren't affected by this change (e.g. isSingleFile depends on isRepo, but it never matched isRepoSearch in the first place, so that's fine)
  4. Release breaking version
  5. All isRepo usage in the extension to hasRepoHeader

Migrate `getCurrentCommittish` and `GitHubURL` here?

Another GitHub-related browser extension Gitako encountered the infamous "slash-in-branch-name" issue: EnixCoda/Gitako#243

Refined GitHub had similar experience and that (along with other issues) resulted in the GitHubURL helper (and its dependency getCurrentCommittish). I think these helpers are generally useful for others as well, so is there any interest maintaining them here?

Issue with this approach is that the helpers are huge comparing to the existing getRepo helper. And it's not super related to URL detection, so it probably should be its own thing.

`isReleasesOrTags` !== `isReleases || isTags`

I think isReleasesOrTags is wrong.

  • isReleases: /user/repo/releases
  • isTags: /user/repo/tags
  • isReleasesOrTags: ?

You'd think that it would match ONLY those two URLs, but it also matches isSingleTag

https://refined-github.github.io/github-url-detection/?url=%2Frefined-github%2Frefined-github%2Freleases%2Ftag%2F2

Possible resolutions (non-exclusive):

  • drop isSingleTag from isReleasesOrTags
  • rename to isReleaseList and isTagList and isReleaseOrTagList
  • add isSingleReleaseOrTag

Use meta tags in isRepoPublic

I see these tags:

<meta name="octolytics-dimension-user_id" content="1402241" />
<meta
  name="octolytics-dimension-user_login"
  content="fregante"
/>
<meta name="octolytics-dimension-repository_id" content="47542242" />
<meta
  name="octolytics-dimension-repository_nwo"
  content="fregante/iphone-inline-video"
/>
<meta name="octolytics-dimension-repository_public" content="true" />
<meta
  name="octolytics-dimension-repository_is_fork"
  content="false"
/>
<meta
  name="octolytics-dimension-repository_network_root_id"
  content="47542242"
/>
<meta
  name="octolytics-dimension-repository_network_root_nwo"
  content="fregante/iphone-inline-video"
/>

octolytics-dimension-repository_public can probably be used for this

Demo website is broken

It seems like the demo website is broken (tested in latest Firefox and Chromium). The page is blank except for the explanation message and the following console error is produced:

Uncaught TypeError: e.default is not a constructor
    epB2 https://fregante.github.io/github-url-detection/main.127a4158.js:4
    f https://fregante.github.io/github-url-detection/main.127a4158.js:1
    parcelRequire https://fregante.github.io/github-url-detection/main.127a4158.js:1
    <anonymous> https://fregante.github.io/github-url-detection/main.127a4158.js:1
main.127a4158.js:4:182

`isArchivedRepo` broken on Global navigation update

No ".Label" element anymore, it only appears on the repo home

https://github.com/fregante/iphone-inline-video

📕 0.0.0 → TypeError: Cannot read properties of null (reading 'textContent')
    at Module.isArchivedRepo (refined-github.js:26029:90)
    at isArchivedRepoAsync (refined-github.js:18073:60)
    at async init (refined-github.js:12546:7)
    at async runFeature (refined-github.js:3797:16)
    at async setupPageLoad (refined-github.js:3809:5)

Update isOpenPR and related detections

From

exists('#partial-discussion-header [title="Status: Open"], #partial-discussion-header [title="Status: Draft"]')

to

exists('.gh-header-meta [title$="Open"], .gh-header-meta [title$="Draft"]'),

but more likely a mix of the 2.

Note: let's not use :is yet, it'd be a breaking change.

Missing detection for creating new files

Per refined-github/refined-github#4252 (comment)

In the PR above I want to match patterns of both these URL examples:

- Create new file:         https://github.com/sindresorhus/refined-github/new/main
- Modify an existing file: https://github.com/sindresorhus/refined-github/edit/main/readme.md

Checking them via https://fregante.github.io/github-url-detection/ I see that :
2021-04-19_184538
2021-04-19_190318

So I have in the PR the following:

	include: [
		...
		pageDetect.isRepo,
		pageDetect.isEditingFile
	],

But, as mentioned by @yakov116:

Adding isRepo will add it to all repo pages (PR's Issues etc)

Include example URLs in JSDocs

It would be good to expose the example/test URLs in the JSDocs:

Screen Shot

I'm not sure how how to do this automatically though:

  • write the test URLs in JSDocs and have the test runner read them (how?!). This has the advantage of "just working" when building it via TS
  • manually extending the types via build, either via typescript transform or via post-build step (gives me a headache just thinking about it)

Something similar was suggested by @kidonng on the RG repo if I remember correctly.

Current situation:

Screen Shot

Add `isSingleGistCode`

Extracted from #80


This "is gist" but it's not the standard page with a gist. Do we need a more specific detection?

https://gist.github.com/fregante/2205329b71218fa2c1d3/revisions

Add `elementReady`-like helper for DOM detections

Sometimes we want to test whether a page matches before it's done downloading, this can be done by passing a selector to element-ready.

I have 2 ideas:

Static definitions

Instead of being just a function, we can define the detections as a list of constraints like:

- const canUserEditOrg = (url) => isOrganizationProfile() && exists('.pagehead-tabs-item[href$="/settings/profile"]')
+ const canUserEditOrgDefinition = [isOrganizationProfile, '.pagehead-tabs-item[href$="/settings/profile"]']
+ export canUserEditOrg = solveConstraints(canUserEditOrgDefinition);
+ export canUserEditOrgAsync = solveConstraintsAsync(canUserEditOrgDefinition);

But this gets wordy FAST

Duplicate functions

  const canUserEditOrg = (url) => isOrganizationProfile() && exists('.pagehead-tabs-item[href$="/settings/profile"]')
+ const canUserEditOrgAsync = async (url) => isOrganizationProfile() && await existsReady('.pagehead-tabs-item[href$="/settings/profile"]')

Publish script broken?

npm notice 
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/
npm ERR! need auth You need to authorize this machine using `npm adduser`

This line was removed:

https://github.com/refined-github/github-url-detection/actions/runs/4082945529/workflow#L28

Maybe it's still needed. What's the minimum required setup for publishing? 🤔

Also the ENV is probably not being shared… https://github.com/fregante/GhostText-for-VSCode/actions/runs/4467201432/jobs/7846357122

error

Run gh release create "$VERSION" --generate-notes
tag required when not running interactively

`getRepositoryInfo` breaks on some pages

Related: refined-github/refined-github#3743
Buggy page: https://github.com/sindresorhus/refined-github/runs/1428929640?check_suite_focus=true

Code to be fixed: https://github.com/fregante/github-url-detection/blob/59527fa38de89231435b6d3a35df8e52c2b6015a/index.ts#L542-L543

I use og:url here instead of location to try to normalize the capitalization.

The problem is that GitHub misuses the og:url here so on that page it lists https://github.com instead of the real URL.

We should put some checks so that it uses location when og:url is broken, like:

if !location.href.toLowerCase().startsWith(canonical.content.toLowerCase) {
	use location
}

Detecting the two kinds of GitHub Security advisories

GitHub has two different kinds of advisories.

The first is the advisories that are published by the repository owners themselves. The last URL part will always end with 'GHSA'. Here's an example of the URL for these:

The second is the advisory that is curated by GitHub, these are similar, but not the same as the advisories published by the project maintainers. These versions are curated/modified/updated by GitHub staff themselves. These get generated after an advisory is published and processed by GitHub. Here's an example of the URL for that:

Also, the above URL incorrectly reports that that URL is:

isRepo(url) // true
isRepoHome(url) // true
isRepoRoot(url) // true
isRepoTree(url) // true

`isRepoRoot` doesn't work on branches with slashes

I think I found a way to determine isRepoRoot: use the title

/fregante/github-url-detection fregante/github-url-detection: Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript
/fregante/github-url-detection/tree/npm-test fregante/github-url-detection at npm-test
/fregante/github-url-detection/tree/npm-test/esm github-url-detection/esm at npm-test · fregante/github-url-detection

You can see 2 behaviors:

  • isRepoRoot starts with getRepoURL
  • isRepoTree does not (but ends with getRepoURL)
    • warning: if the repo is called fregante/fregante and the folder is fregante, then title starts with fregante/fregante and ends with fregante/fregante

The code might be:

const isRepoRoot = (url) => /^(tree\/[^/]+)?$/.test(getRepoPath(url)!) || (!url && document.title.startsWith(getRepoURL()) && !document.title.endsWith(getRepoURL()))

Originally discussed at refined-github/refined-github#3254 (comment)

Add `isBlank`

There are several situations where the repo may only show a takedown notice:

Additionally, an issue may be deleted and only the repository header is shown.

I propose to add a isBlank detection for them. There are several ways to check for them:

  • document.title !== 'GitHub · Where software is built': this is already used in isIssue
  • Check for existence of main .blankslate: this may catch more cases and if GitHub ever changes their tagline again 😄

`isPRFiles` doesn't include "PR Files with single commit selected"

Example:

https://github.com/refined-github/refined-github/pull/6635/commits/3b9ad8cd926337efa500c0a496639022cd15c74d

https://github.com/refined-github/refined-github/pull/6635/files/0971327bfbf6509d7c2b8b9abb7868228c43f844..715c21222c67ce7f320f979ecd226c356ff565fe

It appears that isPRFiles is always used together with isPRCommit:

https://github.com/refined-github/refined-github/blob/930d7d5a43536c87c65f189092d868c26ec69dee/source/features/restore-file.tsx#L143-L144

`isSingleGist` is too broad and incorrect

  1. These two (old) URLs are not detected as isSingleGist:
https://gist.github.com/fregante/2205329b71218fa2c1d3
https://gist.github.com/fregante/2205329b71218fa2c1d3/d1ebf7d9cfaba4d4596d2ea9174e202479a5f9ad # this is a specific gist revision
  1. This is also detected as isGist, but is actually a /raw/ file, not a gist at all:
https://gist.github.com/fregante/2205329b71218fa2c1d3/raw/d1ebf7d9cfaba4d4596d2ea9174e202479a5f9ad/iframe.js
  1. This is correctly detected as isGist, but maybe we should have a more specific isSingleGistCode so that only the code tab is detected.
https://gist.github.com/fregante/2205329b71218fa2c1d3/revisions

These changes should probably be based on https://github.com/sindresorhus/refined-github/blob/1a9c4f9b/source/features/embed-gist-inline.tsx#L9-L23 and will replace that inline function (which intends to be isSingleGistCode, but is more like a more specific isSingleGist)

Go to demo: https://fregante.github.io/github-url-detection/

Specific detection for file and directory commit lists

Following from refined-github/refined-github#4677 (review)

We do not have a detection that distinguishes commit lists for files and directories. There is isCommitList which is a merge of isRepoCommitList and isPRCommitList.

Maybe, we should add a isFileCommitList and isDirectoryCommitList and merge them into isRepoCommitList.

However, I am not sure how to distinguish between a directory and a file from the URL. File extensions seems like a non-safe of detection. If there is a more safer way to distinguish between the file and directories, I will be happy to open a pull request for it.

Create a logger option

Not sure if this belongs here but it can useful in RH. Allow the user to pass a url and it returs all matches. Would be super nice if even the dom ones are returned.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.